AntlrWorks&语言语法错误 [英] AntlrWorks & language grammar errors

查看:364
本文介绍了AntlrWorks&语言语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用涉及脚本语言的游戏项目,我想将其解释为可以直接执行的虚拟机代码。我已经包括了下面的语法。所有词法规则在语法图中正确显示,但是当我点击任何解析器规则的主体时,由于给定的解析器规则X,我得到无法显示规则X,因为未找到开始状态 / p>

我不太确定为什么ANTLR抱怨没有开始状态。语法应该清楚地从codeline开始,它没有被任何其他解析器规则引用。此外,右上方的框是绿色的,表示没有语法错误。



我梳理了一些其他留言板帖子,以及许多语法在ANTLRv3样本语法下载中提供,但是它们都没有任何特殊的代码向ANTLR指示哪个解析器规则是开始状态。我觉得简单的东西坏了,但是我真的是一个僵局。这是什么。



任何建议或帮助将非常感谢!即使它只是沿着去读这个的线。

 语法RobotWarsGrammar; 



EQUAL
选项{
paraphrase ==;
}
:'='
;


解决方案

假设您使用ANTLR 3.x.



所有:

 选项{
paraphrase =。 ..;
}

stuff是(AFAIK)旧ANTLR 2语法 - / p>

此外,注释中的 / p>

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

是一个 tree-rewrite-operator 查看备忘单)。但只有当你有:

 选项{
output = AST;
}

因此,从你的注释中删除​​除非你想匹配文本,在这种情况下,你需要在它周围单引号:

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


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 = "=";
}
   : '='
   ;

解决方案

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)*
  ;

这篇关于AntlrWorks&语言语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆