43 %token <string> STRING
51 /* from lowest precedence */
55 %nonassoc EQ NEQ GT LT GE LE
59 /* to highest precedence */
61 %type <string> program
70 sprintf "program[%s]" $1
83 | MINUS exp %prec UMINUS
85 sprintf "negation[%s]" $2
87 | ID LBRACK exp RBRACK OF exp
90 let number_of_elements = $3 in
91 let initial_value = $6 in
93 "array[type[%s], size[%s], val[%s]]"
94 type_id number_of_elements initial_value
96 | ID LBRACE rec_field_assignments RBRACE
99 let rec_field_assignments = $3 in
101 "record[type[%s], rec_field_assignments[%s]]"
102 type_id rec_field_assignments
110 sprintf "assign[%s := %s]" $1 $3
114 sprintf "string[%S]" $1
119 sprintf "fun_call[%s, []]" id
121 | ID LPAREN fun_args RPAREN
125 sprintf "fun_call[%s, %s]" id fun_args
129 sprintf "op[%s %s %s]" $1 $2 $3
131 | IF exp THEN exp ELSE exp
136 sprintf "if_then_else[%s, then[%s], else[%s]]" e1 e2 e3
140 sprintf "if_then[%s, then[%s]]" $2 $4
144 sprintf "while[%s, do[%s]]" $2 $4
146 | FOR ID ASSIGN exp TO exp DO exp
152 sprintf "for[%s := %s, to[%s], do[%s]]" id e1 e2 e3
160 sprintf "exps[%s]" $2
162 | LET decs IN exps END
166 sprintf "let[decs[%s], in[exps[%s]]]" decs exps
170 (* Perhaps "void"? *)
175 rec_field_assignments:
180 sprintf "%S = %s" id exp
182 | ID EQ exp COMMA rec_field_assignments
186 let rec_field_assignments = $5 in
187 sprintf "%S = %s, %s" id exp rec_field_assignments
201 sprintf "%s; %s" exp exps
212 sprintf "%s %s" $1 $2
220 let type_id_new = $2 in
221 let type_id_orig = $4 in
222 sprintf "tydec_alias[from[%s], to[%s]]" type_id_new type_id_orig
224 | TYPE ID EQ LBRACE RBRACE
227 sprintf "tydec_empty_record[%s]" type_id
229 | TYPE ID EQ LBRACE tyfields RBRACE
233 sprintf "tydec_record[%s, fields[%s]]" type_id tyfields
235 | TYPE ID EQ ARRAY OF ID
238 let element_type_id = $6 in
239 sprintf "tydec_array[%s, elements_of_type[%s]]" type_id element_type_id
247 sprintf "vardec[%s, exp[%s]]" id exp
249 | VAR ID COLON ID ASSIGN exp
254 sprintf "vardec[%s, type_id[%s], exp[%s]]" id type_id exp
258 | FUNCTION ID LPAREN RPAREN EQ exp
262 sprintf "fundec[%s, arguments[], exp[%s]]" id exp
264 | FUNCTION ID LPAREN tyfields RPAREN EQ exp
269 sprintf "fundec[%s, arguments[%s], exp[%s]]" id tyfields exp
271 | FUNCTION ID LPAREN tyfields RPAREN COLON ID EQ exp
278 "fundec[%s, tyfields[%s], type_id[%s], exp[%s]]"
279 id tyfields type_id exp
288 sprintf "%s : %s" id_1 id_2
290 | ID COLON ID COMMA tyfields
294 let tyfield = sprintf "%s : %s" id_1 id_2 in
296 sprintf "%s, %s" tyfield tyfields
307 sprintf "%s, %s" $1 $3
331 sprintf "lvalue[%s, part[%s]]" id part
337 | lvalue_subscript {$1}
338 | lvalue_field_access {$1}
345 sprintf "subscript[%s]" exp
353 sprintf "field_access[%s]" field