[antlr-interest] Can antlr v3 lex star | tristar properly?

Kevin J. Cummings cummings at kjchome.homeip.net
Wed Nov 21 14:48:36 PST 2007


Guntis Ozols wrote:
> Citēju "Kevin J. Cummings" <cummings at kjchome.homeip.net>:
> 
>> Guntis Ozols wrote:
>>> Thanks, guys!
>>>
>>> I've finally found (thanks to Jim Idle) a solution that both works and
>>> is based on syntactic predicates:
>>>   STAR : '*' (('**') => '**'  { type = TRISTAR; } | );
>>>
>>> Solution by Kay Röpke also works:
>>>   TRISTAR : {input.LA(3) == '*'}? => '*' '*' '*';
>>>   STAR    : '*';
>>>
>>> I still do not understand why
>>>   STAR : '*' ;
>>>   TRISTAR : ('***') => '***';
>>> does not work as expected, I think it is a bug in v3.
>> What happens if you reverse the order of STAR and TRISTAR in the
>> previous example, ie don't recognize STAR before you've check for
>> TRISTAR.  I was under the impression that ANTLR was dependent upon the
>> order of certain productions.
> 
> Does not work

I'm surprised, in ANTLR 2, I've done the following, which works fine:

> protected
> DIGIT      : '0' .. '9'
>            ;
> 
> protected
> DIGITS     : ( DIGIT ) +                              // Just digits
>            ;
> 
> protected
> FLOAT      : DIGITS '.' DIGITS
>            ;
> 
> protected
> UINT       : DIGITS
>            ;
> 
> NUM        : ( DIGITS '.' ) => FLOAT
>            | UINT
>            ;

So if the similar construct doesn't work in ANTLR 3, then I'd consider
it a regression.  Terry may feel differently.  B^)

-- 
Kevin J. Cummings
kjchome at rcn.com
cummings at kjchome.homeip.net
cummings at kjc386.framingham.ma.us
Registered Linux User #1232 (http://counter.li.org)


More information about the antlr-interest mailing list