ps3: task 2
This commit is contained in:
@@ -130,7 +130,23 @@ static void node_print(node_t* node, int nesting)
|
||||
static node_t* convert_operator(node_t* node)
|
||||
{
|
||||
assert(node->type == OPERATOR);
|
||||
// TODO: Task 2: Implement this function
|
||||
switch (node->data.operator) {
|
||||
case "or":
|
||||
node->data.operator = "?:";
|
||||
node_t *new = node_create(NUMBER_LITERAL, 0);
|
||||
new->data.number_literal = 0;
|
||||
append_to_list_node(node, new);
|
||||
break;
|
||||
case "and":
|
||||
node->data.operator = "?:";
|
||||
node_t *new = node_create(NUMBER_LITERAL, 0);
|
||||
new->data.number_literal = 1;
|
||||
append_to_list_node(node, new);
|
||||
node_t *tmp = node->children[1];
|
||||
node->children[1] = node->children[2];
|
||||
node->children[2] = tmp;
|
||||
break;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user