[antlr-interest] Can antlr v3 lex star | tristar properly?
Jim Idle
jimi at temporal-wave.com
Wed Nov 21 14:50:36 PST 2007
> -----Original Message-----
> From: Guntis Ozols [mailto:guntiso at latnet.lv]
> Sent: Wednesday, November 21, 2007 2:30 PM
> To: antlr-interest at antlr.org
> Subject: Re: [antlr-interest] Can antlr v3 lex star | tristar properly?
>
> 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 : ('***') => '***';
Essentially, you predicate is useless in that there is no other alt than the three '*'. Hence hence you combine the two tokens into a single root, you can use a predicate to choose one path OR the other, having another path is the key here
Jim
More information about the antlr-interest
mailing list