[antlr-interest] [newbie] Lexer Confusion

Gavin Lambert antlr at mirality.co.nz
Sat Jul 5 15:20:13 PDT 2008


At 03:11 6/07/2008, Johannes Luber wrote:
 >No, it won't. Try this:
 >
 >TERM1: '.' ( ('.')=> '.' {$type = TERM2;} '..'* ) ;

I think that one has the same ambiguity problem as the first 
(ANTLR will see the next character is a dot and then try to match 
a full '..' out of it).  And the second-dot alt needs to be made 
optional so that ANTLR can match a single dot.  This should work 
better:

TERM1
   : '.'
     ( ('.') => '.' { $type = TERM2; }
       ( ('..') => '..' )*
     )?
   ;


I hope this isn't homework, though.  If so, you should be working 
this stuff out yourself :P



More information about the antlr-interest mailing list