return res;
}
+struct ast *ast_unop(enum unop op, struct ast *l)
+{
+ struct ast *res = ast_alloc();
+ res->type = an_unop;
+ res->data.an_unop.op = op;
+ res->data.an_unop.l = l;
+ return res;
+}
static const char *binop_str[] = {
+ [binor] = "||",
+ [binand] = "&&",
+ [eq] = "==",
+ [neq] = "!=",
+ [leq] = "<=",
+ [le] = "<",
+ [geq] = ">=",
+ [ge] = ">",
+ [cons] = ":",
[plus] = "+",
- [minus] = "+",
- [times] = "+",
- [divide] = "+",
+ [minus] = "-",
+ [times] = "*",
+ [divide] = "/",
+ [modulo] = "%",
+ [power] = "^",
+};
+static const char *unop_str[] = {
+ [inverse] = "!",
+ [negate] = "-",
};
void ast_print(struct ast * ast, FILE *out)
case an_int:
fprintf(out, "%d", ast->data.an_int);
break;
+ case an_unop:
+ fprintf(out, "(-");
+ ast_print(ast->data.an_unop.l, out);
+ fprintf(out, ")");
+ break;
default:
fprintf(stderr, "Unsupported AST node\n");
exit(1);