神秘的 ANTLR 错误

发布于 2025-01-07 21:28:30 字数 957 浏览 3 评论 0原文

我所知道的是它阻止了 antlr 的生成,我很抱歉。这是日志文件:

(10): internal error: /Bridge/bridge.g : java.lang.IllegalStateException: java.lang.NullPointerException 
 org.deved.antlride.runtime.AntlrErrorListener$DynamicToken.invokeMethod(AntlrErrorListener.java:59) 
 org.deved.antlride.runtime.AntlrErrorListener$DynamicToken.getLine(AntlrErrorListener.java:64) 
 org.deved.antlride.runtime.AntlrErrorListener.report(AntlrErrorListener.java:131) 
 org.deved.antlride.runtime.AntlrErrorListener.message(AntlrErrorListener.java:115) 
 org.deved.antlride.runtime.AntlrErrorListener.warning(AntlrErrorListener.java:99) 
 org.antlr.tool.ErrorManager.grammarWarning(ErrorManager.java:742) 
 org.antlr.tool.ErrorManager.grammarWarning(ErrorManager.java:757) org.antlr.tool.Grammar.parseAndBuildAST(Grammar.java:655) 
 org.antlr.Tool.getRootGrammar(Tool.java:626) org.antlr.Tool.process(Tool.java:459) 
 org.deved.antlride.runtime.Tool2.main(Tool2.java:24)

All I know is that it's stopping antlr from generating, I apologize. Here's the log file:

(10): internal error: /Bridge/bridge.g : java.lang.IllegalStateException: java.lang.NullPointerException 
 org.deved.antlride.runtime.AntlrErrorListener$DynamicToken.invokeMethod(AntlrErrorListener.java:59) 
 org.deved.antlride.runtime.AntlrErrorListener$DynamicToken.getLine(AntlrErrorListener.java:64) 
 org.deved.antlride.runtime.AntlrErrorListener.report(AntlrErrorListener.java:131) 
 org.deved.antlride.runtime.AntlrErrorListener.message(AntlrErrorListener.java:115) 
 org.deved.antlride.runtime.AntlrErrorListener.warning(AntlrErrorListener.java:99) 
 org.antlr.tool.ErrorManager.grammarWarning(ErrorManager.java:742) 
 org.antlr.tool.ErrorManager.grammarWarning(ErrorManager.java:757) org.antlr.tool.Grammar.parseAndBuildAST(Grammar.java:655) 
 org.antlr.Tool.getRootGrammar(Tool.java:626) org.antlr.Tool.process(Tool.java:459) 
 org.deved.antlride.runtime.Tool2.main(Tool2.java:24)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

国产ˉ祖宗 2025-01-14 21:28:30

我对逻辑公式的简单语法也遇到了同样的错误。对我来说,问题是 ANTLR 找不到明显的开始规则,因为我对预期的开始规则进行了递归。添加指向递归规则的新规则即可完成这项工作(请参阅 http://thesoftwarelife .blogspot.com/2008/07/antlr-frustrations.html)。

遗憾的是ANTLR IDE没有正确转发错误消息。在命令行上我得到:

warning(138): Formula.g:0:1: 语法 Formula: 无起始规则(EOF 后显然没有任何规则)

I got the same error with a simple grammar for logical formulas. For me the problem was, that ANTLR could not find an obvious start rule because I had a recursion on my intended start rule. Adding a new rule pointing to the recursive one did the job (see http://thesoftwarelife.blogspot.com/2008/07/antlr-frustrations.html).

It's a pity that ANTLR IDE does not correctly forward the error message. On the command line i get:

warning(138): Formula.g:0:1: grammar Formula: no start rule (no rule can obviously be followed by EOF)

意犹 2025-01-14 21:28:30

我昨天也遇到了同样的问题。不确定我的情况是否与您的相同,但值得一试。我有一个名为注释的规则,如下所示:

annotation
    : AT class declaration?
        -> ^(ANNOTATION class declaration?)
    ;

我想解析大括号中的子注释,所以我这样做了:

subAnnotation:
    : CURLY_START annotation CURLY_END
       -> ^(ANNOTATION annotation)
    ;

这给了我与你相同的错误。所以,我最终想知道它不起作用。即使我不确定,我认为问题是导致错误的注释规则的递归。所以,我最终这样做了:

annotationValue:
    : CURLY_START subAnnotation CURLY_END
       -> ^(ANNOTATION subAnnotation)
    ;

subAnnotation
    : AT class declaration?
       -> ^(ANNOTATION class declaration?)
    ;

这解决了我的问题。就像我说的,我不知道这个修复是否可以应用于您的问题。此外,我认为 ANTLR 能够处理非左递归规则。也许对该工具有更了解的人可以证实这一点。

我必须承认我没有尝试@BartKiers的建议,也许它也能解决问题。

问候,
马特

I had the same problem yesterday. Not sure if my case is identical to yours but it worth a try. I had a rule named annotation like this:

annotation
    : AT class declaration?
        -> ^(ANNOTATION class declaration?)
    ;

And I wanted to parse sub annotations in curly braces so I did:

subAnnotation:
    : CURLY_START annotation CURLY_END
       -> ^(ANNOTATION annotation)
    ;

This was given me the same error has yours. So, I end up wondering with it is not working. Even if I'm unsure, I think the problem is the recursion of the annotation rule that was causing the error. So, I ended up doing this:

annotationValue:
    : CURLY_START subAnnotation CURLY_END
       -> ^(ANNOTATION subAnnotation)
    ;

subAnnotation
    : AT class declaration?
       -> ^(ANNOTATION class declaration?)
    ;

This resolved my problem. Like I said, I don't know if this fix can be applied to your problem. Moreover, I thought that ANTLR was able to deal with non-left-recursive rule. Maybe someone with a better knowledge of the tool could confirm it.

I must admit I did not try the suggestion of @BartKiers, maybe it would also solve the problem.

Regards,
Matt

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文