all cases are correct
This commit is contained in:
+5
-3
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user