[antlr-interest] Concatenating child nodes into one

Gavin Lambert antlr at mirality.co.nz
Fri Aug 21 05:34:57 PDT 2009


At 16:27 21/08/2009, Elnur Cabarov wrote:
>And when I change literals to lexer rules I get:
>The following token definitions can never be matched because 
>prior tokens match the same input: IMPORT,STATIC

Well, as the error message indicates, you need to re-order your 
lexer rules.

In case of ambiguity, ANTLR's lexer will generally choose the 
longest match; failing that it will pick whichever rule is listed 
first.

Most likely in this case there is a conflict between your 
IMPORT/STATIC rules and some kind of identifier rule.  Since the 
identifier rule is more generic, ensure that it is listed after 
the IMPORT/STATIC rules, which are more specific.  (This applies 
in other cases too -- the most generic lexer rule should be the 
last one.)



More information about the antlr-interest mailing list