1

我正在尝试解析 Prolog 术语,规则如下:

term[ReadOptions Options, int priority]
:
simpleTerm[$Options]
|
term[$Options, $priority - 1]
;

但是运行 ANTLR 会抛出以下错误:

can't find rule grammarSpec or tree structure error:
...My complete code here...
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)          
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:601)
org.antlr.v4.parse.GrammarTreeVisitor.visit(GrammarTreeVisitor.java:206)
org.antlr.v4.parse.GrammarTreeVisitor.visitGrammar(GrammarTreeVisitor.java:200)
org.antlr.v4.semantics.SymbolCollector.process(SymbolCollector.java:76)
org.antlr.v4.semantics.SemanticPipeline.process(SemanticPipeline.java:103)
org.antlr.v4.Tool.processNonCombinedGrammar(Tool.java:399)
...
org.antlr.v4.tool.LeftRecursiveRule.getAltLabels(LeftRecursiveRule.java:91)
org.antlr.v4.tool.Rule.hasAltSpecificContexts(Rule.java:200)
org.antlr.v4.tool.LeftRecursiveRule.hasAltSpecificContexts(LeftRecursiveRule.java:60)
org.antlr.v4.semantics.SymbolChecks.checkForLabelConflicts(SymbolChecks.java:150)
org.antlr.v4.semantics.SymbolChecks.process(SymbolChecks.java:98)
org.antlr.v4.semantics.SemanticPipeline.process(SemanticPipeline.java:107)
org.antlr.v4.Tool.processNonCombinedGrammar(Tool.java:399)
org.antlr.v4.Tool.process(Tool.java:384)
org.antlr.v4.Tool.processGrammarsOnCommandLine(Tool.java:343)
org.antlr.v4.Tool.main(Tool.java:190)

删除我的规则的最后一行会删除所有错误。如果我写

term[ReadOptions Options, int priority]
:
simpleTerm[$Options]
;

ANTLR4 不应该能够处理只涉及直接左递归的语法吗?

4

0 回答 0