diff options
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 39 |
1 files changed, 36 insertions, 3 deletions
@@ -31,13 +31,43 @@ #include "lexer.h" #include "log.h" #include "parser.h" +#include "parser/ast.h" static const char *src = "void test();\nint main();"; +static void +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_syms(struct hashmap *syms) +{ + struct list *list; + struct ast_node *node; + + /* Iterate hashmap rows */ + for (size_t r = 0; r < syms->row_count; r++) { + /* Iterate row entries */ + list = &syms->rows[r]; + node = (struct ast_node *)list->head; + while (node != (struct ast_node *)list) { + if (node->kind == NOK_FUNCTION) { + print_func(node); + } + + node = (struct ast_node *)node->hashmap_entry.list_entry.next; + } + } +} + int main(int argc, char **argv) { struct lexer lexer; + struct parser parser; + bool success; (void)argc; (void)argv; @@ -47,9 +77,12 @@ main(int argc, char **argv) return EXIT_FAILURE; } - if (!parser_parse(&lexer)) { - return EXIT_FAILURE; + parser.lexer = &lexer; + parser.syms.rows = NULL; + success = parser_parse(&parser); + if (parser.syms.rows != NULL) { + print_syms(&parser.syms); } - return EXIT_SUCCESS; + return success ? EXIT_SUCCESS:EXIT_FAILURE; } |