Re: Flex/Bison/ANTLR question... alternative tools for translation?

Sebastian <sk@z.pl>
20 Mar 2005 10:15:58 -0500

          From comp.compilers

Related articles
Flex/Bison/ANTLR question... alternative tools for translation? elikon@cox.net (rgaupsas) (2005-03-15)
Re: Flex/Bison/ANTLR question... alternative tools for translation? lfinsto1@gwdg.de (Laurence Finston) (2005-03-18)
Re: Flex/Bison/ANTLR question... alternative tools for translation? Brian.Inglis@SystematicSW.ab.ca (Brian Inglis) (2005-03-20)
Re: Flex/Bison/ANTLR question... alternative tools for translation? sk@z.pl (Sebastian) (2005-03-20)
Re: Flex/Bison/ANTLR question... alternative tools for translation? elikon@cox.net (rgaupsas) (2005-03-24)
Re: Flex/Bison/ANTLR question... alternative tools for translation? Brian.Inglis@SystematicSW.ab.ca (2005-03-25)
Re: Flex/Bison/ANTLR question... alternative tools for translation? elikon@cox.net (rgaupsas) (2005-03-31)
Re: Flex/Bison/ANTLR question... alternative tools for translation? Brian.Inglis@SystematicSW.ab.ca (Brian Inglis) (2005-04-02)
| List of all articles for this month |

From: Sebastian <sk@z.pl>
Newsgroups: comp.compilers,comp.compilers.tools.pccts
Followup-To: comp.compilers
Date: 20 Mar 2005 10:15:58 -0500
Organization: in Forma
References: 05-03-055
Keywords: parse, tools

rgaupsas wrote:


> I'm working on a translator whereby the input grammar is poorly
> defined; a lot is contextually dependent. I've gotten pretty far with
> Flex/Bison, making heavy use of lexical tie-ins to deal with
> this. However I have some cases, and expect to see more, which Bison
> handles poorly, e.g.:
>
> WK COLOR COLOR ... COLOR NAME PARAM = NUMBER
>
> The problem is that syntactically NAME and PARAM are indistinguishable
> from COLOR (both are alpha numeric of the same form), so the following
> form will not work (note Bflag sets the start_state in Flex).
>
> ...
> | WK {Bflag=F_X1;} x_color { }
> ;
>
> x_color: COLOR { }
> | x_color COLOR { }
> | x_color COLOR NAME PARAM '=' NUMBER { }
> ;
>
>
> The only thing I can get to work with this is a kluge: use the token
> type COLOR token for NAME and PARAM, then modify the concatenated list
> of colors:
>
> | x_color COLOR '=' NUMBER { }
>
>
> Any way to better handle this with Flex/Bison? This brings up the next
> question... would ANTLER be more friendly in dealing with such context
> dependent grammar.


Antlr allows for semantic & syntactic predicates. If I understand your
example correcly then thing like your NAME PARAM would look like the
follwoing in the lexer:


COLOR: ALNUM (
    ('=')=> { $setType(PARAM); }
    | (ALNUM_ '=')=> { $setType(NAME); }
    | )
    ;


protected
ALNUM_: ('0'..'9'|'A'..'Z'|'a'..'z'|'_')+
    ;




> Performance is a big consideration, so this is why I
> haven't gotten too deep into ANTLR ( anyone know just how much faster
> ANTLR 3.0 might be when it is available?).


Should be much faster but don't expect miracles. But what's more
impornant it'll be significantly more powerful (thanks to LL(*)
algorithm -- Terrence Parr, the main author of ANTLR has invented the
way to do arbitrary LL lookahead without terribly slow try+rollback
method).


rgds


Sebastian Kaliszewski


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.