mirror of
https://github.com/ValKmjolnir/Nasal-Interpreter.git
synced 2026-07-26 21:08:45 +08:00
change code structure
This commit is contained in:
+106
-43
@@ -4,32 +4,63 @@
|
||||
enum ast_node
|
||||
{
|
||||
ast_null=0,
|
||||
ast_root,
|
||||
ast_block,
|
||||
ast_file, // ast_file is only used to store which file the subtree is on,codegen will generate nothing
|
||||
ast_nil,ast_num,ast_str,ast_id,ast_func,ast_hash,ast_vec,
|
||||
ast_hashmember,
|
||||
ast_call,ast_callh,ast_callv,ast_callf,
|
||||
ast_subvec,
|
||||
ast_args,ast_default,ast_dynamic,
|
||||
ast_and,ast_or,
|
||||
ast_equal,
|
||||
ast_addeq,ast_subeq,
|
||||
ast_multeq,ast_diveq,
|
||||
ast_lnkeq,
|
||||
ast_cmpeq,ast_neq,
|
||||
ast_less,ast_leq,
|
||||
ast_grt,ast_geq,
|
||||
ast_add,ast_sub,
|
||||
ast_mult,ast_div,
|
||||
ast_link,
|
||||
ast_neg,ast_not,
|
||||
ast_trino,
|
||||
ast_for,ast_forindex,ast_foreach,ast_while,ast_new_iter,
|
||||
ast_conditional,ast_if,ast_elsif,ast_else,
|
||||
ast_multi_id,ast_multi_scalar,
|
||||
ast_def,ast_multi_assign,
|
||||
ast_continue,ast_break,ast_ret
|
||||
ast_root, // mark the root node of ast
|
||||
ast_block, // expression block
|
||||
ast_file, // used to store which file the sub-tree is on
|
||||
ast_nil, // nil keyword
|
||||
ast_num, // number, basic value type
|
||||
ast_str, // string, basic value type
|
||||
ast_id, // identifier
|
||||
ast_func, // func keyword
|
||||
ast_hash, // hash, basic value type
|
||||
ast_vec, // vector, basic value type
|
||||
ast_hashmember,// elements in hashmap
|
||||
ast_call, // mark a sub-tree of calling an identifier
|
||||
ast_callh, // id.name
|
||||
ast_callv, // id[index]
|
||||
ast_callf, // id()
|
||||
ast_subvec, // id[index:index]
|
||||
ast_args, // mark a sub-tree of function parameters
|
||||
ast_default, // default parameter
|
||||
ast_dynamic, // dynamic parameter
|
||||
ast_and, // and keyword
|
||||
ast_or, // or keyword
|
||||
ast_equal, // =
|
||||
ast_addeq, // +=
|
||||
ast_subeq, // -=
|
||||
ast_multeq, // *=
|
||||
ast_diveq, // /=
|
||||
ast_lnkeq, // ~=
|
||||
ast_cmpeq, // ==
|
||||
ast_neq, // !=
|
||||
ast_less, // <
|
||||
ast_leq, // <=
|
||||
ast_grt, // >
|
||||
ast_geq, // >=
|
||||
ast_add, // +
|
||||
ast_sub, // -
|
||||
ast_mult, // *
|
||||
ast_div, // /
|
||||
ast_link, // ~
|
||||
ast_neg, // -
|
||||
ast_not, // ~
|
||||
ast_trino, // ?:
|
||||
ast_for, // for keyword
|
||||
ast_forindex,// forindex keyword
|
||||
ast_foreach, // foreach keyword
|
||||
ast_while, // while
|
||||
ast_new_iter,// iterator, used in forindex/foreach
|
||||
ast_conditional,// mark a sub-tree of conditional expression
|
||||
ast_if, // if keyword
|
||||
ast_elsif, // elsif keyword
|
||||
ast_else, // else keyword
|
||||
ast_multi_id,// multi identifiers sub-tree
|
||||
ast_multi_scalar,// multi value sub-tree
|
||||
ast_def, // definition
|
||||
ast_multi_assign,// multi assignment sub-tree
|
||||
ast_continue,// continue keyword
|
||||
ast_break, // break keyword
|
||||
ast_ret // return keyword
|
||||
};
|
||||
|
||||
const char* ast_name[]=
|
||||
@@ -38,29 +69,61 @@ const char* ast_name[]=
|
||||
"root",
|
||||
"block",
|
||||
"file",
|
||||
"nil","num","str","id","func","hash","vec",
|
||||
"nil",
|
||||
"num",
|
||||
"str",
|
||||
"id",
|
||||
"func",
|
||||
"hash",
|
||||
"vec",
|
||||
"hashmember",
|
||||
"call","callh","callv","callf",
|
||||
"call",
|
||||
"callh",
|
||||
"callv",
|
||||
"callf",
|
||||
"subvec",
|
||||
"args","default","dynamic",
|
||||
"and","or",
|
||||
"args",
|
||||
"default",
|
||||
"dynamic",
|
||||
"and",
|
||||
"or",
|
||||
"=",
|
||||
"+=","-=",
|
||||
"*=","/=",
|
||||
"+=",
|
||||
"-=",
|
||||
"*=",
|
||||
"/=",
|
||||
"~=",
|
||||
"==","!=",
|
||||
"<","<=",
|
||||
">",">=",
|
||||
"+","-",
|
||||
"*","/",
|
||||
"==",
|
||||
"!=",
|
||||
"<",
|
||||
"<=",
|
||||
">",
|
||||
">=",
|
||||
"+",
|
||||
"-",
|
||||
"*",
|
||||
"/",
|
||||
"~",
|
||||
"unary-","unary!",
|
||||
"unary-",
|
||||
"unary!",
|
||||
"trino",
|
||||
"for","forindex","foreach","while","iter",
|
||||
"conditional","if","elsif","else",
|
||||
"multi_id","multi_scalar",
|
||||
"def","multi_assign",
|
||||
"continue","break","return"
|
||||
"for",
|
||||
"forindex",
|
||||
"foreach",
|
||||
"while",
|
||||
"iter",
|
||||
"conditional",
|
||||
"if",
|
||||
"elsif",
|
||||
"else",
|
||||
"multi_id",
|
||||
"multi_scalar",
|
||||
"def",
|
||||
"multi_assign",
|
||||
"continue",
|
||||
"break",
|
||||
"return",
|
||||
nullptr
|
||||
};
|
||||
|
||||
class nasal_ast
|
||||
|
||||
Reference in New Issue
Block a user