diff options
Diffstat (limited to 'src/parser')
-rw-r--r-- | src/parser/parser.c | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/parser/parser.c b/src/parser/parser.c index 4f8543c..ccdc037 100644 --- a/src/parser/parser.c +++ b/src/parser/parser.c @@ -79,6 +79,20 @@ parse_func_decl(struct parser *ctx, struct ast_node *func) } static bool +parse_var_decl(struct parser *ctx, struct ast_node *var) +{ + var->kind = NOK_VARIABLE; + + /* + * TODO: Parse initial value. + */ + + hashmap_add(ctx->syms, &var->hashmap_entry); + parser_advance(ctx); + return true; +} + +static bool parse_decl(struct parser *ctx) { struct type *type; @@ -118,12 +132,11 @@ parse_decl(struct parser *ctx) parser_advance(ctx); if (ctx->tok.kind == TOK_LPAREN) { return parse_func_decl(ctx, node); + } else if (ctx->tok.kind == TOK_SEMICOLON) { + return parse_var_decl(ctx, node); } - /* - * TODO: Parse variable declarations. - */ - tok_error(&ctx->tok, "expected \"(\" after identifier\n"); + tok_error(&ctx->tok, "expected \"(\" or \";\" after identifier\n"); free(node); return false; } |