ANTLR ClassCastException
Why do I get this error开发者_Go百科 while generating code in ANTLR?
[16:06:38] error(10): internal error: C:\Users\user\Desktop\test.g : java.lang.ClassCastException: org.antlr.runtime.tree.CommonTree cannot be cast to org.antlr.tool.GrammarAST
org.antlr.grammar.v3.CodeGenTreeWalker.rules(CodeGenTreeWalker.java:1467)
org.antlr.grammar.v3.CodeGenTreeWalker.grammarSpec(CodeGenTreeWalker.java:1441)
org.antlr.grammar.v3.CodeGenTreeWalker.grammar_(CodeGenTreeWalker.java:509)
org.antlr.codegen.CodeGenerator.genRecognizer(CodeGenerator.java:421)
org.antlr.Tool.generateRecognizer(Tool.java:655)
org.antlr.Tool.process(Tool.java:468)
org.antlr.works.generate.CodeGenerate.generate(CodeGenerate.java:104)
org.antlr.works.generate.CodeGenerate.run(CodeGenerate.java:185)
java.lang.Thread.run(Unknown Source)
The syntax is very simple, just for testing:
grammar test;
ID : ('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
;
Any ideas?
You specified a mixed grammar (lexer and parser), but you did not specify a parser rule.
Either add one or use lexer grammar test;
精彩评论