问题
I have this grammar.
grammar MyGrammar;
prog : lexeme* ;
lexeme :
TOK_INTLIT : [0-9]+;
Identifiers : Letter (Letter | Digit | '_' )* ;
fragment Letter : [a-zA-Z] ;
fragment Digit : [0-9] ;
...
Now when I input this: int 2x = 20;
I am expecting an error for identifier but I am getting an output like this:
Type = TOK_INT value = [int] Line 1, Column 0,
Type = TOK_INTLIT value = [2] Line 1, Column 4,
Type = Identifiers value = [x] Line 1, Column 5,
2x is being split. Am I doing something wrong or is there a way to fix such things?
来源:https://stackoverflow.com/questions/28661601/antlr-ambiguity-issue