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
+40
View File
@@ -0,0 +1,40 @@
#include <compiler/fzl_analyzer.h>
#include <compiler/fzl_parser.h>
#include <compiler/utils/fzl_symtable.h>
#include <stdio.h>
char id_problem[256];
// Analyze identifier
fzl_an_res_t analyze_identifier(fzl_analyzer_t *analyzer, fzl_node_t *id)
{
if (!analyzer)
return (fzl_an_res_t){.error = true};
if (!id || id->type != FZL_NODETYPE_IDENTIFIER)
{
snprintf(id_problem, sizeof(id_problem), "cannot parse identifier");
an_push_error(analyzer, NULL, id_problem);
return (fzl_an_res_t){.error = true};
}
char *symname = id->token->value;
fzl_sym_t sym;
bool sym_found = false;
for (ssize_t i = analyzer->symbols_top - 1; i >= 0; i--)
{
if ((sym_found = fzl_symt_get(analyzer->symbols[i], symname, &sym)))
break;
}
if (!sym_found)
{
snprintf(id_problem, sizeof(id_problem), "cannot find symbol '%s'",
symname);
an_push_error(analyzer, id->token, id_problem);
return (fzl_an_res_t){.error = true};
}
return (fzl_an_res_t){
.error = false, .type = sym.type, .classname = sym.classname};
}