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

Guntis Ozols guntiso at latnet.lv
Wed Nov 21 06:23:26 PST 2007


Yes, we can add it to the list - does NOT work, too:
STAR : '*' ('**' {type = TRISTAR;})? ;

To be sure, I've also tried:
STAR options {bugs=off;}: '*' ('**' {type = TRISTAR;})? ;

Guntis

Johannes Luber wrote:
> Guntis Ozols wrote:
> > Is there a way to lex this simple grammar (I am using ANTLRWorks 1.1.4):
> >
> > stars        :        (STAR | TRISTAR)* EOF;
> > STAR : '*' ;
> > TRISTAR : STAR STAR STAR;
> >
> > For '**' I keep getting: mismatched character '<EOF>' expecting '*'.
> >
> > I am out of options. Below is what I've tried:
> > //tokens { STAR; TRISTAR;}
> > //options { backtrack = true; }
> > //options { k = 3; }
> > //ST        :        ('***') => '***' {type = TRISTAR;}
> > //        |        '*' {type = STAR;};
> > //STAR options {greedy=false;}: '*' ;
> > //TRISTAR : '***';
> > //TRISTAR : ('***')=>'***';
> > //TRISTAR options { greedy=true; } : '***';
> > //TRISTAR options { greedy=true; } : ('***')=>'***';
> > //TRISTAR options {greedy=false;} : '***';
> >
> > Guntis
>
> You didn't try
>
> STAR : '*' ('**' {type = TRISTAR;})? ;
>
> Johannes



More information about the antlr-interest mailing list