This is the grammar for the subset of Pascal used in the coding projects. Nonterminals are shown in lower-case, terminals (tokens) are shown in upper-case, and the empty string is denoted by e. 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 | e |
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 | e |
subroutine | --> | sub_head declarations block |
sub_head | --> | FUNC ID arguments COLON standard_type SEMICOL | PROC ID arguments SEMICOL |
arguments | --> | LPAR parameter_list RPAR | e |
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 | --> | bool_expr | arith_expr |
bool_expr | --> | bool_expr OROP bool_term | bool_term |
bool_term | --> | bool_term ANDOP bool_factor | bool_factor |
bool_factor | --> | arith_expr RELOP arith_expr | BCONST | ID | ID LPAR expr_list RPAR | LPAR bool_expr RPAR | NOTOP bool_factor | ID LBRK expr RBRK |
arith_expr | --> | arith_expr ADDOP term | term |
term | --> | term MULOP factor | factor |
factor | --> | ID | ID LPAR expr_list RPAR | NUM | LPAR arith_expr RPAR | ID LBRK expr RBRK | UNARYOP factor |