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".
Thanks,
MPinnegar
****GRAMMAR BELOW THIS LINE****
grammar RobotWarsGrammar;
//Parser rules
codeline
: comment
| routine
;
comment
: !(DIGIT | LETTER | SPACE)*
;
routine
: subroutine
| main_program
;
subroutine
: 'SUBROUTINE' IDENTIFIER LPAREN parameters RPAREN LCURL block* RCURL
return_statement
;
parameters
: variable_name (',' variable_name)*
|
;
return_statement
: 'RETURN' variable_name
;
main_program
: 'MAIN' LCURL block* RCURL
;
block
: statement*
;
statement
: if
| while
| call
| variable_assignment
| game_order
;
if
: if_only
| if_else
;
if_only
: 'IF' LPAREN expression CONDITION expression RPAREN LCURL block RCURL
;
if_else
: 'IF-ELSE' LPAREN expression CONDITION expression RPAREN LCURL block
'ELSE' block RCURL
;
while
: 'WHILE' LPAREN expression CONDITION expression RPAREN LCURL block
RCURL
;
call
: variable_name EQUAL IDENTIFIER LPAREN parameters RPAREN SEMICOLON
| IDENTIFIER LPAREN parameters RPAREN SEMICOLON
;
variable_assignment
: 'VAR' variable_name EQUAL DIGIT+ SEMICOLON
| 'VAR' variable_name EQUAL game_function SEMICOLON
| 'VAR' variable_name EQUAL expression SEMICOLON
;
variable_name
: IDENTIFIER
;
expression
: term (ADDOP term)*
;
term
: factor (MULTOP factor)*
;
factor
: LPAREN expression RPAREN
| DIGIT+
| variable_name
;
game_function
: 'IS_ENEMY_IN_RANGE' LPAREN parameters RPAREN
;
game_order
: 'FIRE_WEAPON' LPAREN parameters RPAREN
;
// Lexer rules
IDENTIFIER
: LETTER (LETTER|DIGIT)*
;
LETTER
: ('a'..'z'|'A'..'Z')
| '_'
| '-'
;
DIGIT
:'0'..'9'
;
ADDOP
: '+'
| '-'
;
MULTOP
: TIMES
| DIVIDE
| MOD
;
CONDITION
: '!='
| '=='
| '<'
| '>'
| '<='
| '>='
;
SPACE
options {
paraphrase = " ";
}
: ' '
;
SEMICOLON
options {
paraphrase = ";";
}
: ';'
;
LPAREN
options {
paraphrase = "(";
}
: '('
;
RPAREN
options {
paraphrase = ")";
}
: ')'
;
LCURL
options {
paraphrase = "{";
}
: '{'
;
RCURL
options {
paraphrase = "}";
}
: '}'
;
PLUS
options {
paraphrase = "+";
}
: '+'
;
MINUS
options {
paraphrase = "-";
}
: '-'
;
TIMES
options {
paraphrase = "*";
}
: '*'
;
DIVIDE
options {
paraphrase = "/";
}
: '/'
;
MOD
options {
paraphrase = "%";
}
: '%'
;
EQUAL
options {
paraphrase = "=";
}
: '='
;
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---