fix: critical fixes for newer compiler versions
- Add token check before parsing statement or program - Fix program freeing
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 4.3)
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
project(fz-lang
|
||||
LANGUAGES 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user