[antlr-interest] Can antlr v3 lex star | tristar properly?
Guntis Ozols
guntiso at latnet.lv
Wed Nov 21 15:23:58 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
STAR : '*' ('**' { type = TRISTAR; } | );
does not work.
More information about the antlr-interest
mailing list