ANTLR Ambiguity Issue

ぐ巨炮叔叔 提交于 2019-12-04 06:10:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!