Project Grammar

{ }'s not within quotes are metasymbols meaning "0 or more"

[ ]'s not within quotes are metasymbols meaning "0 or 1"


executable-part           -> 'execute' '{' [statements] '}' 

statements	          -> statements statement | statement
 
statement                 -> tell-statement |
			     new-statement  |
			     iterate-statement|		 	
			     remove-statement    /* left place statement out */

tell-statement		 -> tell robot-name ':' instructions 
tell                     -> 'tell' | 'Tell'	

instructions             -> '{' {instruction} '}' | instruction

new-statement            -> new robot-type object-name ['at' coords]';'
new                      -> 'new' | 'New'

iterate-statement        ->  iterate expression 'times' statement
                            | iterate expression 'times' statement '{'statements '}' 
iterate                  ->  'iterate' | 'Iterate'
  
remove-statement         -> remove robot-name ';'
remove                   -> 'remove' | 'Remove'

instruction              -> simple-instruction ';' |
			    control-instruction |
			    assignment-instruction

simple-instruction       ->  move  expression |
			     pickbeeper |
			     putbeeper |
			     turnleft |
			     turnoff

move                     -> 'Move' | 'move'
pickbeeper               -> 'pickbeeper' | 'PickBeeper' | 'pick_beeper'
putbeeper                ->  'putbeeper'| 'PutBeeper' |  'put_beeper'
turnleft                 ->  'turnleft' | 'TurnLeft' | 'turn_left'
turnoff                  ->  'turnoff' | 'TurnOff ' | 'turn_off'



control-instruction       ->  if-instruction |
			    iterate-instruction |
			    while-instruction        

if-instruction            ->  if '(' expression ')' instructions
                           else  instructions |
			   if '(' expression ')' instructions

if                     	   -> 'if' | 'If'
else                       -> 'else' | 'Else'

iterate-instruction        -> iterate expression 'times' instructions

while-instruction	   ->  while  expression instructions 
while                      ->  'While' | 'while'
 
assignment-instruction     ->   variable-name '=' expression ';'

robot-name            	   ->   object-name

robot-type	           -> variable-name

variable-name              ->   object-name

object-name                ->   letter { lettdig }

coords		           ->  expression "," expression

lettdig                    ->    letter | digit | '_'

letter                     ->    'A'..'Z' | 'a'..'z'

digit                      ->    '0'..'9'


Expression Grammar

expression           -> relation {and relation} |
                        relation {or relation}

relation	     -> simple_expression [relop simple_expression]

simple_expression    -> [sign] term {addop term}
			
term                 -> term mulop factor |
			factor

factor               -> not factor | ident | bool_function |
			'(' expression ')'

ident                -> variable-name | literal | integer_function

literal              -> {digit}+

not                  -> '!' | 'not'

relop                -> '==' | '!=' | '<' | '>' | '<=' | '>='

addop                -> '+' | '-' 

or                   -> 'or' | '||'

mulop                -> '*' | '/' 

and                  -> 'and' | '&&'

bool_function        -> 'front_is_clear' | 'FrontIsClear' |
                        'right_is_clear' | 'RightIsClear' |
			'left_is_clear' | 'LeftIsClear' |
			'facing_north' | 'FacingNorth'
			'facing_south' | 'FacingSouth'
			'facing_east' | 'FacingEast'
			'facing_west' | 'FacingWest'

integer_function     -> 'beepers_in_bag' | 'BeepersInBag' |
		        'beepers_on_floor' | 'BeepersOnFloor' |
		         'x_position' | 'XPosition'
		         'y_position' | 'YPosition'

sign		     -> '+' | '-'




Send questions and comments to: Karen Lemone