identifiers' name changed

This commit is contained in:
Valk Richard Li 2021-02-12 23:48:51 +08:00
parent b5514fd269
commit 7329c70492
5 changed files with 273 additions and 272 deletions

View File

@ -4,14 +4,14 @@
enum ast_node enum ast_node
{ {
ast_null=0,ast_root,ast_block, ast_null=0,ast_root,ast_block,
ast_nil,ast_number,ast_string,ast_identifier,ast_function,ast_hash,ast_vector, ast_nil,ast_num,ast_str,ast_id,ast_func,ast_hash,ast_vec,
ast_hashmember,ast_call,ast_call_hash,ast_call_vec,ast_call_func,ast_subvec, ast_hashmember,ast_call,ast_call_hash,ast_call_vec,ast_call_func,ast_subvec,
ast_args,ast_default_arg,ast_dynamic_id, ast_args,ast_default_arg,ast_dynamic_id,
ast_and,ast_or, ast_and,ast_or,
ast_equal,ast_add_equal,ast_sub_equal,ast_mult_equal,ast_div_equal,ast_link_equal, ast_equal,ast_add_equal,ast_sub_equal,ast_mult_equal,ast_div_equal,ast_link_equal,
ast_cmp_equal,ast_cmp_not_equal, ast_cmp_equal,ast_cmp_not_equal,
ast_less_than,ast_less_equal, ast_less,ast_leq,
ast_greater_than,ast_greater_equal, ast_grt,ast_geq,
ast_add,ast_sub,ast_mult,ast_div,ast_link, ast_add,ast_sub,ast_mult,ast_div,ast_link,
ast_unary_sub,ast_unary_not, ast_unary_sub,ast_unary_not,
ast_trinocular, ast_trinocular,
@ -22,7 +22,7 @@ enum ast_node
ast_continue,ast_break,ast_return ast_continue,ast_break,ast_return
}; };
std::string ast_str(int type) std::string ast_name(int type)
{ {
switch(type) switch(type)
{ {
@ -30,12 +30,12 @@ std::string ast_str(int type)
case ast_root: return "root"; case ast_root: return "root";
case ast_block: return "block"; case ast_block: return "block";
case ast_nil: return "nil"; case ast_nil: return "nil";
case ast_number: return "number"; case ast_num: return "number";
case ast_string: return "string"; case ast_str: return "string";
case ast_identifier: return "id"; case ast_id: return "id";
case ast_function: return "function"; case ast_func: return "function";
case ast_hash: return "hash"; case ast_hash: return "hash";
case ast_vector: return "vector"; case ast_vec: return "vector";
case ast_hashmember: return "hashmember"; case ast_hashmember: return "hashmember";
case ast_call: return "call"; case ast_call: return "call";
case ast_call_hash: return "callh"; case ast_call_hash: return "callh";
@ -55,10 +55,10 @@ std::string ast_str(int type)
case ast_link_equal: return "~="; case ast_link_equal: return "~=";
case ast_cmp_equal: return "=="; case ast_cmp_equal: return "==";
case ast_cmp_not_equal:return "!="; case ast_cmp_not_equal:return "!=";
case ast_less_than: return "<"; case ast_less: return "<";
case ast_less_equal: return "<="; case ast_leq: return "<=";
case ast_greater_than: return ">"; case ast_grt: return ">";
case ast_greater_equal:return ">="; case ast_geq: return ">=";
case ast_add: return "+"; case ast_add: return "+";
case ast_sub: return "-"; case ast_sub: return "-";
case ast_mult: return "*"; case ast_mult: return "*";
@ -216,11 +216,11 @@ void nasal_ast::print_ast(int depth)
{ {
std::string indentation=""; std::string indentation="";
for(int i=0;i<depth;++i) indentation+="| "; for(int i=0;i<depth;++i) indentation+="| ";
indentation+=ast_str(this->type); indentation+=ast_name(this->type);
std::cout<<indentation; std::cout<<indentation;
if(this->type==ast_string || this->type==ast_identifier || this->type==ast_dynamic_id || this->type==ast_call_hash) if(this->type==ast_str || this->type==ast_id || this->type==ast_dynamic_id || this->type==ast_call_hash)
std::cout<<":"<<this->str; std::cout<<":"<<this->str;
else if(this->type==ast_number) else if(this->type==ast_num)
std::cout<<":"<<this->num; std::cout<<":"<<this->num;
std::cout<<'\n'; std::cout<<'\n';
int child_size=this->children.size(); int child_size=this->children.size();

View File

@ -278,7 +278,7 @@ void nasal_codegen::function_gen(nasal_ast& ast)
for(int i=0;i<arg_size;++i) for(int i=0;i<arg_size;++i)
{ {
nasal_ast& tmp=ref_arg.get_children()[i]; nasal_ast& tmp=ref_arg.get_children()[i];
if(tmp.get_type()==ast_identifier) if(tmp.get_type()==ast_id)
{ {
std::string str=tmp.get_str(); std::string str=tmp.get_str();
regist_string(str); regist_string(str);
@ -396,7 +396,7 @@ void nasal_codegen::call_func(nasal_ast& ast)
void nasal_codegen::mem_call(nasal_ast& ast) void nasal_codegen::mem_call(nasal_ast& ast)
{ {
if(ast.get_type()==ast_identifier) if(ast.get_type()==ast_id)
mem_call_id(ast); mem_call_id(ast);
else else
mem_call_id(ast.get_children()[0]); mem_call_id(ast.get_children()[0]);
@ -473,7 +473,7 @@ void nasal_codegen::multi_def(nasal_ast& ast)
void nasal_codegen::definition_gen(nasal_ast& ast) void nasal_codegen::definition_gen(nasal_ast& ast)
{ {
if(ast.get_children()[0].get_type()==ast_identifier) if(ast.get_children()[0].get_type()==ast_id)
single_def(ast); single_def(ast);
else else
multi_def(ast); multi_def(ast);
@ -585,13 +585,13 @@ void nasal_codegen::for_gen(nasal_ast& ast)
case ast_null:break; case ast_null:break;
case ast_definition:definition_gen(ast.get_children()[0]);break; case ast_definition:definition_gen(ast.get_children()[0]);break;
case ast_multi_assign:multi_assignment_gen(ast.get_children()[0]);break; case ast_multi_assign:multi_assignment_gen(ast.get_children()[0]);break;
case ast_nil:case ast_number:case ast_string:case ast_function:break; case ast_nil:case ast_num:case ast_str:case ast_func:break;
case ast_vector:case ast_hash: case ast_vec:case ast_hash:
case ast_call: case ast_call:
case ast_equal:case ast_add_equal:case ast_sub_equal:case ast_mult_equal:case ast_div_equal:case ast_link_equal: case ast_equal:case ast_add_equal:case ast_sub_equal:case ast_mult_equal:case ast_div_equal:case ast_link_equal:
case ast_unary_sub:case ast_unary_not: case ast_unary_sub:case ast_unary_not:
case ast_add:case ast_sub:case ast_mult:case ast_div:case ast_link: case ast_add:case ast_sub:case ast_mult:case ast_div:case ast_link:
case ast_cmp_equal:case ast_cmp_not_equal:case ast_less_equal:case ast_less_than:case ast_greater_equal:case ast_greater_than: case ast_cmp_equal:case ast_cmp_not_equal:case ast_leq:case ast_less:case ast_geq:case ast_grt:
case ast_trinocular:calculation_gen(ast.get_children()[0]);pop_gen();break; case ast_trinocular:calculation_gen(ast.get_children()[0]);pop_gen();break;
} }
int jmp_place=exec_code.size(); int jmp_place=exec_code.size();
@ -609,13 +609,13 @@ void nasal_codegen::for_gen(nasal_ast& ast)
case ast_null:break; case ast_null:break;
case ast_definition:definition_gen(ast.get_children()[2]);break; case ast_definition:definition_gen(ast.get_children()[2]);break;
case ast_multi_assign:multi_assignment_gen(ast.get_children()[2]);break; case ast_multi_assign:multi_assignment_gen(ast.get_children()[2]);break;
case ast_nil:case ast_number:case ast_string:case ast_function:break; case ast_nil:case ast_num:case ast_str:case ast_func:break;
case ast_vector:case ast_hash: case ast_vec:case ast_hash:
case ast_call: case ast_call:
case ast_equal:case ast_add_equal:case ast_sub_equal:case ast_mult_equal:case ast_div_equal:case ast_link_equal: case ast_equal:case ast_add_equal:case ast_sub_equal:case ast_mult_equal:case ast_div_equal:case ast_link_equal:
case ast_unary_sub:case ast_unary_not: case ast_unary_sub:case ast_unary_not:
case ast_add:case ast_sub:case ast_mult:case ast_div:case ast_link: case ast_add:case ast_sub:case ast_mult:case ast_div:case ast_link:
case ast_cmp_equal:case ast_cmp_not_equal:case ast_less_equal:case ast_less_than:case ast_greater_equal:case ast_greater_than: case ast_cmp_equal:case ast_cmp_not_equal:case ast_leq:case ast_less:case ast_geq:case ast_grt:
case ast_trinocular:calculation_gen(ast.get_children()[2]);pop_gen();break; case ast_trinocular:calculation_gen(ast.get_children()[2]);pop_gen();break;
} }
gen(op_jmp,jmp_place); gen(op_jmp,jmp_place);
@ -735,12 +735,12 @@ void nasal_codegen::calculation_gen(nasal_ast& ast)
switch(ast.get_type()) switch(ast.get_type())
{ {
case ast_nil: nil_gen(); break; case ast_nil: nil_gen(); break;
case ast_number: number_gen(ast); break; case ast_num: number_gen(ast); break;
case ast_string: string_gen(ast); break; case ast_str: string_gen(ast); break;
case ast_identifier: call_id(ast); break; case ast_id: call_id(ast); break;
case ast_vector: vector_gen(ast); break; case ast_vec: vector_gen(ast); break;
case ast_hash: hash_gen(ast); break; case ast_hash: hash_gen(ast); break;
case ast_function: function_gen(ast); break; case ast_func: function_gen(ast); break;
case ast_call: call_gen(ast); break; case ast_call: call_gen(ast); break;
case ast_equal: case ast_equal:
calculation_gen(ast.get_children()[1]); calculation_gen(ast.get_children()[1]);
@ -761,8 +761,8 @@ void nasal_codegen::calculation_gen(nasal_ast& ast)
calculation_gen(ast.get_children()[1]); calculation_gen(ast.get_children()[1]);
gen(ast.get_type()-ast_add+op_add,0); gen(ast.get_type()-ast_add+op_add,0);
break; break;
// ast_cmp_equal(27)~ast_greater_equal(32) op_eq(29)~op_geq(34) // ast_cmp_equal(27)~ast_geq(32) op_eq(29)~op_geq(34)
case ast_cmp_equal:case ast_cmp_not_equal:case ast_less_than:case ast_less_equal:case ast_greater_than:case ast_greater_equal: case ast_cmp_equal:case ast_cmp_not_equal:case ast_less:case ast_leq:case ast_grt:case ast_geq:
calculation_gen(ast.get_children()[0]); calculation_gen(ast.get_children()[0]);
calculation_gen(ast.get_children()[1]); calculation_gen(ast.get_children()[1]);
gen(ast.get_type()-ast_cmp_equal+op_eq,0); gen(ast.get_type()-ast_cmp_equal+op_eq,0);
@ -788,7 +788,7 @@ void nasal_codegen::block_gen(nasal_ast& ast)
nasal_ast& tmp=ast.get_children()[i]; nasal_ast& tmp=ast.get_children()[i];
switch(tmp.get_type()) switch(tmp.get_type())
{ {
case ast_null:case ast_nil:case ast_number:case ast_string:case ast_function:break; case ast_null:case ast_nil:case ast_num:case ast_str:case ast_func:break;
case ast_definition:definition_gen(tmp);break; case ast_definition:definition_gen(tmp);break;
case ast_multi_assign:multi_assignment_gen(tmp);break; case ast_multi_assign:multi_assignment_gen(tmp);break;
case ast_conditional:conditional_gen(tmp);break; case ast_conditional:conditional_gen(tmp);break;
@ -804,8 +804,8 @@ void nasal_codegen::block_gen(nasal_ast& ast)
case ast_for: case ast_for:
case ast_forindex: case ast_forindex:
case ast_foreach:loop_gen(tmp);break; case ast_foreach:loop_gen(tmp);break;
case ast_identifier: case ast_id:
case ast_vector: case ast_vec:
case ast_hash: case ast_hash:
case ast_call: case ast_call:
case ast_equal: case ast_equal:
@ -823,10 +823,10 @@ void nasal_codegen::block_gen(nasal_ast& ast)
case ast_link: case ast_link:
case ast_cmp_equal: case ast_cmp_equal:
case ast_cmp_not_equal: case ast_cmp_not_equal:
case ast_less_equal: case ast_leq:
case ast_less_than: case ast_less:
case ast_greater_equal: case ast_geq:
case ast_greater_than: case ast_grt:
case ast_or: case ast_or:
case ast_and: case ast_and:
case ast_trinocular:calculation_gen(tmp);pop_gen();break; case ast_trinocular:calculation_gen(tmp);pop_gen();break;
@ -859,7 +859,7 @@ void nasal_codegen::main_progress(nasal_ast& ast)
nasal_ast& tmp=ast.get_children()[i]; nasal_ast& tmp=ast.get_children()[i];
switch(tmp.get_type()) switch(tmp.get_type())
{ {
case ast_null:case ast_nil:case ast_number:case ast_string:case ast_function:break; case ast_null:case ast_nil:case ast_num:case ast_str:case ast_func:break;
case ast_definition:definition_gen(tmp);break; case ast_definition:definition_gen(tmp);break;
case ast_multi_assign:multi_assignment_gen(tmp);break; case ast_multi_assign:multi_assignment_gen(tmp);break;
case ast_conditional:conditional_gen(tmp);break; case ast_conditional:conditional_gen(tmp);break;
@ -867,8 +867,8 @@ void nasal_codegen::main_progress(nasal_ast& ast)
case ast_for: case ast_for:
case ast_forindex: case ast_forindex:
case ast_foreach:loop_gen(tmp);break; case ast_foreach:loop_gen(tmp);break;
case ast_identifier: case ast_id:
case ast_vector: case ast_vec:
case ast_hash: case ast_hash:
case ast_call: case ast_call:
case ast_equal: case ast_equal:
@ -886,10 +886,10 @@ void nasal_codegen::main_progress(nasal_ast& ast)
case ast_link: case ast_link:
case ast_cmp_equal: case ast_cmp_equal:
case ast_cmp_not_equal: case ast_cmp_not_equal:
case ast_less_equal: case ast_leq:
case ast_less_than: case ast_less:
case ast_greater_equal: case ast_geq:
case ast_greater_than: case ast_grt:
case ast_or: case ast_or:
case ast_and: case ast_and:
case ast_trinocular:calculation_gen(tmp);pop_gen();break; case ast_trinocular:calculation_gen(tmp);pop_gen();break;

View File

@ -47,7 +47,7 @@ bool nasal_import::check_import(nasal_ast& node)
return false; return false;
if(ref_vec[1].get_type()!=ast_call_func) if(ref_vec[1].get_type()!=ast_call_func)
return false; return false;
if(ref_vec[1].get_children().size()!=1 || ref_vec[1].get_children()[0].get_type()!=ast_string) if(ref_vec[1].get_children().size()!=1 || ref_vec[1].get_children()[0].get_type()!=ast_str)
return false; return false;
return true; return true;
} }

View File

@ -16,18 +16,18 @@
enum token_type enum token_type
{ {
tok_null=0, tok_null=0,
tok_number,tok_string,tok_identifier, tok_num,tok_str,tok_id,
tok_for,tok_forindex,tok_foreach,tok_while, tok_for,tok_forindex,tok_foreach,tok_while,
tok_var,tok_func,tok_break,tok_continue, tok_var,tok_func,tok_break,tok_continue,
tok_return,tok_if,tok_elsif,tok_else,tok_nil, tok_ret,tok_if,tok_elsif,tok_else,tok_nil,
tok_left_curve,tok_right_curve, tok_lcurve,tok_rcurve,
tok_left_bracket,tok_right_bracket, tok_lbracket,tok_rbracket,
tok_left_brace,tok_right_brace, tok_lbrace,tok_rbrace,
tok_semi,tok_and,tok_or,tok_comma,tok_dot,tok_ellipsis,tok_quesmark, tok_semi,tok_and,tok_or,tok_comma,tok_dot,tok_ellipsis,tok_quesmark,
tok_colon,tok_add,tok_sub,tok_mult,tok_div,tok_link,tok_not, tok_colon,tok_add,tok_sub,tok_mult,tok_div,tok_link,tok_not,
tok_equal, tok_eq,
tok_add_equal,tok_sub_equal,tok_mult_equal,tok_div_equal,tok_link_equal, tok_addeq,tok_subeq,tok_multeq,tok_diveq,tok_lnkeq,
tok_cmp_equal,tok_cmp_not_equal,tok_less_than,tok_less_equal,tok_greater_than,tok_greater_equal tok_cmpeq,tok_neq,tok_less,tok_leq,tok_grt,tok_geq
}; };
struct struct
@ -44,17 +44,17 @@ struct
{"func" ,tok_func }, {"func" ,tok_func },
{"break" ,tok_break }, {"break" ,tok_break },
{"continue",tok_continue }, {"continue",tok_continue },
{"return" ,tok_return }, {"return" ,tok_ret },
{"if" ,tok_if }, {"if" ,tok_if },
{"elsif" ,tok_elsif }, {"elsif" ,tok_elsif },
{"else" ,tok_else }, {"else" ,tok_else },
{"nil" ,tok_nil }, {"nil" ,tok_nil },
{"(" ,tok_left_curve }, {"(" ,tok_lcurve },
{")" ,tok_right_curve }, {")" ,tok_rcurve },
{"[" ,tok_left_bracket }, {"[" ,tok_lbracket },
{"]" ,tok_right_bracket}, {"]" ,tok_rbracket },
{"{" ,tok_left_brace }, {"{" ,tok_lbrace },
{"}" ,tok_right_brace }, {"}" ,tok_rbrace },
{";" ,tok_semi }, {";" ,tok_semi },
{"and" ,tok_and }, {"and" ,tok_and },
{"or" ,tok_or }, {"or" ,tok_or },
@ -69,18 +69,18 @@ struct
{"/" ,tok_div }, {"/" ,tok_div },
{"~" ,tok_link }, {"~" ,tok_link },
{"!" ,tok_not }, {"!" ,tok_not },
{"=" ,tok_equal }, {"=" ,tok_eq },
{"+=" ,tok_add_equal }, {"+=" ,tok_addeq },
{"-=" ,tok_sub_equal }, {"-=" ,tok_subeq },
{"*=" ,tok_mult_equal }, {"*=" ,tok_multeq },
{"/=" ,tok_div_equal }, {"/=" ,tok_diveq },
{"~=" ,tok_link_equal }, {"~=" ,tok_lnkeq },
{"==" ,tok_cmp_equal }, {"==" ,tok_cmpeq },
{"!=" ,tok_cmp_not_equal}, {"!=" ,tok_neq },
{"<" ,tok_less_than }, {"<" ,tok_less },
{"<=" ,tok_less_equal }, {"<=" ,tok_leq },
{">" ,tok_greater_than }, {">" ,tok_grt },
{">=" ,tok_greater_equal}, {">=" ,tok_geq },
{NULL ,-1 } {NULL ,-1 }
}; };
@ -322,19 +322,19 @@ void nasal_lexer::scanner()
token_str=identifier_gen(); token_str=identifier_gen();
token new_token(line,get_token_type(token_str),token_str); token new_token(line,get_token_type(token_str),token_str);
if(!new_token.type) if(!new_token.type)
new_token.type=tok_identifier; new_token.type=tok_id;
token_list.push_back(new_token); token_list.push_back(new_token);
} }
else if(IS_DIGIT(res[ptr])) else if(IS_DIGIT(res[ptr]))
{ {
token_str=number_gen(); token_str=number_gen();
token new_token(line,tok_number,token_str); token new_token(line,tok_num,token_str);
token_list.push_back(new_token); token_list.push_back(new_token);
} }
else if(IS_STRING(res[ptr])) else if(IS_STRING(res[ptr]))
{ {
token_str=string_gen(); token_str=string_gen();
token new_token(line,tok_string,token_str); token new_token(line,tok_str,token_str);
token_list.push_back(new_token); token_list.push_back(new_token);
} }
else if(IS_SINGLE_OPERATOR(res[ptr])) else if(IS_SINGLE_OPERATOR(res[ptr]))

View File

@ -39,7 +39,7 @@
class nasal_parse class nasal_parse
{ {
#define error_line (tok_list[ptr>=tok_list_size? tok_list_size-1:ptr].line) #define error_line (tok_list[ptr>=tok_list_size? tok_list_size-1:ptr].line)
#define is_call(type) ((type)==tok_left_curve || (type)==tok_left_bracket || (type)==tok_dot) #define is_call(type) ((type)==tok_lcurve || (type)==tok_lbracket || (type)==tok_dot)
private: private:
int tok_list_size; int tok_list_size;
int ptr; int ptr;
@ -50,7 +50,7 @@ private:
int in_loop; // count when generating loop block,used to check break/continue-expression int in_loop; // count when generating loop block,used to check break/continue-expression
void reset(); void reset();
void die(int,std::string); void die(int,std::string);
bool check_multi_definition(); bool check_multi_def();
bool check_multi_scalar(); bool check_multi_scalar();
bool check_function_end(nasal_ast&); bool check_function_end(nasal_ast&);
bool check_special_call(); bool check_special_call();
@ -58,17 +58,17 @@ private:
void check_memory_reachable(nasal_ast&); void check_memory_reachable(nasal_ast&);
nasal_ast null_node_gen(); nasal_ast null_node_gen();
nasal_ast nil_gen(); nasal_ast nil_gen();
nasal_ast number_gen(); nasal_ast num_gen();
nasal_ast string_gen(); nasal_ast str_gen();
nasal_ast id_gen(); nasal_ast id_gen();
nasal_ast vector_gen(); nasal_ast vec_gen();
nasal_ast hash_gen(); nasal_ast hash_gen();
nasal_ast hash_member_gen(); nasal_ast hmem_gen(); // hash member
nasal_ast func_gen(); nasal_ast func_gen();
nasal_ast args_list_gen(); nasal_ast args_gen();
nasal_ast expr(); nasal_ast expr();
nasal_ast exprs_gen(); nasal_ast exprs_gen();
nasal_ast calculation(); nasal_ast calc();
nasal_ast or_expr(); nasal_ast or_expr();
nasal_ast and_expr(); nasal_ast and_expr();
nasal_ast cmp_expr(); nasal_ast cmp_expr();
@ -78,7 +78,7 @@ private:
nasal_ast scalar(); nasal_ast scalar();
nasal_ast call_scalar(); nasal_ast call_scalar();
nasal_ast call_hash(); nasal_ast call_hash();
nasal_ast call_vector(); nasal_ast call_vec();
nasal_ast call_func(); nasal_ast call_func();
nasal_ast subvec(); nasal_ast subvec();
nasal_ast definition(); nasal_ast definition();
@ -108,9 +108,9 @@ int nasal_parse::get_error()
return error; return error;
} }
void nasal_parse::set_toklist(std::vector<token>& lex_token) void nasal_parse::set_toklist(std::vector<token>& toks)
{ {
tok_list=lex_token; tok_list=toks;
tok_list_size=tok_list.size(); tok_list_size=tok_list.size();
return; return;
} }
@ -165,7 +165,7 @@ void nasal_parse::die(int line,std::string info)
return; return;
} }
bool nasal_parse::check_multi_definition() bool nasal_parse::check_multi_def()
{ {
return ptr+1<tok_list_size && tok_list[ptr+1].type==tok_var; return ptr+1<tok_list_size && tok_list[ptr+1].type==tok_var;
} }
@ -177,12 +177,12 @@ bool nasal_parse::check_multi_scalar()
{ {
switch(tok_list[check_ptr].type) switch(tok_list[check_ptr].type)
{ {
case tok_left_curve: ++curve_cnt; break; case tok_lcurve: ++curve_cnt; break;
case tok_left_bracket: ++bracket_cnt;break; case tok_lbracket: ++bracket_cnt;break;
case tok_left_brace: ++brace_cnt; break; case tok_lbrace: ++brace_cnt; break;
case tok_right_curve: --curve_cnt; break; case tok_rcurve: --curve_cnt; break;
case tok_right_bracket:--bracket_cnt;break; case tok_rbracket:--bracket_cnt;break;
case tok_right_brace: --brace_cnt; break; case tok_rbrace: --brace_cnt; break;
} }
if(curve_cnt==1 && !bracket_cnt && !brace_cnt && tok_list[check_ptr].type==tok_comma) if(curve_cnt==1 && !bracket_cnt && !brace_cnt && tok_list[check_ptr].type==tok_comma)
return true; return true;
@ -193,9 +193,9 @@ bool nasal_parse::check_multi_scalar()
bool nasal_parse::check_function_end(nasal_ast& node) bool nasal_parse::check_function_end(nasal_ast& node)
{ {
int type=node.get_type(); int type=node.get_type();
if(type==ast_function) if(type==ast_func)
return true; return true;
else if(type==ast_number || type==ast_identifier || type==ast_string || type==ast_nil || type==ast_vector || type==ast_hash) else if(type==ast_num || type==ast_id || type==ast_str || type==ast_nil || type==ast_vec || type==ast_hash)
return false; return false;
if( if(
node.get_children().empty() || node.get_children().empty() ||
@ -224,12 +224,12 @@ bool nasal_parse::check_special_call()
{ {
switch(tok_list[check_ptr].type) switch(tok_list[check_ptr].type)
{ {
case tok_left_curve: ++curve_cnt; break; case tok_lcurve: ++curve_cnt; break;
case tok_left_bracket: ++bracket_cnt;break; case tok_lbracket: ++bracket_cnt;break;
case tok_left_brace: ++brace_cnt; break; case tok_lbrace: ++brace_cnt; break;
case tok_right_curve: --curve_cnt; break; case tok_rcurve: --curve_cnt; break;
case tok_right_bracket:--bracket_cnt;break; case tok_rbracket: --bracket_cnt;break;
case tok_right_brace: --brace_cnt; break; case tok_rbrace: --brace_cnt; break;
} }
// m?1:0 will be recognized as normal parameter // m?1:0 will be recognized as normal parameter
if(curve_cnt==1 && !bracket_cnt && !brace_cnt && tok_list[check_ptr].type==tok_quesmark) if(curve_cnt==1 && !bracket_cnt && !brace_cnt && tok_list[check_ptr].type==tok_quesmark)
@ -252,19 +252,19 @@ void nasal_parse::check_memory_reachable(nasal_ast& node)
{ {
if(node.get_type()==ast_call) if(node.get_type()==ast_call)
{ {
if(node.get_children()[0].get_type()!=ast_identifier) if(node.get_children()[0].get_type()!=ast_id)
die(node.get_line(),"cannot get the memory of a temporary data"); die(node.get_line(),"cannot get the memory of a temporary data");
int size=node.get_children().size(); int size=node.get_children().size();
for(int i=0;i<size;++i) for(int i=0;i<size;++i)
{ {
nasal_ast& tmp_node=node.get_children()[i]; nasal_ast& tmp=node.get_children()[i];
if(tmp_node.get_type()==ast_call_func) if(tmp.get_type()==ast_call_func)
die(tmp_node.get_line(),"cannot get the memory of function-returned value"); die(tmp.get_line(),"cannot get the memory of function-returned value");
if(tmp_node.get_type()==ast_call_vec && (tmp_node.get_children().size()>1 || tmp_node.get_children()[0].get_type()==ast_subvec)) if(tmp.get_type()==ast_call_vec && (tmp.get_children().size()>1 || tmp.get_children()[0].get_type()==ast_subvec))
die(tmp_node.get_line(),"cannot get the memory in temporary sliced vector"); die(tmp.get_line(),"cannot get the memory in temporary sliced vector");
} }
} }
else if(node.get_type()!=ast_identifier) else if(node.get_type()!=ast_id)
die(node.get_line(),"cannot use calculation as the memory of scalar"); die(node.get_line(),"cannot use calculation as the memory of scalar");
return; return;
} }
@ -281,42 +281,42 @@ nasal_ast nasal_parse::nil_gen()
return node; return node;
} }
nasal_ast nasal_parse::number_gen() nasal_ast nasal_parse::num_gen()
{ {
nasal_ast node(tok_list[ptr].line,ast_number); nasal_ast node(tok_list[ptr].line,ast_num);
node.set_num(trans_string_to_number(tok_list[ptr].str)); node.set_num(trans_string_to_number(tok_list[ptr].str));
return node; return node;
} }
nasal_ast nasal_parse::string_gen() nasal_ast nasal_parse::str_gen()
{ {
nasal_ast node(tok_list[ptr].line,ast_string); nasal_ast node(tok_list[ptr].line,ast_str);
node.set_str(tok_list[ptr].str); node.set_str(tok_list[ptr].str);
return node; return node;
} }
nasal_ast nasal_parse::id_gen() nasal_ast nasal_parse::id_gen()
{ {
nasal_ast node(tok_list[ptr].line,ast_identifier); nasal_ast node(tok_list[ptr].line,ast_id);
node.set_str(tok_list[ptr].str); node.set_str(tok_list[ptr].str);
return node; return node;
} }
nasal_ast nasal_parse::vector_gen() nasal_ast nasal_parse::vec_gen()
{ {
nasal_ast node(tok_list[ptr].line,ast_vector); nasal_ast node(tok_list[ptr].line,ast_vec);
++ptr; ++ptr;
while(ptr<tok_list_size && tok_list[ptr].type!=tok_right_bracket) while(ptr<tok_list_size && tok_list[ptr].type!=tok_rbracket)
{ {
node.add_child(calculation()); node.add_child(calc());
if(++ptr>=tok_list_size) if(++ptr>=tok_list_size)
break; break;
if(tok_list[ptr].type==tok_comma) if(tok_list[ptr].type==tok_comma)
++ptr; ++ptr;
else if(tok_list[ptr].type!=tok_right_bracket) else if(tok_list[ptr].type!=tok_rbracket)
break; break;
} }
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_right_bracket) if(ptr>=tok_list_size || tok_list[ptr].type!=tok_rbracket)
die(error_line,"expected \"]\""); die(error_line,"expected \"]\"");
return node; return node;
} }
@ -324,50 +324,50 @@ nasal_ast nasal_parse::hash_gen()
{ {
nasal_ast node(tok_list[ptr].line,ast_hash); nasal_ast node(tok_list[ptr].line,ast_hash);
++ptr; ++ptr;
while (ptr<tok_list_size && tok_list[ptr].type!=tok_right_brace) while (ptr<tok_list_size && tok_list[ptr].type!=tok_rbrace)
{ {
node.add_child(hash_member_gen()); node.add_child(hmem_gen());
if(++ptr>=tok_list_size) if(++ptr>=tok_list_size)
break; break;
if(tok_list[ptr].type==tok_comma) if(tok_list[ptr].type==tok_comma)
++ptr; ++ptr;
else if(tok_list[ptr].type!=tok_right_brace) else if(tok_list[ptr].type!=tok_rbrace)
break; break;
} }
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_right_brace) if(ptr>=tok_list_size || tok_list[ptr].type!=tok_rbrace)
die(error_line,"expected \"}\""); die(error_line,"expected \"}\"");
return node; return node;
} }
nasal_ast nasal_parse::hash_member_gen() nasal_ast nasal_parse::hmem_gen()
{ {
if(ptr>=tok_list_size || (tok_list[ptr].type!=tok_identifier && tok_list[ptr].type!=tok_string)) if(ptr>=tok_list_size || (tok_list[ptr].type!=tok_id && tok_list[ptr].type!=tok_str))
{ {
die(error_line,"expected identifier/string"); die(error_line,"expected identifier/string");
nasal_ast nullnode; nasal_ast nullnode;
return nullnode; return nullnode;
} }
nasal_ast node(tok_list[ptr].line,ast_hashmember); nasal_ast node(tok_list[ptr].line,ast_hashmember);
node.add_child(tok_list[ptr].type==tok_identifier?id_gen():string_gen()); node.add_child(tok_list[ptr].type==tok_id?id_gen():str_gen());
if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_colon) if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_colon)
{ {
die(error_line,"expected \":\""); die(error_line,"expected \":\"");
return node; return node;
} }
++ptr; ++ptr;
node.add_child(calculation()); node.add_child(calc());
return node; return node;
} }
nasal_ast nasal_parse::func_gen() nasal_ast nasal_parse::func_gen()
{ {
nasal_ast node(tok_list[ptr].line,ast_function); nasal_ast node(tok_list[ptr].line,ast_func);
if(++ptr>=tok_list_size) if(++ptr>=tok_list_size)
{ {
die(error_line,"expected argument(s)/expression block"); die(error_line,"expected argument(s)/expression block");
return node; return node;
} }
if(tok_list[ptr].type==tok_left_curve) if(tok_list[ptr].type==tok_lcurve)
{ {
node.add_child(args_list_gen()); node.add_child(args_gen());
++ptr; ++ptr;
} }
else else
@ -378,27 +378,27 @@ nasal_ast nasal_parse::func_gen()
node.add_child(exprs_gen()); node.add_child(exprs_gen());
return node; return node;
} }
nasal_ast nasal_parse::args_list_gen() nasal_ast nasal_parse::args_gen()
{ {
nasal_ast node(tok_list[ptr].line,ast_args); nasal_ast node(tok_list[ptr].line,ast_args);
++ptr; ++ptr;
while(ptr<tok_list_size && tok_list[ptr].type!=tok_right_curve) while(ptr<tok_list_size && tok_list[ptr].type!=tok_rcurve)
{ {
nasal_ast tmp; nasal_ast tmp;
if(tok_list[ptr].type!=tok_identifier) if(tok_list[ptr].type!=tok_id)
{ {
die(error_line,"expected identifier"); die(error_line,"expected identifier");
return node; return node;
} }
tmp=id_gen(); tmp=id_gen();
if(++ptr<tok_list_size && (tok_list[ptr].type==tok_equal || tok_list[ptr].type==tok_ellipsis)) if(++ptr<tok_list_size && (tok_list[ptr].type==tok_eq || tok_list[ptr].type==tok_ellipsis))
{ {
nasal_ast special_arg(tok_list[ptr].line); nasal_ast special_arg(tok_list[ptr].line);
if(tok_list[ptr].type==tok_equal) if(tok_list[ptr].type==tok_eq)
{ {
special_arg.add_child(tmp); special_arg.add_child(tmp);
++ptr; ++ptr;
special_arg.add_child(calculation()); special_arg.add_child(calc());
special_arg.set_type(ast_default_arg); special_arg.set_type(ast_default_arg);
} }
else else
@ -417,10 +417,10 @@ nasal_ast nasal_parse::args_list_gen()
break; break;
if(tok_list[ptr].type==tok_comma) if(tok_list[ptr].type==tok_comma)
++ptr; ++ptr;
else if(tok_list[ptr].type!=tok_right_curve) else if(tok_list[ptr].type!=tok_rcurve)
break; break;
} }
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve) if(ptr>=tok_list_size || tok_list[ptr].type!=tok_rcurve)
{ {
die(error_line,"expected \")\""); die(error_line,"expected \")\"");
return node; return node;
@ -432,7 +432,7 @@ nasal_ast nasal_parse::args_list_gen()
{ {
switch(node.get_children()[i].get_type()) switch(node.get_children()[i].get_type())
{ {
case ast_identifier: args_format+="val";break; case ast_id: args_format+="val";break;
case ast_default_arg: args_format+="val=scalar";break; case ast_default_arg: args_format+="val=scalar";break;
case ast_dynamic_id: args_format+="val...";break; case ast_dynamic_id: args_format+="val...";break;
} }
@ -457,7 +457,7 @@ nasal_ast nasal_parse::args_list_gen()
switch(node.get_children()[i].get_type()) switch(node.get_children()[i].get_type())
{ {
case ast_dynamic_id: case ast_dynamic_id:
case ast_identifier:new_name=node.get_children()[i].get_str();break; case ast_id:new_name=node.get_children()[i].get_str();break;
case ast_default_arg:new_name=node.get_children()[i].get_children()[0].get_str();break; case ast_default_arg:new_name=node.get_children()[i].get_children()[0].get_str();break;
} }
if(argname_table.find(new_name)!=argname_table.end()) if(argname_table.find(new_name)!=argname_table.end())
@ -473,21 +473,21 @@ nasal_ast nasal_parse::expr()
int tok_type=tok_list[ptr].type; int tok_type=tok_list[ptr].type;
if((tok_type==tok_break || tok_type==tok_continue) && !in_loop) if((tok_type==tok_break || tok_type==tok_continue) && !in_loop)
die(error_line,"cannot use break/continue outside loop"); die(error_line,"cannot use break/continue outside loop");
if(tok_type==tok_return && !in_function) if(tok_type==tok_ret && !in_function)
die(error_line,"cannot use return outside function"); die(error_line,"cannot use return outside function");
switch(tok_type) switch(tok_type)
{ {
case tok_nil: case tok_nil:
case tok_number: case tok_num:
case tok_string: case tok_str:
case tok_identifier: case tok_id:
case tok_func: case tok_func:
case tok_left_bracket: case tok_lbracket:
case tok_left_brace: case tok_lbrace:
case tok_sub: case tok_sub:
case tok_not: node=calculation(); break; case tok_not: node=calc(); break;
case tok_var: node=definition(); break; case tok_var: node=definition(); break;
case tok_left_curve: node=(check_multi_definition()?definition():(check_multi_scalar()?multi_assgin():calculation()));break; case tok_lcurve: node=(check_multi_def()?definition():(check_multi_scalar()?multi_assgin():calc()));break;
case tok_for: case tok_for:
case tok_forindex: case tok_forindex:
case tok_foreach: case tok_foreach:
@ -495,7 +495,7 @@ nasal_ast nasal_parse::expr()
case tok_if: node=conditional(); break; case tok_if: node=conditional(); break;
case tok_continue: node=continue_expr(); break; case tok_continue: node=continue_expr(); break;
case tok_break: node=break_expr(); break; case tok_break: node=break_expr(); break;
case tok_return: node=return_expr(); break; case tok_ret: node=return_expr(); break;
case tok_semi: --ptr; break; case tok_semi: --ptr; break;
default: die(error_line,"error token \""+tok_list[ptr].str+"\"");break; default: die(error_line,"error token \""+tok_list[ptr].str+"\"");break;
} }
@ -510,10 +510,10 @@ nasal_ast nasal_parse::exprs_gen()
return nullnode; return nullnode;
} }
nasal_ast node(tok_list[ptr].line,ast_block); nasal_ast node(tok_list[ptr].line,ast_block);
if(tok_list[ptr].type==tok_left_brace) if(tok_list[ptr].type==tok_lbrace)
{ {
int left_brace_line=tok_list[ptr++].line; int left_brace_line=tok_list[ptr++].line;
while(ptr<tok_list_size && tok_list[ptr].type!=tok_right_brace) while(ptr<tok_list_size && tok_list[ptr].type!=tok_rbrace)
{ {
node.add_child(expr()); node.add_child(expr());
if(++ptr>=tok_list_size) if(++ptr>=tok_list_size)
@ -523,14 +523,14 @@ nasal_ast nasal_parse::exprs_gen()
else if(need_semi_check(node.get_children().back())) else if(need_semi_check(node.get_children().back()))
{ {
// the last expression can be recognized without semi // the last expression can be recognized without semi
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_right_brace) if(ptr>=tok_list_size || tok_list[ptr].type!=tok_rbrace)
{ {
die(error_line,"expected \";\""); die(error_line,"expected \";\"");
break; break;
} }
} }
} }
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_right_brace) if(ptr>=tok_list_size || tok_list[ptr].type!=tok_rbrace)
{ {
std::string lb_line=""; std::string lb_line="";
while(left_brace_line) while(left_brace_line)
@ -548,7 +548,7 @@ nasal_ast nasal_parse::exprs_gen()
} }
return node; return node;
} }
nasal_ast nasal_parse::calculation() nasal_ast nasal_parse::calc()
{ {
nasal_ast node; nasal_ast node;
if(ptr>=tok_list_size) if(ptr>=tok_list_size)
@ -564,25 +564,25 @@ nasal_ast nasal_parse::calculation()
nasal_ast tmp(tok_list[ptr].line,ast_trinocular); nasal_ast tmp(tok_list[ptr].line,ast_trinocular);
tmp.add_child(node); tmp.add_child(node);
++ptr; ++ptr;
tmp.add_child(calculation()); tmp.add_child(calc());
if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_colon) if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_colon)
{ {
die(error_line,"expected \":\""); die(error_line,"expected \":\"");
return node; return node;
} }
++ptr; ++ptr;
tmp.add_child(calculation()); tmp.add_child(calc());
node=tmp; node=tmp;
} }
else if(ptr<tok_list_size && tok_equal<=tok_list[ptr].type && tok_list[ptr].type<=tok_link_equal) else if(ptr<tok_list_size && tok_eq<=tok_list[ptr].type && tok_list[ptr].type<=tok_lnkeq)
{ {
// check the left expression to confirm it is available to get memory // check the left expression to confirm it is available to get memory
check_memory_reachable(node); check_memory_reachable(node);
// tok_equal~tok_link_equal is 37 to 42,ast_equal~ast_link_equal is 21~26 // tok_eq~tok_lnkeq is 37 to 42,ast_equal~ast_link_equal is 21~26
nasal_ast tmp(tok_list[ptr].line,tok_list[ptr].type-tok_equal+ast_equal); nasal_ast tmp(tok_list[ptr].line,tok_list[ptr].type-tok_eq+ast_equal);
tmp.add_child(node); tmp.add_child(node);
++ptr; ++ptr;
tmp.add_child(calculation()); tmp.add_child(calc());
node=tmp; node=tmp;
} }
else --ptr; else --ptr;
@ -626,10 +626,10 @@ nasal_ast nasal_parse::cmp_expr()
{ {
nasal_ast node; nasal_ast node;
node=additive_expr(); node=additive_expr();
while(++ptr<tok_list_size && tok_cmp_equal<=tok_list[ptr].type && tok_list[ptr].type<=tok_greater_equal) while(++ptr<tok_list_size && tok_cmpeq<=tok_list[ptr].type && tok_list[ptr].type<=tok_geq)
{ {
// tok_cmp_equal~tok_greater_equal is 43~48,ast_cmp_equal~ast_greater_equal is 27~32 // tok_cmpeq~tok_geq is 43~48,ast_cmp_equal~ast_geq is 27~32
nasal_ast tmp(tok_list[ptr].line,tok_list[ptr].type-tok_cmp_equal+ast_cmp_equal); nasal_ast tmp(tok_list[ptr].line,tok_list[ptr].type-tok_cmpeq+ast_cmp_equal);
tmp.add_child(node); tmp.add_child(node);
if(++ptr<tok_list_size) if(++ptr<tok_list_size)
tmp.add_child(additive_expr()); tmp.add_child(additive_expr());
@ -682,12 +682,12 @@ nasal_ast nasal_parse::multive_expr()
int type1=tmp.get_children()[0].get_type(); int type1=tmp.get_children()[0].get_type();
int type2=tmp.get_children()[1].get_type(); int type2=tmp.get_children()[1].get_type();
double num1,num2,num; double num1,num2,num;
if(type1==ast_number && type2==ast_number) if(type1==ast_num && type2==ast_num)
{ {
num1=tmp.get_children()[0].get_num(); num1=tmp.get_children()[0].get_num();
num2=tmp.get_children()[1].get_num(); num2=tmp.get_children()[1].get_num();
num=(tmp.get_type()==ast_mult? num1*num2:num1/num2); num=(tmp.get_type()==ast_mult? num1*num2:num1/num2);
tmp.set_type(ast_number); tmp.set_type(ast_num);
tmp.set_num(num); tmp.set_num(num);
tmp.get_children().clear(); tmp.get_children().clear();
} }
@ -709,11 +709,11 @@ nasal_ast nasal_parse::unary()
else else
die(error_line,"expected calculation"); die(error_line,"expected calculation");
// pre-calculation // pre-calculation
if(node.get_children()[0].get_type()==ast_number) if(node.get_children()[0].get_type()==ast_num)
{ {
double num=node.get_children()[0].get_num(); double num=node.get_children()[0].get_num();
num=(node.get_type()==ast_unary_not?(!num):-num); num=(node.get_type()==ast_unary_not?(!num):-num);
node.set_type(ast_number); node.set_type(ast_num);
node.set_num(num); node.set_num(num);
node.get_children().clear(); node.get_children().clear();
} }
@ -724,15 +724,15 @@ nasal_ast nasal_parse::scalar()
nasal_ast node(tok_list[ptr].line); nasal_ast node(tok_list[ptr].line);
if(tok_list[ptr].type==tok_nil) if(tok_list[ptr].type==tok_nil)
node=nil_gen(); node=nil_gen();
else if(tok_list[ptr].type==tok_number) else if(tok_list[ptr].type==tok_num)
node=number_gen(); node=num_gen();
else if(tok_list[ptr].type==tok_string) else if(tok_list[ptr].type==tok_str)
node=string_gen(); node=str_gen();
else if(tok_list[ptr].type==tok_identifier) else if(tok_list[ptr].type==tok_id)
node=id_gen(); node=id_gen();
else if(tok_list[ptr].type==tok_func) else if(tok_list[ptr].type==tok_func)
{ {
if(ptr+1<tok_list_size && tok_list[ptr+1].type==tok_identifier) if(ptr+1<tok_list_size && tok_list[ptr+1].type==tok_id)
{ {
++ptr; ++ptr;
node=id_gen(); node=id_gen();
@ -744,16 +744,16 @@ nasal_ast nasal_parse::scalar()
--in_function; --in_function;
} }
} }
else if(tok_list[ptr].type==tok_left_bracket) else if(tok_list[ptr].type==tok_lbracket)
node=vector_gen(); node=vec_gen();
else if(tok_list[ptr].type==tok_left_brace) else if(tok_list[ptr].type==tok_lbrace)
node=hash_gen(); node=hash_gen();
else if(tok_list[ptr].type==tok_left_curve) else if(tok_list[ptr].type==tok_lcurve)
{ {
++ptr; ++ptr;
node=calculation(); node=calc();
++ptr; ++ptr;
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve) if(ptr>=tok_list_size || tok_list[ptr].type!=tok_rcurve)
die(error_line,"expected \")\""); die(error_line,"expected \")\"");
} }
else else
@ -780,8 +780,8 @@ nasal_ast nasal_parse::call_scalar()
nasal_ast node; nasal_ast node;
switch(tok_list[ptr].type) switch(tok_list[ptr].type)
{ {
case tok_left_curve: node=call_func(); break; case tok_lcurve: node=call_func(); break;
case tok_left_bracket: node=call_vector(); break; case tok_lbracket: node=call_vec(); break;
case tok_dot: node=call_hash(); break; case tok_dot: node=call_hash(); break;
} }
return node; return node;
@ -789,27 +789,27 @@ nasal_ast nasal_parse::call_scalar()
nasal_ast nasal_parse::call_hash() nasal_ast nasal_parse::call_hash()
{ {
nasal_ast node(tok_list[ptr].line,ast_call_hash); nasal_ast node(tok_list[ptr].line,ast_call_hash);
if(++ptr<tok_list_size && tok_list[ptr].type==tok_identifier) if(++ptr<tok_list_size && tok_list[ptr].type==tok_id)
node.set_str(tok_list[ptr].str); node.set_str(tok_list[ptr].str);
else else
die(error_line,"expected identifier"); die(error_line,"expected identifier");
return node; return node;
} }
nasal_ast nasal_parse::call_vector() nasal_ast nasal_parse::call_vec()
{ {
nasal_ast node(tok_list[ptr].line,ast_call_vec); nasal_ast node(tok_list[ptr].line,ast_call_vec);
++ptr; ++ptr;
while(ptr<tok_list_size && tok_list[ptr].type!=tok_right_bracket) while(ptr<tok_list_size && tok_list[ptr].type!=tok_rbracket)
{ {
node.add_child(subvec()); node.add_child(subvec());
if(++ptr>=tok_list_size) if(++ptr>=tok_list_size)
break; break;
else if(tok_list[ptr].type==tok_comma) else if(tok_list[ptr].type==tok_comma)
++ptr; ++ptr;
else if(tok_list[ptr].type!=tok_right_bracket) else if(tok_list[ptr].type!=tok_rbracket)
break; break;
} }
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_right_bracket) if(ptr>=tok_list_size || tok_list[ptr].type!=tok_rbracket)
die(error_line,"expected \"]\""); die(error_line,"expected \"]\"");
return node; return node;
} }
@ -818,17 +818,17 @@ nasal_ast nasal_parse::call_func()
nasal_ast node(tok_list[ptr].line,ast_call_func); nasal_ast node(tok_list[ptr].line,ast_call_func);
bool special_call=check_special_call(); bool special_call=check_special_call();
++ptr; ++ptr;
while(ptr<tok_list_size && tok_list[ptr].type!=tok_right_curve) while(ptr<tok_list_size && tok_list[ptr].type!=tok_rcurve)
{ {
node.add_child(special_call?hash_member_gen():calculation()); node.add_child(special_call?hmem_gen():calc());
if(++ptr>=tok_list_size) if(++ptr>=tok_list_size)
break; break;
else if(tok_list[ptr].type==tok_comma) else if(tok_list[ptr].type==tok_comma)
++ptr; ++ptr;
else if(tok_list[ptr].type!=tok_right_curve) else if(tok_list[ptr].type!=tok_rcurve)
break; break;
} }
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve) if(ptr>=tok_list_size || tok_list[ptr].type!=tok_rcurve)
die(error_line,"expected \")\""); die(error_line,"expected \")\"");
return node; return node;
} }
@ -840,7 +840,7 @@ nasal_ast nasal_parse::subvec()
--ptr; --ptr;
node=nil_gen(); node=nil_gen();
} }
else node=calculation(); else node=calc();
++ptr; ++ptr;
if(ptr<tok_list_size && tok_list[ptr].type==tok_colon) if(ptr<tok_list_size && tok_list[ptr].type==tok_colon)
{ {
@ -848,13 +848,13 @@ nasal_ast nasal_parse::subvec()
return node; return node;
nasal_ast tmp(node.get_line(),ast_subvec); nasal_ast tmp(node.get_line(),ast_subvec);
tmp.add_child(node); tmp.add_child(node);
if(tok_list[ptr].type==tok_comma || tok_list[ptr].type==tok_right_bracket) if(tok_list[ptr].type==tok_comma || tok_list[ptr].type==tok_rbracket)
{ {
--ptr; --ptr;
tmp.add_child(nil_gen()); tmp.add_child(nil_gen());
} }
else else
tmp.add_child(calculation()); tmp.add_child(calc());
node=tmp; node=tmp;
} }
else else
@ -873,14 +873,14 @@ nasal_ast nasal_parse::definition()
} }
switch(tok_list[ptr].type) switch(tok_list[ptr].type)
{ {
case tok_identifier:node.add_child(id_gen()); break; case tok_id:node.add_child(id_gen()); break;
case tok_left_curve:node.add_child(var_outcurve_def()); break; case tok_lcurve:node.add_child(var_outcurve_def()); break;
default:die(error_line,"expected identifier"); return node; default:die(error_line,"expected identifier"); return node;
} }
} }
else if(tok_list[ptr].type==tok_left_curve) else if(tok_list[ptr].type==tok_lcurve)
node.add_child(var_incurve_def()); node.add_child(var_incurve_def());
if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_equal) if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_eq)
{ {
die(error_line,"expected \"=\" / don\'t call identifier in definition"); die(error_line,"expected \"=\" / don\'t call identifier in definition");
return node; return node;
@ -890,11 +890,11 @@ nasal_ast nasal_parse::definition()
die(error_line,"expected scalar"); die(error_line,"expected scalar");
return node; return node;
} }
if(tok_list[ptr].type==tok_left_curve) if(tok_list[ptr].type==tok_lcurve)
node.add_child(check_multi_scalar()?multi_scalar(false):calculation()); node.add_child(check_multi_scalar()?multi_scalar(false):calc());
else else
node.add_child(calculation()); node.add_child(calc());
if(node.get_children()[0].get_type()==ast_identifier && node.get_children()[1].get_type()==ast_multi_scalar) if(node.get_children()[0].get_type()==ast_id && node.get_children()[1].get_type()==ast_multi_scalar)
die(node.get_children()[1].get_line(),"one identifier cannot accept too many values"); die(node.get_children()[1].get_line(),"one identifier cannot accept too many values");
else if(node.get_children()[0].get_type()==ast_multi_id && node.get_children()[1].get_type()==ast_multi_scalar) else if(node.get_children()[0].get_type()==ast_multi_id && node.get_children()[1].get_type()==ast_multi_scalar)
if(node.get_children()[0].get_children().size()!=node.get_children()[1].get_children().size()) if(node.get_children()[0].get_children().size()!=node.get_children()[1].get_children().size())
@ -905,11 +905,11 @@ nasal_ast nasal_parse::var_incurve_def()
{ {
nasal_ast node; nasal_ast node;
ptr+=2; ptr+=2;
// check_multi_definition will check the 'var',so there's no need to check this again // check_multi_def will check the 'var',so there's no need to check this again
node=multi_id(); node=multi_id();
if(++ptr<tok_list_size && is_call(tok_list[ptr].type)) if(++ptr<tok_list_size && is_call(tok_list[ptr].type))
die(error_line,"don\'t call identifier in multi-definition"); die(error_line,"don\'t call identifier in multi-definition");
else if(ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve) else if(ptr>=tok_list_size || tok_list[ptr].type!=tok_rcurve)
die(error_line,"expected \")\""); die(error_line,"expected \")\"");
return node; return node;
} }
@ -920,14 +920,14 @@ nasal_ast nasal_parse::var_outcurve_def()
node=multi_id(); node=multi_id();
if(++ptr<tok_list_size && is_call(tok_list[ptr].type)) if(++ptr<tok_list_size && is_call(tok_list[ptr].type))
die(error_line,"don\'t call identifier in multi-definition"); die(error_line,"don\'t call identifier in multi-definition");
else if(ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve) else if(ptr>=tok_list_size || tok_list[ptr].type!=tok_rcurve)
die(error_line,"expected \")\""); die(error_line,"expected \")\"");
return node; return node;
} }
nasal_ast nasal_parse::multi_id() nasal_ast nasal_parse::multi_id()
{ {
nasal_ast node; nasal_ast node;
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_identifier) if(ptr>=tok_list_size || tok_list[ptr].type!=tok_id)
{ {
die(error_line,"expected identifier"); die(error_line,"expected identifier");
return node; return node;
@ -952,19 +952,19 @@ nasal_ast nasal_parse::multi_scalar(bool check_call_memory)
// if check_call_memory is true,we will check if value called here can reach a memory space // if check_call_memory is true,we will check if value called here can reach a memory space
nasal_ast node(tok_list[ptr].line,ast_multi_scalar); nasal_ast node(tok_list[ptr].line,ast_multi_scalar);
++ptr; ++ptr;
while(ptr<tok_list_size && tok_list[ptr].type!=tok_right_curve) while(ptr<tok_list_size && tok_list[ptr].type!=tok_rcurve)
{ {
node.add_child(calculation()); node.add_child(calc());
if(check_call_memory) if(check_call_memory)
check_memory_reachable(node.get_children().back()); check_memory_reachable(node.get_children().back());
if(++ptr>=tok_list_size) if(++ptr>=tok_list_size)
break; break;
if(tok_list[ptr].type==tok_comma) if(tok_list[ptr].type==tok_comma)
++ptr; ++ptr;
else if(tok_list[ptr].type!=tok_right_curve) else if(tok_list[ptr].type!=tok_rcurve)
break; break;
} }
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve) if(ptr>=tok_list_size || tok_list[ptr].type!=tok_rcurve)
die(error_line,"expected \")\""); die(error_line,"expected \")\"");
return node; return node;
} }
@ -972,7 +972,7 @@ nasal_ast nasal_parse::multi_assgin()
{ {
nasal_ast node(tok_list[ptr].line,ast_multi_assign); nasal_ast node(tok_list[ptr].line,ast_multi_assign);
node.add_child(multi_scalar(true)); node.add_child(multi_scalar(true));
if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_equal) if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_eq)
{ {
die(error_line,"expected \"=\""); die(error_line,"expected \"=\"");
return node; return node;
@ -982,10 +982,10 @@ nasal_ast nasal_parse::multi_assgin()
die(error_line,"expected value list"); die(error_line,"expected value list");
return node; return node;
} }
if(tok_list[ptr].type==tok_left_curve) if(tok_list[ptr].type==tok_lcurve)
node.add_child(check_multi_scalar()?multi_scalar(false):calculation()); node.add_child(check_multi_scalar()?multi_scalar(false):calc());
else else
node.add_child(calculation()); node.add_child(calc());
if(node.get_children()[1].get_type()==ast_multi_scalar if(node.get_children()[1].get_type()==ast_multi_scalar
&& node.get_children()[0].get_children().size()!=node.get_children()[1].get_children().size()) && node.get_children()[0].get_children().size()!=node.get_children()[1].get_children().size())
die(node.get_children()[0].get_line(),"too much or lack values in multi-assignment"); die(node.get_children()[0].get_line(),"too much or lack values in multi-assignment");
@ -1008,14 +1008,14 @@ nasal_ast nasal_parse::loop()
nasal_ast nasal_parse::while_loop() nasal_ast nasal_parse::while_loop()
{ {
nasal_ast node(tok_list[ptr].line,ast_while); nasal_ast node(tok_list[ptr].line,ast_while);
if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_left_curve) if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_lcurve)
{ {
die(error_line,"expected \"(\""); die(error_line,"expected \"(\"");
return node; return node;
} }
++ptr; ++ptr;
node.add_child(calculation()); node.add_child(calc());
if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve) if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_rcurve)
{ {
die(error_line,"expected \")\""); die(error_line,"expected \")\"");
return node; return node;
@ -1027,7 +1027,7 @@ nasal_ast nasal_parse::while_loop()
nasal_ast nasal_parse::for_loop() nasal_ast nasal_parse::for_loop()
{ {
nasal_ast node(tok_list[ptr].line,ast_for); nasal_ast node(tok_list[ptr].line,ast_for);
if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_left_curve) if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_lcurve)
{ {
die(error_line,"expected \"(\""); die(error_line,"expected \"(\"");
return node; return node;
@ -1045,18 +1045,18 @@ nasal_ast nasal_parse::for_loop()
} }
else if(tok_list[ptr].type==tok_var) else if(tok_list[ptr].type==tok_var)
node.add_child(definition()); node.add_child(definition());
else if(tok_list[ptr].type==tok_left_curve) else if(tok_list[ptr].type==tok_lcurve)
node.add_child( node.add_child(
check_multi_definition()? check_multi_def()?
definition(): definition():
( (
check_multi_scalar()? check_multi_scalar()?
multi_assgin(): multi_assgin():
calculation() calc()
) )
); );
else else
node.add_child(calculation()); node.add_child(calc());
if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_semi) if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_semi)
{ {
die(error_line,"expected \";\""); die(error_line,"expected \";\"");
@ -1074,7 +1074,7 @@ nasal_ast nasal_parse::for_loop()
--ptr; --ptr;
} }
else else
node.add_child(calculation()); node.add_child(calc());
if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_semi) if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_semi)
{ {
die(error_line,"expected \";\""); die(error_line,"expected \";\"");
@ -1086,15 +1086,15 @@ nasal_ast nasal_parse::for_loop()
die(error_line,"expected calculation"); die(error_line,"expected calculation");
return node; return node;
} }
if(tok_list[ptr].type==tok_right_curve) if(tok_list[ptr].type==tok_rcurve)
{ {
node.add_child(null_node_gen()); node.add_child(null_node_gen());
--ptr; --ptr;
} }
else else
node.add_child(calculation()); node.add_child(calc());
++ptr; ++ptr;
if(ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve) if(ptr>=tok_list_size || tok_list[ptr].type!=tok_rcurve)
{ {
die(error_line,"expected \")\""); die(error_line,"expected \")\"");
return node; return node;
@ -1111,14 +1111,14 @@ nasal_ast nasal_parse::forei_loop()
case tok_forindex: node.set_type(ast_forindex);break; case tok_forindex: node.set_type(ast_forindex);break;
case tok_foreach: node.set_type(ast_foreach); break; case tok_foreach: node.set_type(ast_foreach); break;
} }
if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_left_curve) if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_lcurve)
{ {
die(error_line,"expected \"(\""); die(error_line,"expected \"(\"");
return node; return node;
} }
// first expression // first expression
// foreach/forindex must have an iterator to loop through // foreach/forindex must have an iterator to loop through
if(++ptr>=tok_list_size || (tok_list[ptr].type!=tok_var && tok_list[ptr].type!=tok_identifier)) if(++ptr>=tok_list_size || (tok_list[ptr].type!=tok_var && tok_list[ptr].type!=tok_id))
{ {
die(error_line,"expected iterable value"); die(error_line,"expected iterable value");
return node; return node;
@ -1134,8 +1134,8 @@ nasal_ast nasal_parse::forei_loop()
die(error_line,"expected vector"); die(error_line,"expected vector");
return node; return node;
} }
node.add_child(calculation()); node.add_child(calc());
if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve) if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_rcurve)
{ {
die(error_line,"expected \")\""); die(error_line,"expected \")\"");
return node; return node;
@ -1151,7 +1151,7 @@ nasal_ast nasal_parse::new_iter_gen()
if(tok_list[ptr].type==tok_var) if(tok_list[ptr].type==tok_var)
{ {
node.set_type(ast_new_iter); node.set_type(ast_new_iter);
if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_identifier) if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_id)
{ {
die(error_line,"expected identifier"); die(error_line,"expected identifier");
return node; return node;
@ -1173,14 +1173,14 @@ nasal_ast nasal_parse::conditional()
{ {
nasal_ast node(tok_list[ptr].line,ast_conditional); nasal_ast node(tok_list[ptr].line,ast_conditional);
nasal_ast tmp(tok_list[ptr].line,ast_if); nasal_ast tmp(tok_list[ptr].line,ast_if);
if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_left_curve) if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_lcurve)
{ {
die(error_line,"expected \"(\""); die(error_line,"expected \"(\"");
return node; return node;
} }
++ptr; ++ptr;
tmp.add_child(calculation()); tmp.add_child(calc());
if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve) if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_rcurve)
{ {
die(error_line,"expected \")\""); die(error_line,"expected \")\"");
return node; return node;
@ -1189,19 +1189,20 @@ nasal_ast nasal_parse::conditional()
tmp.add_child(exprs_gen()); tmp.add_child(exprs_gen());
node.add_child(tmp); node.add_child(tmp);
// end of if-expression // end of if-expression
while(++ptr<tok_list_size && (tok_list[ptr].type==tok_elsif || (tok_list[ptr].type==tok_else && ptr+1<tok_list_size && tok_list[ptr+1].type==tok_if))) while(++ptr<tok_list_size &&
(tok_list[ptr].type==tok_elsif || (tok_list[ptr].type==tok_else && ptr+1<tok_list_size && tok_list[ptr+1].type==tok_if)))
{ {
if(tok_list[ptr].type==tok_else) if(tok_list[ptr].type==tok_else)
++ptr; ++ptr;
if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_left_curve) if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_lcurve)
{ {
die(error_line,"expected \"(\""); die(error_line,"expected \"(\"");
return node; return node;
} }
nasal_ast tmp(tok_list[ptr].line,ast_elsif); nasal_ast tmp(tok_list[ptr].line,ast_elsif);
++ptr; ++ptr;
tmp.add_child(calculation()); tmp.add_child(calc());
if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve) if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_rcurve)
{ {
die(error_line,"expected \")\""); die(error_line,"expected \")\"");
return node; return node;
@ -1242,9 +1243,9 @@ nasal_ast nasal_parse::return_expr()
if(++ptr<tok_list_size) if(++ptr<tok_list_size)
{ {
int type=tok_list[ptr].type; int type=tok_list[ptr].type;
if(type==tok_nil || type==tok_number || type==tok_string || type==tok_identifier || type==tok_func || if(type==tok_nil || type==tok_num || type==tok_str || type==tok_id || type==tok_func ||
type==tok_sub || type==tok_not || type==tok_left_curve || type==tok_left_bracket || type==tok_left_brace) type==tok_sub || type==tok_not || type==tok_lcurve || type==tok_lbracket || type==tok_lbrace)
node.add_child(calculation()); node.add_child(calc());
else else
--ptr; --ptr;
} }