Yacc: Pascal Subset
program : statement DOT /* change this! */ { parseresult = $1; } ; statement : BEGINBEGIN statement endpart { $$ = makeprogn($1,cons($2,$3)); } | IF expr THEN statement endif { $$ = makeif($1, $2, $4, $5); } | assignment ; endpart : SEMICOLON statement endpart { $$ = cons($2, $3); } | END { $$ = NULL; } ; endif : ELSE statement { $$ = $2; } | /* empty */ { $$ = NULL; } ; assignment : variable ASSIGN expr { $$ = binop($2, $1, $3); } ; expr : expr PLUS term { $$ = binop($2, $1, $3); } | term ; term : term TIMES factor { $$ = binop($2, $1, $3); } | factor ; factor : LPAREN expr RPAREN { $$ = $2; } | variable | NUMBER ; variable : IDENTIFIER ;