The Grammar for Project 2

This grammar describes the language that must be parsed by the parser of project 2. It is the upper part of this grammar - all nonterminals after expr were removed and the productions for expr were changed. Nonterminals are shown in lower-case, terminals (tokens) are shown in upper-case, and the empty string is denoted by . Click here for the list of the tokens.


program --> PROGTOK ID LPAR id_list RPAR SEMICOL declarations subroutines block DOT
id_list --> ID | id_list COMMA ID
declarations --> declarations VARTOK declaration SEMICOL |
declaration --> ID declaration_rest
declaration_rest --> COMMA ID declaration_rest | COLON type
type --> standard_type | ARRAYTOK LBRK NUM DOTDOT NUM RBRK OFTOK standard_type
standard_type --> INTTOK | REALTOK | BOOLTOK
subroutines --> subroutines subroutine SEMICOL |
subroutine --> sub_head declarations block
sub_head --> FUNC ID arguments COLON standard_type SEMICOL | PROC ID arguments SEMICOL
arguments --> LPAR parameter_list RPAR |
parameter_list --> declaration | parameter_list SEMICOL declaration
block --> BEGINTOK block_rest
block_rest --> statement_list ENDTOK | ENDTOK
statement_list --> statement | statement_list SEMICOL statement
statement --> variable ASSIGNOP expr | procedure_call | block | IFTOK expr THENTOK statement ELSETOK statement | WHILETOK expr DOTOK statement
variable --> ID | ID LBRK expr RBRK
procedure_call --> ID | ID LPAR expr_list RPAR
expr_list --> expr | expr_list COMMA expr
expr --> NUM | BCONST

Kenneth E. Batcher - 1/12/2006