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
118 sprintf "op[%s %s %s]" $1 $2 $3
120 | IF exp THEN exp ELSE exp
125 sprintf "if_then_else[%s, then[%s], else[%s]]" e1 e2 e3
129 sprintf "if_then[%s, then[%s]]" $2 $4
133 sprintf "while[%s, do[%s]]" $2 $4
135 | FOR ID ASSIGN exp TO exp DO exp
141 sprintf "for[%s := %s, to[%s], do[%s]]" id e1 e2 e3
151 | LET decs IN seq END
155 sprintf "let[decs[%s], in[seq[%s]]]" decs seq
169 sprintf "%s; %s" $1 $3
179 sprintf "%s %s" $1 $2
188 | FUNCTION ID unit EQ exp
192 sprintf "fundec[%s, exp[%s]]" id exp
194 | FUNCTION ID LPAREN tyfields RPAREN EQ exp
199 sprintf "fundec[%s, tyfields[%s], exp[%s]]" id tyfields exp
201 | FUNCTION ID LPAREN tyfields RPAREN COLON ID EQ exp
208 "fundec[%s, tyfields[%s], type_id[%s], exp[%s]]"
209 id tyfields type_id exp
217 sprintf "vardec[%s, exp[%s]]" id exp
219 | VAR ID COLON ID ASSIGN exp
224 sprintf "vardec[%s, type_id[%s], exp[%s]]" id type_id exp
232 sprintf "tydec[%s, %s]" type_id ty
239 sprintf "type[type_id[%S]]" type_id
245 | LBRACE tyfields RBRACE
248 sprintf "record[%s]" tyfields
253 sprintf "array_of_type[%s]" type_id
260 | tyfield COMMA tyfields
264 sprintf "%s, %s" tyfield tyfields
272 sprintf "tyfield[%s, %s]" id type_id
275 /* Perhaps "void"? */
282 rec_field_assignments:
287 sprintf "%S = %s" id exp
289 | ID EQ exp COMMA rec_field_assignments
293 let rec_field_assignments = $5 in
294 sprintf "%S = %s, %s" id exp rec_field_assignments
301 sprintf "fun_call[%s, []]" id
303 | ID LPAREN fun_args RPAREN
307 sprintf "fun_call[%s, %s]" id fun_args
317 sprintf "%s, %s" $1 $3
338 sprintf "lvalue[%s]" id
344 sprintf "get_record_field[%s, %s]" record field
346 | lvalue LBRACK exp RBRACK
349 let subscript = $3 in
350 sprintf "get_array_subscript[%s, %s]" array subscript