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 449f4e6..dff0858 100644 --- a/boot/tree.c +++ b/boot/tree.c @@ -912,8 +912,30 @@ struct Statement_Value_Expression struct Expression* inner; }; +enum Statement_Declaration_Kind +{ + STATEMENT_DECLARATION_NONE, + STATEMENT_DECLARATION_VARIABLE, + STATEMENT_DECLARATION_CONSTANT, +}; + +enum Statement_Declaration_Kind +statement_declaration_kind_from_token(const struct Token* token) +{ + switch (token->kind) { + case TOKEN_WORD_VAR: + return STATEMENT_DECLARATION_VARIABLE; + case TOKEN_WORD_LET: + return STATEMENT_DECLARATION_CONSTANT; + + default: + return STATEMENT_DECLARATION_NONE; + } +} + struct Statement_Value_Declaration { + enum Statement_Declaration_Kind kind; struct String_Array names; struct Expression* initializer; struct Type_Node* type; @@ -1042,6 +1064,11 @@ statement_print(const struct Statement* statement) } case STATEMENT_DECLARATION: { printf("(declaration "); + if (statement->value.declaration.kind == STATEMENT_DECLARATION_VARIABLE) + printf("variable "); + else if (statement->value.declaration.kind == STATEMENT_DECLARATION_CONSTANT) + printf("constant "); + STRING_ARRAY_FOR_EACH(i, name, statement->value.declaration.names) { printf("%s ", name.data); |
