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

Guntis Ozols guntiso at latnet.lv
Wed Nov 21 14:29:44 PST 2007


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.

I like antlr because antlr grammar is much more readable than regular
expressions, but enhancements are needed to antlr because lexing gets
broken by adding more tokens, and no warning is given.

> 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 '*'.

Guntis



More information about the antlr-interest mailing list