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
156 sprintf "exps[%s]" $2
158 | LET decs IN exps END
162 sprintf "let[decs[%s], in[exps[%s]]]" decs exps
166 (* Perhaps "void"? *)
177 sprintf "%s; %s" $1 $3
187 sprintf "%s %s" $1 $2
194 let type_id_new = $2 in
195 let type_id_orig = $4 in
196 sprintf "tydec_alias[from[%s], to[%s]]" type_id_new type_id_orig
198 | TYPE ID EQ LBRACE RBRACE
201 sprintf "tydec_empty_record[%s]" type_id
203 | TYPE ID EQ LBRACE tyfields RBRACE
207 sprintf "tydec_record[%s, fields[%s]]" type_id tyfields
209 | TYPE ID EQ ARRAY OF ID
212 let element_type_id = $6 in
213 sprintf "tydec_array[%s, elements_of_type[%s]]" type_id element_type_id
221 sprintf "vardec[%s, exp[%s]]" id exp
223 | VAR ID COLON ID ASSIGN exp
228 sprintf "vardec[%s, type_id[%s], exp[%s]]" id type_id exp
232 | FUNCTION ID LPAREN RPAREN EQ exp
236 sprintf "fundec[%s, arguments[], exp[%s]]" id exp
238 | FUNCTION ID LPAREN tyfields RPAREN EQ exp
243 sprintf "fundec[%s, arguments[%s], exp[%s]]" id tyfields exp
245 | FUNCTION ID LPAREN tyfields RPAREN COLON ID EQ exp
252 "fundec[%s, tyfields[%s], type_id[%s], exp[%s]]"
253 id tyfields type_id exp
260 | tyfield COMMA tyfields
264 sprintf "%s, %s" tyfield tyfields
272 sprintf "tyfield[%s, %s]" id type_id
275 rec_field_assignments:
280 sprintf "%S = %s" id exp
282 | ID EQ exp COMMA rec_field_assignments
286 let rec_field_assignments = $5 in
287 sprintf "%S = %s, %s" id exp rec_field_assignments
297 sprintf "%s, %s" $1 $3
318 sprintf "lvalue[%s]" id
324 sprintf "get_record_field[%s, %s]" record field
326 | lvalue LBRACK exp RBRACK
329 let subscript = $3 in
330 sprintf "get_array_subscript[%s, %s]" array subscript