diff options
| author | Mel <mel@rnrd.eu> | 2025-06-03 01:20:50 +0200 |
|---|---|---|
| committer | Mel <mel@rnrd.eu> | 2025-06-03 01:20:50 +0200 |
| commit | a9b5fef2eb126500974a1cfe9ce4a8f7cc6e0490 (patch) | |
| tree | c375798160976ce9dae1d4f386ee90260706e54e /boot/tree.c | |
| parent | a65c02b752722c873036a9246753f2e40c24305f (diff) | |
| download | catskill-a9b5fef2eb126500974a1cfe9ce4a8f7cc6e0490.tar.zst catskill-a9b5fef2eb126500974a1cfe9ce4a8f7cc6e0490.zip | |
Parse all 4 types of for-loops
Signed-off-by: Mel <mel@rnrd.eu>
Diffstat (limited to 'boot/tree.c')
| -rw-r--r-- | boot/tree.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/boot/tree.c b/boot/tree.c index 64eb23b..3ae90b8 100644 --- a/boot/tree.c +++ b/boot/tree.c @@ -592,6 +592,7 @@ enum Statement_Kind // NOTE: a block could be an expression in the future. STATEMENT_BLOCK, STATEMENT_CONDITIONAL, + STATEMENT_LOOP, }; struct Statement_Value_Expression @@ -624,12 +625,25 @@ struct Statement_Value_Conditional uint condition_count; }; +struct Statement_Value_Loop +{ + // exists for iterator-style + c-style loops. + struct Statement* declaration; + // exists for all loop types, except for infinite loops. + struct Expression* condition; + // exists for c-style loops. + struct Expression* iteration; + + struct Block_Node body; +}; + union Statement_Value { struct Statement_Value_Expression expression; struct Statement_Value_Declaration declaration; struct Statement_Value_Block block; struct Statement_Value_Conditional conditional; + struct Statement_Value_Loop loop; }; struct Statement @@ -731,6 +745,29 @@ statement_print(const struct Statement* statement) printf(")"); break; } + case STATEMENT_LOOP: { + printf("(loop "); + if (statement->value.loop.declaration) { + printf("(declaration "); + statement_print(statement->value.loop.declaration); + printf(") "); + } + + if (statement->value.loop.condition) { + printf("(condition "); + expression_print(statement->value.loop.condition); + printf(") "); + } + + if (statement->value.loop.iteration) { + printf("(iteration "); + expression_print(statement->value.loop.iteration); + printf(") "); + } + + block_node_print(&statement->value.loop.body); + break; + } default: failure("unexpected statement kind passed to `statement_print`"); break; |
