我正在编写解析器,但遇到了一个尴尬的错误。我的规则之一如下:
operatorTerm[ReadOptions Options, int priority] returns [Term t]
@init
{
int p = priority;
Term t2 = null;
Term t = null;
CompoundTermTag f = null;
}
: {testFY($Options, $priority)}?
a=op[$Options, p] {f = $a.tag;}
b=term[$Options, p] {$t = $b.t; $t = createTerm(f, $t); }
| {testFX($Options, $priority)}?
d=op[$Options, p] {f = $d.tag;}
e=term[$Options, p-1] {$t = $e.t; $t = createTerm(f, $t);}
;
这将使用别名 ANTLR4 引发以下错误
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 199, Size: 199
at java.util.ArrayList.rangeCheck(ArrayList.java:604)
at java.util.ArrayList.get(ArrayList.java:382)
at org.antlr.v4.automata.ATNSerializer.serialize(ATNSerializer.java:201)
at org.antlr.v4.automata.ATNSerializer.getSerialized(ATNSerializer.java:375)
at org.antlr.v4.codegen.model.SerializedATN.<init>(SerializedATN.java:46)
at org.antlr.v4.codegen.model.Parser.<init>(Parser.java:96)
at org.antlr.v4.codegen.ParserFactory.parser(ParserFactory.java:92)
at org.antlr.v4.codegen.OutputModelController.parser(OutputModelController.java:165)
at org.antlr.v4.codegen.OutputModelController.buildParserOutputModel(OutputModelController.java:114)
at org.antlr.v4.codegen.CodeGenerator.generateParser(CodeGenerator.java:169)
at org.antlr.v4.codegen.CodeGenPipeline.process(CodeGenPipeline.java:73)
at org.antlr.v4.Tool.processNonCombinedGrammar(Tool.java:422)
at org.antlr.v4.Tool.process(Tool.java:384)
at org.antlr.v4.Tool.processGrammarsOnCommandLine(Tool.java:343)
at org.antlr.v4.Tool.main(Tool.java:190)
现在,如果我从代码中删去几行,这将编译。制定此新规则已引发此异常。此外,如果我从这条规则本身中删除几行,则不会引发异常。
是不是因为我的语法变大了?无法弄清楚这个错误。
此外,即使我删除了其他一些独立规则,我也没有遇到这样的错误。语法文件的大小有限制吗?
我的语法文件大约有 800 行。