[antlr-interest] Lexer rule with alternatives (Newbie question)

Gavin Lambert antlr at mirality.co.nz
Sat Nov 22 15:57:55 PST 2008


At 05:26 23/11/2008, Johannes Luber wrote:
 >but there can be problems as '+' used in to different rules will 

 >create two distinct token types which will cause a
 >MismatchedTokenTypeException later.

Actually normally it won't create separate token types, if you're 
just using '+' on its own only in parser rules.  But it's easy to 
accidentally introduce additional types (if you forget to import 
the lexer tokens; if you combine it with additional characters; if 
you refer to it in other lexer rules as well; etc).

This is one of the reasons why I prefer to never use literal 
characters in parser rules at all, and make explicit lexer rules 
for them.



More information about the antlr-interest mailing list