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:
@@ -0,0 +1,38 @@
|
||||
#include <compiler/fzl_analyzer.h>
|
||||
#include <compiler/utils/fzl_symtable.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
// Nest context
|
||||
fzl_an_ctx_t *an_nest_ctx(fzl_analyzer_t *analyzer, fzl_an_ctx_type_t type)
|
||||
{
|
||||
if (!analyzer)
|
||||
return NULL;
|
||||
|
||||
fzl_an_ctx_t *ctx = malloc(sizeof(fzl_an_ctx_t));
|
||||
if (!ctx)
|
||||
return NULL;
|
||||
|
||||
ctx->type = type;
|
||||
if (analyzer->ctx != NULL)
|
||||
ctx->parent = analyzer->ctx;
|
||||
|
||||
analyzer->ctx = ctx;
|
||||
analyzer->symbols[analyzer->symbols_top++] = fzl_mksymt();
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
// Close context and return parent
|
||||
fzl_an_ctx_t *an_fin_ctx(fzl_analyzer_t *analyzer)
|
||||
{
|
||||
if (!analyzer || !analyzer->ctx)
|
||||
return NULL;
|
||||
|
||||
fzl_an_ctx_t *current = analyzer->ctx;
|
||||
fzl_an_ctx_t *parent = current->parent;
|
||||
analyzer->ctx = parent;
|
||||
fzl_freesymt(analyzer->symbols[--analyzer->symbols_top]);
|
||||
|
||||
free(current);
|
||||
return parent;
|
||||
}
|
||||
Reference in New Issue
Block a user