[an_fundecl] = "fundecl", [an_ident] = "ident", [an_if] = "if",
[an_int] = "int", [an_nil] = "nil", [an_list] = "list",
[an_return] = "return", [an_stmt_expr] = "stmt_expr",
- [an_unop] = "unop", [an_vardecl] = "vardecl", [an_while] = "while",
+ [an_tuple] = "tuple", [an_unop] = "unop", [an_vardecl] = "vardecl",
+ [an_while] = "while",
};
#endif
static const char *binop_str[] = {
return res;
}
+struct ast *ast_tuple(struct ast *left, struct ast *right)
+{
+ struct ast *res = ast_alloc();
+ res->type = an_tuple;
+ res->data.an_tuple.left = left;
+ res->data.an_tuple.right = right;
+ return res;
+}
+
+
struct ast *ast_unop(enum unop op, struct ast *l)
{
struct ast *res = ast_alloc();
ast_print(ast->data.an_stmt_expr, indent, out);
safe_fprintf(out, ";\n");
break;
+ case an_tuple:
+ safe_fprintf(out, "(");
+ ast_print(ast->data.an_tuple.left, indent, out);
+ safe_fprintf(out, ", ");
+ ast_print(ast->data.an_tuple.right, indent, out);
+ safe_fprintf(out, ")");
+ break;
case an_unop:
safe_fprintf(out, "(%s", unop_str[ast->data.an_unop.op]);
ast_print(ast->data.an_unop.l, indent, out);
case an_stmt_expr:
ast_free(ast->data.an_stmt_expr);
break;
+ case an_tuple:
+ ast_free(ast->data.an_tuple.left);
+ ast_free(ast->data.an_tuple.right);
+ break;
case an_unop:
ast_free(ast->data.an_unop.l);
break;