From 0d46dc0f56e2634b283237563b771a9e50cda90a Mon Sep 17 00:00:00 2001 From: Fredrik Robertsen Date: Sun, 1 Mar 2026 14:08:37 +0100 Subject: [PATCH] all cases are correct --- ps3/src/tree.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ps3/src/tree.c b/ps3/src/tree.c index ae3561b..9599fa2 100644 --- a/ps3/src/tree.c +++ b/ps3/src/tree.c @@ -148,7 +148,7 @@ static node_t* convert_operator(node_t* node) node_finalize(node); node = converted_op; } else { - printf("convert_operator: found op `%s`\n", node->data.operator); + /* printf("convert_operator: found op `%s`\n", node->data.operator); */ } return node; } @@ -157,8 +157,10 @@ static node_t* convert_operator(node_t* node) static node_t* constant_fold_operator(node_t* node) { assert(node->type == OPERATOR); + bool cont = 1; for (int i = 0; i < node->n_children; i++) - assert(node->children[i]->type == NUMBER_LITERAL); + cont &= node->children[i]->type == NUMBER_LITERAL; + if (!cont) return node; node_t *a, *b, *c, *result; if (node->n_children == 1) { @@ -296,7 +298,7 @@ static node_t* simplify_subtree(node_t* node) switch (node->type) { case OPERATOR: - return convert_operator(node); + return constant_fold_operator(convert_operator(node)); case PRINTLN_STATEMENT: return simplify_println_statement(node); case BLOCK: