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:
@@ -1,9 +1,21 @@
|
||||
#ifndef FZL_ANALYZER_H
|
||||
#define FZL_ANALYZER_H
|
||||
|
||||
#include <common/fzl_types.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <compiler/fzl_token.h>
|
||||
#include <compiler/utils/fzl_symtable.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
// Analyzing context type
|
||||
typedef enum
|
||||
{
|
||||
FZL_AN_CTX_TYPE_UNNECESSARY, // default type
|
||||
FZL_AN_CTX_TYPE_FUNCTION, // when analyzing function
|
||||
FZL_AN_CTX_TYPE_LOOP, // when analyzing loop
|
||||
} fzl_an_ctx_type_t;
|
||||
|
||||
// Analyzer descriptor
|
||||
typedef struct
|
||||
{
|
||||
@@ -13,16 +25,49 @@ typedef struct
|
||||
char *errors[256];
|
||||
size_t errors_top;
|
||||
|
||||
fzl_symtable_t *symbols[256];
|
||||
size_t symbols_top;
|
||||
|
||||
fzl_node_t *root;
|
||||
} fzl_analyzer_t;
|
||||
|
||||
// Inner node analyzing result descriptor
|
||||
typedef struct
|
||||
{
|
||||
bool error;
|
||||
|
||||
fzl_type_t type;
|
||||
char *classname;
|
||||
} fzl_an_res_t;
|
||||
|
||||
// Current node context descriptor
|
||||
typedef struct fzl_an_ctx
|
||||
{
|
||||
struct fzl_an_ctx *parent;
|
||||
|
||||
fzl_an_ctx_type_t type;
|
||||
} fzl_an_ctx_t;
|
||||
|
||||
// Temp container for error
|
||||
extern char alast_error[256];
|
||||
|
||||
// Allocate analyzer
|
||||
fzl_analyzer_t *fzl_mkanalyzer(fzl_node_t *node);
|
||||
|
||||
// Push error to errors list
|
||||
bool an_push_error(fzl_analyzer_t *analyzer, fzl_token_t *tok, char *error);
|
||||
|
||||
// Push warning to warnings list
|
||||
bool an_push_warning(fzl_analyzer_t *analyzer, fzl_token_t *tok, char *warning);
|
||||
|
||||
// Analyze AST
|
||||
void fzl_analyze(fzl_analyzer_t *analyzer);
|
||||
|
||||
// Free analyzer
|
||||
void fzl_freeanalyzer(fzl_analyzer_t *analyzer);
|
||||
|
||||
fzl_an_res_t analyze_common(fzl_analyzer_t *analyzer, fzl_node_t *node);
|
||||
fzl_an_res_t analyze_call(fzl_analyzer_t *analyzer, fzl_node_t *call_node);
|
||||
fzl_an_res_t analyze_identifier(fzl_analyzer_t *analyzer, fzl_node_t *id);
|
||||
|
||||
#endif // FZL_ANALYZER_H
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define FZL_SYMTABLE_H
|
||||
|
||||
#include <common/fzl_types.h>
|
||||
#include <compiler/fzl_parser.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
@@ -19,6 +20,7 @@ typedef struct
|
||||
{
|
||||
char *name;
|
||||
fzl_type_t type;
|
||||
fzl_node_t *node;
|
||||
size_t ip;
|
||||
|
||||
char *classname;
|
||||
@@ -37,8 +39,8 @@ typedef struct
|
||||
fzl_symtable_t *fzl_mksymt();
|
||||
|
||||
// Put new entry into symtable
|
||||
fzl_symtable_res_t fzl_symt_put(fzl_symtable_t *symt, char *name,
|
||||
fzl_type_t type, uint64_t ip);
|
||||
fzl_symtable_res_t fzl_symt_put(fzl_symtable_t *symt, fzl_node_t *node,
|
||||
char *name, fzl_type_t type, uint64_t ip);
|
||||
|
||||
// Assign class name to object type
|
||||
fzl_symtable_res_t fzl_symt_setobjclass(fzl_symtable_t *symt, char *name,
|
||||
|
||||
Reference in New Issue
Block a user