fix: critical fixes for newer compiler versions

- Add token check before parsing statement or program
- Fix program freeing
This commit is contained in:
samsonium
2026-10-19 17:50:31 +03:00
parent 41e8600ce4
commit d09468cc6b
2 changed files with 11 additions and 2 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 4.3)
cmake_minimum_required(VERSION 3.16)
project(fz-lang
LANGUAGES C)
+10 -1
View File
@@ -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;
}
}