summaryrefslogtreecommitdiff
path: root/src/parser/parser.c
diff options
context:
space:
mode:
authorQuinn Stephens <quinn@osmora.org>2025-06-09 22:02:58 -0400
committerQuinn Stephens <quinn@osmora.org>2025-06-09 22:02:58 -0400
commit13923af3ab57dbd826ce6f36b38228eea595590f (patch)
tree200afacf2c9c6bc8612c8bf5b4037c1bc4f11adf /src/parser/parser.c
parentc7c2e0dc65b0ea01d297de21983acbd1019df025 (diff)
parser: Parse uninitialized variable declarations
Signed-off-by: Quinn Stephens <quinn@osmora.org>
Diffstat (limited to 'src/parser/parser.c')
-rw-r--r--src/parser/parser.c21
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;
}