CIT 594 “Logo2006” Grammar
Spring 2006, David Matuszek

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

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

The following productions are handled by your Tokenizer, and are the raw input to your Recognizer:
<NAME> ::= <letter> { <letter> | <digit> | "_" }

<NUMBER> ::= <digit> { <digit> }

<SYMBOL> ::= "+" | "-" | "*" | "/" | "=" | "(" | ")" | "[" | "]" 

<EOL> ::=  end of string "\n"

<END_OF_INPUT> ::= end of string

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

<variable> ::= <NAME>

<program> ::= <command> { <command> } { <procedure> }

<command> ::= "move" <expression> <eol>
                         | "turn" <direction> <eol>
                         | "penup" <eol>
                         | "pendown" <eol>
                         | "color" <colorName> <eol>
                         | "home" <eol>
                         | <variable> "=" <expression> <eol>
                         | "repeat" <expression> <block>
                         | "while" <condition> <block> 
                         | "if" <condition> <block> [ "else" <block> ]
                         | "call" <NAME> { <expression> } <eol>

<direction> ::= "north"
                        | "east"
                        | "south"
                        | "west"
                        | "left" [ <expression> ]
                        | "right" [ <expression> ]

<colorName>  ::= "magenta" | "red" | "orange" | "yellow" | "green" | "aqua"
                            | "blue" | "purple" | "violet" | "brown" | "black" | "charcoal"
                            | "gray" | "grey" | "white" | "pink"

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

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

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

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

<conjunct> ::= [ "not" ] <logicalExpression> <logicalFactor>

<logicalExpression>
<logicalFactor> ::= <comparison> | "(" <condition> ")" <comparator> ::= "<" | "=" | ">" <procedure> ::= "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> { <addOperator> <term> } 

<term> ::= <factor> { <multiplyOperator> <factor> }

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

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

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