The problem is the location of the CLEAR
rule in your lexer. Since the input clear
matches both the rules ID
and CLEAR
, ANTLR chooses the one that appears first in the grammar. In this case, the input clear
becomes an ID
.
In general, you want to place all keywords for your language before the rule for other identifiers, to ensure that they are properly matched.