From 13923af3ab57dbd826ce6f36b38228eea595590f Mon Sep 17 00:00:00 2001 From: Quinn Stephens Date: Mon, 9 Jun 2025 22:02:58 -0400 Subject: parser: Parse uninitialized variable declarations Signed-off-by: Quinn Stephens --- src/main.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 645656c..c06d83e 100644 --- a/src/main.c +++ b/src/main.c @@ -33,7 +33,7 @@ #include "parser.h" #include "parser/ast.h" -static const char *src = "void test();\nint main();"; +static const char *src = "int x;\nvoid test();\nint main();\n"; static void print_func(struct ast_node *func) @@ -41,6 +41,12 @@ print_func(struct ast_node *func) log_debug("found function \"%.*s\" (return type %s)\n", func->name_len, func->name, func->type->name); } +static void +print_var(struct ast_node *var) +{ + log_debug("found variable \"%.*s\" (type %s)\n", var->name_len, var->name, var->type->name); +} + static void print_syms(struct hashmap *syms) { @@ -55,6 +61,8 @@ print_syms(struct hashmap *syms) while (node != (struct ast_node *)list) { if (node->kind == NOK_FUNCTION) { print_func(node); + } else if (node->kind == NOK_VARIABLE) { + print_var(node); } node = (struct ast_node *)node->hashmap_entry.list_entry.next; -- cgit v1.2.3