开发者

AntlrWorks & language grammar errors

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 rul开发者_运维技巧es 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)*
  ;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜