diff options
| author | Mel <mel@rnrd.eu> | 2025-05-31 23:56:35 +0200 |
|---|---|---|
| committer | Mel <mel@rnrd.eu> | 2025-05-31 23:56:35 +0200 |
| commit | ef66c99536a631ff2bd1dab4a825ce16d2efa530 (patch) | |
| tree | d1f2b12d53b3f670b694011f5b6a8077b92762f5 /boot/tree.c | |
| parent | 43b8623ad8323ac73f40908f0fae9f57aa906f39 (diff) | |
| download | catskill-ef66c99536a631ff2bd1dab4a825ce16d2efa530.tar.zst catskill-ef66c99536a631ff2bd1dab4a825ce16d2efa530.zip | |
Parse blocks of statements as node
Signed-off-by: Mel <mel@rnrd.eu>
Diffstat (limited to 'boot/tree.c')
| -rw-r--r-- | boot/tree.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/boot/tree.c b/boot/tree.c index 1d88743..7dd6447 100644 --- a/boot/tree.c +++ b/boot/tree.c @@ -326,6 +326,15 @@ binary_operation_to_string(enum Binary_Operation operation) // nodes are parts of the syntax tree that are reused often // and in different places. +// a block of code, enclosed in curly braces. +// represents a sequence of statements that are executed in order. +struct Block_Node +{ + struct Statement* statements; + struct Span span; + struct Cursor location; +}; + // a type node represents a type in the syntax tree. // currently, we only support types that are simple names. struct Type_Node @@ -538,6 +547,8 @@ enum Statement_Kind STATEMENT_NONE, STATEMENT_EXPRESSION, STATEMENT_DECLARATION, + // NOTE: a block could be an expression in the future. + STATEMENT_BLOCK, }; struct Statement_Value_Expression @@ -554,10 +565,16 @@ struct Statement_Value_Declaration struct Type_Node type; // the type of the variable, if any. }; +struct Statement_Value_Block +{ + struct Block_Node inner; // the block of statements. +}; + union Statement_Value { struct Statement_Value_Expression expression; struct Statement_Value_Declaration declaration; + struct Statement_Value_Block block; }; struct Statement @@ -621,6 +638,16 @@ statement_print(const struct Statement* statement) printf(")"); break; } + case STATEMENT_BLOCK: + printf("(block \n"); + FOR_EACH(struct Statement*, sub_statement, statement->value.block.inner.statements) + { + printf("\t"); + statement_print(sub_statement); + printf("\n"); + } + printf(")"); + break; default: failure("unexpected statement kind passed to `statement_print`"); break; |
