antlr4编译错误:序列化的ATN数据元素超出范围

时间:2015-03-18 15:37:03

标签: java antlr

antlr4.5,目标Java,jdk1.6。

我编译了.g4合并文件,并收到此错误:

Exception in thread "main" java.lang.UnsupportedOperationException: Serialized ATN data element out of range.
at org.antlr.v4.runtime.atn.ATNSerializer.serialize(ATNSerializer.java:370)
at org.antlr.v4.runtime.atn.ATNSerializer.getSerialized(ATNSerializer.java:547)
at org.antlr.v4.codegen.model.SerializedATN.<init>(SerializedATN.java:46)
at org.antlr.v4.codegen.model.Recognizer.<init>(Recognizer.java:87)
at org.antlr.v4.codegen.model.Lexer.<init>(Lexer.java:51)
at org.antlr.v4.codegen.OutputModelController.lexer(OutputModelController.java:176)
at org.antlr.v4.codegen.OutputModelController.buildLexerOutputModel(OutputModelController.java:129)
at org.antlr.v4.codegen.CodeGenerator.generateLexer(CodeGenerator.java:144)
at org.antlr.v4.codegen.CodeGenPipeline.process(CodeGenPipeline.java:73)
at org.antlr.v4.Tool.processNonCombinedGrammar(Tool.java:429)
at org.antlr.v4.Tool.process(Tool.java:379)
at org.antlr.v4.Tool.processGrammarsOnCommandLine(Tool.java:346)
at org.antlr.v4.Tool.main(Tool.java:193)
at com.dicp.fdsl.antlr.FDSLCompiler.main(FDSLCompiler.java:13)

这个错误是什么意思?

1 个答案:

答案 0 :(得分:1)

我遇到了类似的问题,所以我开始在语法中注释出行,直到错误消失为止。

就我而言,问题是我的数字文字规则中的拼写错误:

片段DIGIT:'0'..'9';

将其更改为以下任何一项都会导致错误消失:

片段DIGIT:'0'..'9';

片段DIGIT:[0123456789];

从“0”到“9”的字符范围似乎可能被解释为Unicode值,并且它会产生意外的大范围。这与ANTLR小组https://github.com/antlr/antlr4/issues/840的讨论一致。