- /* Fundec */
- | FUNCTION ID LPAREN RPAREN EQ exp
- {
- let id = $2 in
- let exp = $6 in
- sprintf "fundec[%s, arguments[], exp[%s]]" id exp
- }
- | FUNCTION ID LPAREN tyfields RPAREN EQ exp
- {
- let id = $2 in
- let tyfields = $4 in
- let exp = $7 in
- sprintf "fundec[%s, arguments[%s], exp[%s]]" id tyfields exp
- }
- | FUNCTION ID LPAREN tyfields RPAREN COLON ID EQ exp
- {
- let id = $2 in
- let tyfields = $4 in
- let type_id = $7 in
- let exp = $9 in
- sprintf
- "fundec[%s, tyfields[%s], type_id[%s], exp[%s]]"
- id tyfields type_id exp
+var_dec:
+ | VAR ID maybe_type_sig ASSIGN exp
+ {
+ let var_id = Sym.of_string $2 in
+ let maybe_type_sig = $3 in
+ let exp = $5 in
+ let pos = pos () in
+ Ast.VarDec
+ { name = var_id
+ ; escape = ref true
+ ; typ = maybe_type_sig
+ ; init = exp
+ ; pos
+ }