CIT 594 “RoboTalk” Grammar
Spring 2007, David Matuszek

This page describes the grammar used by our Recognizer for the "RoboTalk" language.

Extended BNF Key
::= "is defined by"
| "or"
<...> nonterminal
"..." terminal
[...] optional
{...} zero or more

The following productions are handled by the Tokenizer, and are the raw input to your Recognizer:
<NAME> ::= <letter> { <letter> | <digit> | "_" }
 
<NUMBER> ::= <digit> { <digit> }
 
<SYMBOL> ::= "+" | "-" | "*" | "/"| "%" | "="| "<" | ">" | "(" | ")" | "{" | "}" 

<EOL> ::=  "\n"

<EOF> ::= end of string

The following productions are not handled by your Tokenizer, but must instead be handled by your Recognizer:

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

<command> ::= <action>
                          |   <repeat statement>
                          |   <while statement> 
                          |   <if statement>
                          |   <return statement>
                          |   <assignment statement>
                          |   <method 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> } ] ")"

<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>

<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> } 

I have given you starter code for your Recognizer, with methods to handle the following productions:

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


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


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

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

<multiplyOperator> ::= "*"| "/"| "%"
The definition of <factor> that I have provided needs to be expanded a bit. Modify it as follows:

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