diff options
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; |
