43 %token <string> STRING
51 /* from lowest precedence */
54 %nonassoc EQ NEQ GT LT GE LE
58 /* to highest precedence */
60 %type <string> program
69 sprintf "program[%s]" $1
81 | MINUS exp %prec UMINUS
83 sprintf "negation[%s]" $2
85 | type_id LBRACK exp RBRACK OF exp
87 sprintf "array[type[%s], size[%s], val[%s]]" $1 $3 $6
89 | type_id LBRACE rec_field_assignments RBRACE
91 sprintf "record[type[%s], rec_field_assignments[%s]]" $1 $3
99 sprintf "assign[%s := %s]" $1 $3
103 sprintf "string[%S]" $1
111 sprintf "op[%s %s %s]" $1 $2 $3
113 | IF exp THEN exp ELSE exp
118 sprintf "if_then_else[%s, then[%s], else[%s]]" e1 e2 e3
122 sprintf "if_then[%s, then[%s]]" $2 $4
126 sprintf "while[%s, do[%s]]" $2 $4
128 | FOR id ASSIGN exp TO exp DO exp
134 sprintf "for[%s := %s, to[%s], do[%s]]" id e1 e2 e3
144 | LET decs IN seq END
148 sprintf "let[decs[%s], in[seq[%s]]]" decs seq
162 sprintf "%s; %s" $1 $3
172 sprintf "%s %s" $1 $2
181 | FUNCTION id LPAREN tyfields RPAREN EQ exp
186 sprintf "fundec[%s, tyfields[%s], exp[%s]]" id tyfields exp
188 | FUNCTION id LPAREN tyfields RPAREN COLON type_id EQ exp
195 "fundec[%s, tyfields[%s], type_id[%s], exp[%s]]"
196 id tyfields type_id exp
204 sprintf "vardec[%s, exp[%s]]" id exp
206 | VAR id COLON type_id ASSIGN exp
211 sprintf "vardec[%s, type_id[%s], exp[%s]]" id tyid exp
217 sprintf "tydec[%s, %s]" $2 $4
227 | LBRACE tyfields RBRACE
230 sprintf "record[%s]" tyfields
235 sprintf "array_of_type[%s]" type_id
242 | tyfield COMMA tyfields
246 sprintf "%s, %s" tyfield tyfields
254 sprintf "tyfield[%s, %s]" id type_id
263 /* Perhaps "void"? */
273 sprintf "type_id[%S]" $1
276 rec_field_assignments:
279 sprintf "%S = %s" $1 $3
281 | id EQ exp COMMA rec_field_assignments
283 sprintf "%S = %s, %s" $1 $3 $5
289 sprintf "fun_call[%s, %s]" $1 $2
291 | id LPAREN fun_args RPAREN
293 sprintf "fun_call[%s, %s]" $1 $3
303 sprintf "%s, %s" $1 $3
323 sprintf "lvalue[%s]" $1
327 sprintf "get_record_field[%s, %s]" $1 $3
329 | lvalue LBRACK exp RBRACK
331 sprintf "get_array_subscript[%s, %s]" $1 $3