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 | ID LBRACK exp RBRACK OF exp
90 sprintf "array[type[%s], size[%s], val[%s]]" type_id exp_1 exp_2
92 | ID LBRACE rec_field_assignments RBRACE
95 let rec_field_assignments = $3 in
97 "record[type[%s], rec_field_assignments[%s]]"
98 type_id rec_field_assignments
106 sprintf "assign[%s := %s]" $1 $3
110 sprintf "string[%S]" $1
115 sprintf "fun_call[%s, []]" id
117 | ID LPAREN fun_args RPAREN
121 sprintf "fun_call[%s, %s]" id fun_args
125 sprintf "op[%s %s %s]" $1 $2 $3
127 | IF exp THEN exp ELSE exp
132 sprintf "if_then_else[%s, then[%s], else[%s]]" e1 e2 e3
136 sprintf "if_then[%s, then[%s]]" $2 $4
140 sprintf "while[%s, do[%s]]" $2 $4
142 | FOR ID ASSIGN exp TO exp DO exp
148 sprintf "for[%s := %s, to[%s], do[%s]]" id e1 e2 e3
158 | LET decs IN seq END
162 sprintf "let[decs[%s], in[seq[%s]]]" decs seq
176 sprintf "%s; %s" $1 $3
186 sprintf "%s %s" $1 $2
195 | FUNCTION ID unit EQ exp
199 sprintf "fundec[%s, exp[%s]]" id exp
201 | FUNCTION ID LPAREN tyfields RPAREN EQ exp
206 sprintf "fundec[%s, tyfields[%s], exp[%s]]" id tyfields exp
208 | FUNCTION ID LPAREN tyfields RPAREN COLON ID EQ exp
215 "fundec[%s, tyfields[%s], type_id[%s], exp[%s]]"
216 id tyfields type_id exp
224 sprintf "vardec[%s, exp[%s]]" id exp
226 | VAR ID COLON ID ASSIGN exp
231 sprintf "vardec[%s, type_id[%s], exp[%s]]" id type_id exp
239 sprintf "tydec[%s, %s]" type_id ty
246 sprintf "type[type_id[%S]]" type_id
252 | LBRACE tyfields RBRACE
255 sprintf "record[%s]" tyfields
260 sprintf "array_of_type[%s]" type_id
267 | tyfield COMMA tyfields
271 sprintf "%s, %s" tyfield tyfields
279 sprintf "tyfield[%s, %s]" id type_id
282 /* Perhaps "void"? */
289 rec_field_assignments:
294 sprintf "%S = %s" id exp
296 | ID EQ exp COMMA rec_field_assignments
300 let rec_field_assignments = $5 in
301 sprintf "%S = %s, %s" id exp rec_field_assignments
311 sprintf "%s, %s" $1 $3
332 sprintf "lvalue[%s]" id
338 sprintf "get_record_field[%s, %s]" record field
340 | lvalue LBRACK exp RBRACK
343 let subscript = $3 in
344 sprintf "get_array_subscript[%s, %s]" array subscript