wip: working on analyzer

- Feat: now symbols table store node on PUT
- Feat: call analyzer with callee resolving and arguments validate
- Feat: identifier analyzer
- Feat: analyzer utils (types compat, tok-to-type, type-to-string)
This commit is contained in:
samsonium
2026-10-26 20:47:24 +03:00
parent 4904f40037
commit 62ae05b4cd
11 changed files with 474 additions and 15 deletions
+48 -9
View File
@@ -1,9 +1,14 @@
#include <compiler/fzl_analyzer.h>
#include <compiler/fzl_parser.h>
#include <compiler/fzl_token.h>
#include <compiler/utils/fzl_symtable.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char alast_err[256];
fzl_analyzer_t *fzl_mkanalyzer(fzl_node_t *node)
{
if (!node)
@@ -16,30 +21,44 @@ fzl_analyzer_t *fzl_mkanalyzer(fzl_node_t *node)
analyzer->root = node;
analyzer->warnings_top = 0;
analyzer->errors_top = 0;
analyzer->symbols_top = 0;
memset(analyzer->errors, 0, sizeof(analyzer->errors));
memset(analyzer->warnings, 0, sizeof(analyzer->warnings));
memset(analyzer->symbols, 0, sizeof(analyzer->symbols));
return analyzer;
}
// Push error to errors list
bool push_error(fzl_analyzer_t *analyzer, char *error)
bool an_push_error(fzl_analyzer_t *analyzer, fzl_token_t *tok, char *error)
{
if (analyzer->errors_top >= 256)
if (analyzer->errors_top >= 256 || !analyzer || !error)
return false;
analyzer->errors[analyzer->errors_top++] = error;
if (tok != NULL)
snprintf(alast_error, sizeof(alast_error), "%s:%zu:%zu => %s",
tok->filename, tok->ln, tok->cn, error);
else
snprintf(alast_error, sizeof(alast_error), "<unknown location> => %s",
error);
analyzer->errors[analyzer->errors_top++] = alast_error;
return true;
}
// Push warning to warnings list
bool push_warning(fzl_analyzer_t *analyzer, char *error)
bool an_push_warning(fzl_analyzer_t *analyzer, fzl_token_t *tok, char *warning)
{
if (analyzer->warnings_top >= 256)
if (analyzer->warnings_top >= 256 || !analyzer || !warning)
return false;
analyzer->warnings[analyzer->warnings_top++] = error;
if (tok != NULL)
snprintf(alast_error, sizeof(alast_error), "%s:%zu:%zu => %s",
tok->filename, tok->ln, tok->cn, warning);
else
snprintf(alast_error, sizeof(alast_error), "<unknown location> => %s",
warning);
analyzer->warnings[analyzer->warnings_top++] = alast_error;
return true;
}
@@ -48,7 +67,26 @@ void fzl_analyze(fzl_analyzer_t *analyzer)
if (!analyzer)
return;
//
analyzer->symbols[analyzer->symbols_top++] = fzl_mksymt();
fzl_node_t *current = analyzer->root;
while (current != NULL)
{
fzl_an_res_t res = analyze_common(analyzer, current);
if (res.error)
break;
current = current->next;
}
if (analyzer->symbols_top < 0)
{
an_push_error(analyzer, NULL,
"undefined error (early finish of global environment)");
return;
}
fzl_freesymt(analyzer->symbols[--analyzer->symbols_top]);
}
void fzl_freeanalyzer(fzl_analyzer_t *analyzer)
@@ -58,5 +96,6 @@ void fzl_freeanalyzer(fzl_analyzer_t *analyzer)
memset(analyzer->errors, 0, sizeof(analyzer->errors));
memset(analyzer->warnings, 0, sizeof(analyzer->warnings));
memset(analyzer->symbols, 0, sizeof(analyzer->symbols));
free(analyzer);
}