AntlrWorks &语言语法错误

发布于 2024-10-05 14:24:30 字数 481 浏览 8 评论 0原文

正在开发一个涉及脚本语言的游戏项目,我想将其解释为可以直接执行的虚拟机代码。我已将语法包含在下面。所有词法分析器规则都在语法图中正确显示,但是当我单击任何解析器规则的主体时,对于给定的解析器规则 X,我得到“无法显示规则“X”,因为未找到起始状态”

。我不太确定为什么 ANTLR 抱怨没有启动状态。语法应该明确地从代码行开始,任何其他解析器规则都不会引用该代码行。另外,右上角的框是绿色的,表示没有语法错误。

我梳理了其他一些留言板帖子,以及 ANTLRv3 示例语法下载中提供的许多语法,但它们都没有任何特殊代码来向 ANTLR 指示哪一个解析器规则是起始状态。我觉得一些简单的东西被打破了,但我对它到底是什么陷入了僵局。

任何建议或帮助将不胜感激!即使只是“去读一下这个”。

grammar RobotWarsGrammar;



EQUAL
options {
    paraphrase = "=";
}
   : '='
   ;

Working on a game project that involves a scripting language that I want to interpret into a virtual machine code that can be executed directly. I've included the grammar below. All the lexer rules are displaying properly in the syntax diagram, but when I click on the bodies of any of the parser rules, I get "Cannot display rule "X" because start state is not found" for a given parser rule X.

I'm not really sure why ANTLR is complaining about not having a start state. The grammar should plainly start from codeline, which isn't referenced by any other parser rule. Also, the box in the upper right is green, indicating there are no syntax errors.

I combed through some of the other message board posts, as well as many of the grammars provided in the ANTLRv3 sample grammar download, but none of them have any special code that indicates to ANTLR which one of the parser rules is the start state. I feel like something simple is broken, but I'm at an impasse as to what exactly that is.

Any advice or assistance would be much appreciated! Even if it's just along the lines of "go read this".

grammar RobotWarsGrammar;



EQUAL
options {
    paraphrase = "=";
}
   : '='
   ;

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

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

发布评论

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

评论(1

断念 2024-10-12 14:24:30

假设您使用的是 ANTLR 3.x。

所有这些:

options {
    paraphrase = ...;
}

东西是(据我所知)旧的 ANTLR 2 语法 - 尝试删除它。

另外,您的 comment 规则中的 !

comment
  :  !(DIGIT | LETTER | SPACE)*
  ;

是一个 tree-rewrite-operator (查看备忘单)。但这只有

options { 
  output=AST;
}

在你的语法中有以下内容时才有效(你没有)。因此,请从您的 comment 规则中删除该 ! 。除非你想匹配文字 !,在这种情况下你需要用单引号括起来:

comment
  :  '!' (DIGIT | LETTER | SPACE)*
  ;

Assuming you're using ANTLR 3.x.

All that:

options {
    paraphrase = ...;
}

stuff is (AFAIK) old ANTLR 2 syntax -- try removing it.

Also, that ! in your comment rule:

comment
  :  !(DIGIT | LETTER | SPACE)*
  ;

is a tree-rewrite-operator (see the cheat sheet). But that only works when you have:

options { 
  output=AST;
}

in your grammar (which you don't). So, remove that ! from your comment rule as well. Unless you want to match the literal !, in which case you need to wrap single quotes around it:

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