CIT 594 “RoboTalk” Grammar--With Changes
Spring 2007, David Matuszek

This page describes the grammar used by our Recognizer for the "RoboTalk" language, with the changes we discussed in class last week. Please use the name isAssignOrCall and isAssignOrCallExtender for your new methods. Also, as discussed, it's a good idea to have a keyword(String) or isKeyword(String) method, but this is not (yet) required.

<program> ::= <command> { <command> }  { <method> }  <EOF>

<command> ::= <action>
                          |   <repeat statement>
                          |   <while statement> 
                          |   <if statement>
                          |   <return statement>
                          |   <assignment statement>
                          |   <assign or call> <eol>

<action> ::= <move action>
                   |   <turn action>
                   |   <take action>
                   |   <drop action>
                   |   <zap action>

<move action> ::= "move" <expression> <eol>

<turn action> ::= "turn" <direction> <eol>

 <take action> ::= "take" <thing> <eol>

<drop action> ::= "drop" <thing> <eol>

<zap action> ::="zap" <eol>

<repeat statement> ::= "repeat" <expression> <block>

<while statement> ::= "while" <condition> <block>

<if statement> ::= "if" <condition> <block> [ "else" <block> ]

<return statement> ::= "return" <expression> <eol>

<assignment statement> ::= <variable> "=" <expression> <eol>

<method call> ::= <variable> "(" [ <expression> { "," <expression> } ] ")"

<assign or call> ::= <variable> <assign or call extender>

<assign or call extender> ::=  "=" <expression>
                                                   |  "(" [ <expression> { "," <expression> } ] ")"

<assignment statement> ::= <variable> "=" <expression> <eol>

<variable> ::= <NAME>

<direction> ::= "north"
                       | "east"
                       | "south"
                       | "west"
                       | "left"
                       | "right"
                       | "around"

<thing> ::= "WALL"
                     | "ENEMY"
                     | "FUEL"
                     | "ARMOR"
                     | "ZAP_GUN"

<block> ::= "{" <eol> { <command> }  "}" <eol>

<comparison> ::= <expression> <comparator> <expression>

<condition> ::= <logicalCondition>
                          | "seeing" <thing>
                          | "smelling" <thing>
                          | "facing" <thing> <direction>

<logical condition> ::= <disjunct> { "or" <disjunct> }

<disjunct> ::= <conjunct> { "and" <conjunct> }

<conjunct> ::= [ "not" ] <logical factor>

<logical factor> ::= <comparison>

<comparator> ::= "<" | "<=" | "=" | "!=" ">=" | ">"

<method> ::= "define" <NAME> { <variable> } <eol> { <command> } "end" <eol>

<eol> ::= <EOL> { <EOL> }
<expression> ::= <term> { <add operator> <term> } 


<term> ::= <factor> { <multiply operator> <factor> }


<factor> ::= <variable>
                  | <NUMBER>
                  | "(" <expression> ")"
                  | "distance"
                  | <method call>

<addOperator> ::= "+" | "-"

<multiplyOperator> ::= "*"| "/"| "%"