diff options
author | Bad Diode <bd@badd10de.dev> | 2022-04-06 08:02:52 -0300 |
---|---|---|
committer | Bad Diode <bd@badd10de.dev> | 2022-04-06 08:02:52 -0300 |
commit | 11df0f4556f526189234be216fa16a2fcb8c308b (patch) | |
tree | d9459ebf0b99ef1ecadf4101da147d60935e916f /src/nodes.c | |
parent | 77b309ba82d090094f5f753342c3aa401cbf657d (diff) | |
download | bdl-11df0f4556f526189234be216fa16a2fcb8c308b.tar.gz bdl-11df0f4556f526189234be216fa16a2fcb8c308b.zip |
Add parsing of if statements
Diffstat (limited to 'src/nodes.c')
-rw-r--r-- | src/nodes.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/nodes.c b/src/nodes.c index 3a63246..af3b772 100644 --- a/src/nodes.c +++ b/src/nodes.c | |||
@@ -11,6 +11,9 @@ alloc_node(NodeType type) { | |||
11 | 11 | ||
12 | void | 12 | void |
13 | print_node(Node *node) { | 13 | print_node(Node *node) { |
14 | if (node == NULL) { | ||
15 | return; | ||
16 | } | ||
14 | switch (node->type) { | 17 | switch (node->type) { |
15 | case NODE_NUMBER: { | 18 | case NODE_NUMBER: { |
16 | if (node->number.negative) { | 19 | if (node->number.negative) { |
@@ -73,6 +76,17 @@ print_node(Node *node) { | |||
73 | } | 76 | } |
74 | printf(" }"); | 77 | printf(" }"); |
75 | } break; | 78 | } break; |
79 | case NODE_IF: { | ||
80 | printf("(if "); | ||
81 | print_node(node->ifexpr.cond); | ||
82 | printf(" "); | ||
83 | print_node(node->ifexpr.expr_true); | ||
84 | if (node->ifexpr.expr_false != NULL) { | ||
85 | printf(" "); | ||
86 | print_node(node->ifexpr.expr_false); | ||
87 | } | ||
88 | printf(")"); | ||
89 | } break; | ||
76 | case NODE_FUN: { | 90 | case NODE_FUN: { |
77 | printf("(fun "); | 91 | printf("(fun "); |
78 | print_node(node->fun.name); | 92 | print_node(node->fun.name); |