wip: working on analyzer

- Feat: add `nest_ctx` and `fin_ctx` fns for working with context and
environment
- Feat: add block analyzer
- Feat: add conditional statement analyzer
This commit is contained in:
samsonium
2026-10-26 21:34:54 +03:00
parent 62ae05b4cd
commit a70ad011f3
9 changed files with 165 additions and 35 deletions
+40
View File
@@ -0,0 +1,40 @@
#include <common/fzl_types.h>
#include <compiler/fzl_analyzer.h>
#include <compiler/fzl_parser.h>
#include <compiler/fzl_token.h>
#include <stdio.h>
char cond_problem[256];
// Analyze conditional statement
fzl_an_res_t analyze_conditional(fzl_analyzer_t *analyzer, fzl_node_t *cond)
{
if (!analyzer)
return (fzl_an_res_t){.error = true};
if (!cond || cond->type != FZL_NODETYPE_CONDITIONAL)
{
an_push_error(analyzer, NULL, "provided node is not typeof CONDITIONAL");
return (fzl_an_res_t){.error = true};
}
fzl_an_res_t cond_res = analyze_common(analyzer, cond->cond.condition);
fzl_an_res_t true_res = analyze_common(analyzer, cond->cond.true_block);
fzl_an_res_t else_res = analyze_common(analyzer, cond->cond.else_block);
if (cond_res.error || true_res.error || else_res.error)
return (fzl_an_res_t){.error = true};
if (cond_res.type != FZL_TYPE_BOOL)
an_push_warning(analyzer, cond->cond.condition->token,
"resulting type is not bool");
if (cond->cond.condition->token->type == FZL_TOKTYPE_BOOL_LITERAL)
{
snprintf(cond_problem, sizeof(cond_problem), "condition is always %s",
(char *)cond->cond.condition->token->value);
an_push_warning(analyzer, cond->cond.condition->token, cond_problem);
}
return (fzl_an_res_t){.error = false, .type = FZL_TYPE_NULL};
}