跟踪许多规则文件中的ANTLR错误?

时间:2022-10-29 16:58:28

I'm about to migrate this PHP EBNF to ANTLR v4 format.

我即将将这个PHP EBNF迁移到ANTLR v4格式。

Unfortunately, ANTLR breaks with the message can't find rule grammarSpec or tree structure error:

不幸的是,ANTLR中断了消息无法找到规则grammarSpec或树结构错误:

can't find rule grammarSpec or tree structure error: 
(COMBINED_GRAMMAR Php (RULES (RULE start (BLOCK (ALT (top_statement_list 0)))) 
(RULE top_statement_list int _p (BLOCK (ALT (BLOCK (ALT {})) (* (BLOCK (ALT {2 >= 
...

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.antlr.v4.parse.GrammarTreeVisitor.visit(GrammarTreeVisitor.java:206)
    at org.antlr.v4.parse.GrammarTreeVisitor.visitGrammar(GrammarTreeVisitor.java:200)
    at org.antlr.v4.semantics.SymbolCollector.process(SymbolCollector.java:76)
    at org.antlr.v4.semantics.SemanticPipeline.process(SemanticPipeline.java:103)
    at org.antlr.v4.Tool.processNonCombinedGrammar(Tool.java:399)
    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)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 2
    at org.antlr.v4.semantics.SymbolCollector.discoverOuterAlt(SymbolCollector.java:111)
    at org.antlr.v4.parse.GrammarTreeVisitor.outerAlternative(GrammarTreeVisitor.java:2284)
    at org.antlr.v4.parse.GrammarTreeVisitor.ruleBlock(GrammarTreeVisitor.java:2197)
    at org.antlr.v4.parse.GrammarTreeVisitor.rule(GrammarTreeVisitor.java:1663)
    at org.antlr.v4.parse.GrammarTreeVisitor.rules(GrammarTreeVisitor.java:1241)
    at org.antlr.v4.parse.GrammarTreeVisitor.grammarSpec(GrammarTreeVisitor.java:480)
    ... 12 more
Exception in thread "main" java.lang.NullPointerException
    at org.antlr.v4.tool.LeftRecursiveRule.getAltLabels(LeftRecursiveRule.java:91)
    at org.antlr.v4.tool.Rule.hasAltSpecificContexts(Rule.java:200)
    at org.antlr.v4.tool.LeftRecursiveRule.hasAltSpecificContexts(LeftRecursiveRule.java:60)
    at org.antlr.v4.semantics.SymbolChecks.checkForLabelConflicts(SymbolChecks.java:150)
    at org.antlr.v4.semantics.SymbolChecks.process(SymbolChecks.java:98)
    at org.antlr.v4.semantics.SemanticPipeline.process(SemanticPipeline.java:107)
    at org.antlr.v4.Tool.processNonCombinedGrammar(Tool.java:399)
    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)

If I reduce the number of rules, the problem doesn't appear, but ANTLR complains about missing symbols.

如果我减少规则数量,问题就不会出现,但ANTLR会抱怨缺少符号。

Could anybody provide hints how to track down the error? Don't see a alternative to reduce the rule count.

任何人都可以提供如何追踪错误的提示吗?没有看到减少规则数量的替代方案。

1 个解决方案

#1


0  

One of the following is occurring in your grammar (which is not included in the question):

您的语法中出现以下情况之一(未包含在问题中):

  1. It contains a syntax error which the ANTLR 4 grammar compiler is not able to recover from.

    它包含ANTLR 4语法编译器无法从中恢复的语法错误。

  2. You found a bug in the ANTLR 4 grammar compiler, which should be reported to the project issue tracker.

    您在ANTLR 4语法编译器中发现了一个错误,应该将其报告给项目问题跟踪器。

#1


0  

One of the following is occurring in your grammar (which is not included in the question):

您的语法中出现以下情况之一(未包含在问题中):

  1. It contains a syntax error which the ANTLR 4 grammar compiler is not able to recover from.

    它包含ANTLR 4语法编译器无法从中恢复的语法错误。

  2. You found a bug in the ANTLR 4 grammar compiler, which should be reported to the project issue tracker.

    您在ANTLR 4语法编译器中发现了一个错误,应该将其报告给项目问题跟踪器。