ANTLR - NoViableAltException

女生的网名这么多〃 提交于 2019-12-05 09:59:44

I'm assuming you're using the built-in interpreter. Don't, it's buggy. Either create a custom test-class yourself, or use ANTLRWorks' debugger (I believe the Eclipse plugin uses the same debugger as ANTLRWorks). Just never use the interpreter.

In ANTLRWorks, the input "int a12q2efwe, char eq45dsf" is being parsed (using the debugger) as follows:

As you can see yourself using this small grammar:

grammar T;

args       : (typedident (COMMA typedident)*)? EOF;
typedident : (INT | CHAR) IDENT;

COMMA : ',';
INT   : 'int';
CHAR  : 'char';
IDENT : ('a'..'z' | 'A'..'Z') ('a'..'z' | 'A'..'Z' | '0'..'9')*;
SPACE : ' ' {skip();};
A.H.

Perhaps this answer will help you:

ANTLR NoViableAltException with JAVA

According to it a EOF token is missing in your grammar. You did show us the complete grammar, didn't you?

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