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:
@@ -0,0 +1,60 @@
|
||||
#include "compiler/fzl_token.h"
|
||||
#include <common/fzl_types.h>
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <stddef.h>
|
||||
|
||||
// Analyzer main function
|
||||
fzl_an_res_t analyze_common(fzl_analyzer_t *analyzer, fzl_node_t *node)
|
||||
{
|
||||
fzl_an_res_t res = {.error = false, .type = FZL_TYPE_NULL, .classname = NULL};
|
||||
switch (node->type)
|
||||
{
|
||||
case FZL_NODETYPE_IDENTIFIER:
|
||||
res = analyze_identifier(analyzer, node);
|
||||
break;
|
||||
|
||||
case FZL_NODETYPE_BLOCK:
|
||||
for (size_t i = 0; i < node->list.entry_count; i++)
|
||||
{
|
||||
fzl_an_res_t entry_res =
|
||||
analyze_common(analyzer, node->list.entries[i]);
|
||||
if (entry_res.error)
|
||||
res.error = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case FZL_NODETYPE_CALL:
|
||||
res = analyze_call(analyzer, node);
|
||||
break;
|
||||
|
||||
case FZL_NODETYPE_LITERAL:
|
||||
switch (node->token->type)
|
||||
{
|
||||
case FZL_TOKTYPE_STR_LITERAL:
|
||||
res.type = FZL_TYPE_STRING;
|
||||
break;
|
||||
|
||||
case FZL_TOKTYPE_NUM_LITERAL:
|
||||
res.type = FZL_TYPE_INT;
|
||||
break;
|
||||
|
||||
case FZL_TOKTYPE_BOOL_LITERAL:
|
||||
res.type = FZL_TYPE_BOOL;
|
||||
break;
|
||||
|
||||
case FZL_TOKTYPE_NULL_LITERAL:
|
||||
res.type = FZL_TYPE_OBJECT;
|
||||
res.classname = "null";
|
||||
break;
|
||||
|
||||
default:
|
||||
an_push_error(analyzer, node->token, "unknown literal type");
|
||||
res.error = true;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
Reference in New Issue
Block a user