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

Johannes Luber jaluber at gmx.de
Wed Nov 21 03:47:44 PST 2007


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