diff --git a/CMakeLists.txt b/CMakeLists.txt index f25345b..db0aab3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 4.3) +cmake_minimum_required(VERSION 3.16) project(fz-lang LANGUAGES C) diff --git a/src/compiler/fzl_parser.c b/src/compiler/fzl_parser.c index 5e403c0..b7c9b9f 100644 --- a/src/compiler/fzl_parser.c +++ b/src/compiler/fzl_parser.c @@ -959,6 +959,9 @@ fzl_node_t *parse_block(fzl_parser_t *parser) // Statement parsing fzl_node_t *parse_statement(fzl_parser_t *parser) { + if (!peek(parser)) + return NULL; + fzl_node_t *res = NULL; if (is(parser, FZL_TOKTYPE_CLASS)) @@ -990,6 +993,9 @@ fzl_node_t *parse_statement(fzl_parser_t *parser) // Internal parsing entry point fzl_node_t *parse_program(fzl_parser_t *parser) { + if (!peek(parser)) + return NULL; + fzl_node_t *first = NULL; fzl_node_t *last = NULL; fzl_node_t *node = NULL; @@ -1023,6 +1029,8 @@ fzl_node_t *parse_program(fzl_parser_t *parser) // Parse tokens and build AST int fzl_parse(fzl_parser_t *parser) { + last_known_tok = NULL; + fzl_node_t *ast = parse_program(parser); if (!ast) return -1; @@ -1121,8 +1129,9 @@ void fzl_freeast(fzl_node_t *root) fzl_freenode(root->memb.parent); } - root = root->next; + fzl_node_t *next = root->next; free(root); + root = root->next; } }