diff --git a/nasal_ast.h b/nasal_ast.h index 7bccfff..bb474e3 100644 --- a/nasal_ast.h +++ b/nasal_ast.h @@ -4,14 +4,14 @@ enum ast_node { 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_args,ast_default_arg,ast_dynamic_id, ast_and,ast_or, 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_less_than,ast_less_equal, - ast_greater_than,ast_greater_equal, + ast_less,ast_leq, + ast_grt,ast_geq, ast_add,ast_sub,ast_mult,ast_div,ast_link, ast_unary_sub,ast_unary_not, ast_trinocular, @@ -22,7 +22,7 @@ enum ast_node ast_continue,ast_break,ast_return }; -std::string ast_str(int type) +std::string ast_name(int type) { switch(type) { @@ -30,12 +30,12 @@ std::string ast_str(int type) case ast_root: return "root"; case ast_block: return "block"; case ast_nil: return "nil"; - case ast_number: return "number"; - case ast_string: return "string"; - case ast_identifier: return "id"; - case ast_function: return "function"; + case ast_num: return "number"; + case ast_str: return "string"; + case ast_id: return "id"; + case ast_func: return "function"; case ast_hash: return "hash"; - case ast_vector: return "vector"; + case ast_vec: return "vector"; case ast_hashmember: return "hashmember"; case ast_call: return "call"; case ast_call_hash: return "callh"; @@ -55,10 +55,10 @@ std::string ast_str(int type) case ast_link_equal: return "~="; case ast_cmp_equal: return "=="; case ast_cmp_not_equal:return "!="; - case ast_less_than: return "<"; - case ast_less_equal: return "<="; - case ast_greater_than: return ">"; - case ast_greater_equal:return ">="; + case ast_less: return "<"; + case ast_leq: return "<="; + case ast_grt: return ">"; + case ast_geq: return ">="; case ast_add: return "+"; case ast_sub: return "-"; case ast_mult: return "*"; @@ -216,11 +216,11 @@ void nasal_ast::print_ast(int depth) { std::string indentation=""; for(int i=0;itype); + indentation+=ast_name(this->type); std::cout<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<<":"<str; - else if(this->type==ast_number) + else if(this->type==ast_num) std::cout<<":"<num; std::cout<<'\n'; int child_size=this->children.size(); diff --git a/nasal_codegen.h b/nasal_codegen.h index 6ee6ba6..87742e2 100644 --- a/nasal_codegen.h +++ b/nasal_codegen.h @@ -278,7 +278,7 @@ void nasal_codegen::function_gen(nasal_ast& ast) for(int i=0;i" ,tok_greater_than }, - {">=" ,tok_greater_equal}, - {NULL ,-1 } + {"for" ,tok_for }, + {"forindex",tok_forindex }, + {"foreach" ,tok_foreach }, + {"while" ,tok_while }, + {"var" ,tok_var }, + {"func" ,tok_func }, + {"break" ,tok_break }, + {"continue",tok_continue }, + {"return" ,tok_ret }, + {"if" ,tok_if }, + {"elsif" ,tok_elsif }, + {"else" ,tok_else }, + {"nil" ,tok_nil }, + {"(" ,tok_lcurve }, + {")" ,tok_rcurve }, + {"[" ,tok_lbracket }, + {"]" ,tok_rbracket }, + {"{" ,tok_lbrace }, + {"}" ,tok_rbrace }, + {";" ,tok_semi }, + {"and" ,tok_and }, + {"or" ,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_eq }, + {"+=" ,tok_addeq }, + {"-=" ,tok_subeq }, + {"*=" ,tok_multeq }, + {"/=" ,tok_diveq }, + {"~=" ,tok_lnkeq }, + {"==" ,tok_cmpeq }, + {"!=" ,tok_neq }, + {"<" ,tok_less }, + {"<=" ,tok_leq }, + {">" ,tok_grt }, + {">=" ,tok_geq }, + {NULL ,-1 } }; struct token @@ -322,19 +322,19 @@ void nasal_lexer::scanner() token_str=identifier_gen(); token new_token(line,get_token_type(token_str),token_str); if(!new_token.type) - new_token.type=tok_identifier; + new_token.type=tok_id; token_list.push_back(new_token); } else if(IS_DIGIT(res[ptr])) { 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); } else if(IS_STRING(res[ptr])) { 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); } else if(IS_SINGLE_OPERATOR(res[ptr])) diff --git a/nasal_parse.h b/nasal_parse.h index 901c3eb..ceb828f 100644 --- a/nasal_parse.h +++ b/nasal_parse.h @@ -39,7 +39,7 @@ class nasal_parse { #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: int tok_list_size; int ptr; @@ -50,7 +50,7 @@ private: int in_loop; // count when generating loop block,used to check break/continue-expression void reset(); void die(int,std::string); - bool check_multi_definition(); + bool check_multi_def(); bool check_multi_scalar(); bool check_function_end(nasal_ast&); bool check_special_call(); @@ -58,17 +58,17 @@ private: void check_memory_reachable(nasal_ast&); nasal_ast null_node_gen(); nasal_ast nil_gen(); - nasal_ast number_gen(); - nasal_ast string_gen(); + nasal_ast num_gen(); + nasal_ast str_gen(); nasal_ast id_gen(); - nasal_ast vector_gen(); + nasal_ast vec_gen(); nasal_ast hash_gen(); - nasal_ast hash_member_gen(); + nasal_ast hmem_gen(); // hash member nasal_ast func_gen(); - nasal_ast args_list_gen(); + nasal_ast args_gen(); nasal_ast expr(); nasal_ast exprs_gen(); - nasal_ast calculation(); + nasal_ast calc(); nasal_ast or_expr(); nasal_ast and_expr(); nasal_ast cmp_expr(); @@ -78,7 +78,7 @@ private: nasal_ast scalar(); nasal_ast call_scalar(); nasal_ast call_hash(); - nasal_ast call_vector(); + nasal_ast call_vec(); nasal_ast call_func(); nasal_ast subvec(); nasal_ast definition(); @@ -108,9 +108,9 @@ int nasal_parse::get_error() return error; } -void nasal_parse::set_toklist(std::vector& lex_token) +void nasal_parse::set_toklist(std::vector& toks) { - tok_list=lex_token; + tok_list=toks; tok_list_size=tok_list.size(); return; } @@ -165,7 +165,7 @@ void nasal_parse::die(int line,std::string info) return; } -bool nasal_parse::check_multi_definition() +bool nasal_parse::check_multi_def() { return ptr+11 || tmp_node.get_children()[0].get_type()==ast_subvec)) - die(tmp_node.get_line(),"cannot get the memory in temporary sliced vector"); + nasal_ast& tmp=node.get_children()[i]; + if(tmp.get_type()==ast_call_func) + die(tmp.get_line(),"cannot get the memory of function-returned value"); + if(tmp.get_type()==ast_call_vec && (tmp.get_children().size()>1 || tmp.get_children()[0].get_type()==ast_subvec)) + 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"); return; } @@ -281,42 +281,42 @@ nasal_ast nasal_parse::nil_gen() 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)); 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); return node; } 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); 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; - while(ptr=tok_list_size) break; if(tok_list[ptr].type==tok_comma) ++ptr; - else if(tok_list[ptr].type!=tok_right_bracket) + else if(tok_list[ptr].type!=tok_rbracket) 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 \"]\""); return node; } @@ -324,50 +324,50 @@ nasal_ast nasal_parse::hash_gen() { nasal_ast node(tok_list[ptr].line,ast_hash); ++ptr; - while (ptr=tok_list_size) break; if(tok_list[ptr].type==tok_comma) ++ptr; - else if(tok_list[ptr].type!=tok_right_brace) + else if(tok_list[ptr].type!=tok_rbrace) 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 \"}\""); 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"); nasal_ast nullnode; return nullnode; } 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) { die(error_line,"expected \":\""); return node; } ++ptr; - node.add_child(calculation()); + node.add_child(calc()); return node; } 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) { die(error_line,"expected argument(s)/expression block"); 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; } else @@ -378,27 +378,27 @@ nasal_ast nasal_parse::func_gen() node.add_child(exprs_gen()); return node; } -nasal_ast nasal_parse::args_list_gen() +nasal_ast nasal_parse::args_gen() { nasal_ast node(tok_list[ptr].line,ast_args); ++ptr; - while(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 \")\""); return node; @@ -432,7 +432,7 @@ nasal_ast nasal_parse::args_list_gen() { 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_dynamic_id: args_format+="val...";break; } @@ -457,7 +457,7 @@ nasal_ast nasal_parse::args_list_gen() switch(node.get_children()[i].get_type()) { 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; } 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; if((tok_type==tok_break || tok_type==tok_continue) && !in_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"); switch(tok_type) { case tok_nil: - case tok_number: - case tok_string: - case tok_identifier: + case tok_num: + case tok_str: + case tok_id: case tok_func: - case tok_left_bracket: - case tok_left_brace: + case tok_lbracket: + case tok_lbrace: case tok_sub: - case tok_not: node=calculation(); break; + case tok_not: node=calc(); 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_forindex: case tok_foreach: @@ -495,7 +495,7 @@ nasal_ast nasal_parse::expr() case tok_if: node=conditional(); break; case tok_continue: node=continue_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; default: die(error_line,"error token \""+tok_list[ptr].str+"\"");break; } @@ -510,10 +510,10 @@ nasal_ast nasal_parse::exprs_gen() return nullnode; } 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; - while(ptr=tok_list_size) @@ -523,14 +523,14 @@ nasal_ast nasal_parse::exprs_gen() else if(need_semi_check(node.get_children().back())) { // 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 \";\""); 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=""; while(left_brace_line) @@ -548,7 +548,7 @@ nasal_ast nasal_parse::exprs_gen() } return node; } -nasal_ast nasal_parse::calculation() +nasal_ast nasal_parse::calc() { nasal_ast node; if(ptr>=tok_list_size) @@ -564,25 +564,25 @@ nasal_ast nasal_parse::calculation() nasal_ast tmp(tok_list[ptr].line,ast_trinocular); tmp.add_child(node); ++ptr; - tmp.add_child(calculation()); + tmp.add_child(calc()); if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_colon) { die(error_line,"expected \":\""); return node; } ++ptr; - tmp.add_child(calculation()); + tmp.add_child(calc()); node=tmp; } - else 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 \")\""); } else @@ -780,8 +780,8 @@ nasal_ast nasal_parse::call_scalar() nasal_ast node; switch(tok_list[ptr].type) { - case tok_left_curve: node=call_func(); break; - case tok_left_bracket: node=call_vector(); break; + case tok_lcurve: node=call_func(); break; + case tok_lbracket: node=call_vec(); break; case tok_dot: node=call_hash(); break; } return node; @@ -789,27 +789,27 @@ nasal_ast nasal_parse::call_scalar() nasal_ast nasal_parse::call_hash() { nasal_ast node(tok_list[ptr].line,ast_call_hash); - if(++ptr=tok_list_size) break; else if(tok_list[ptr].type==tok_comma) ++ptr; - else if(tok_list[ptr].type!=tok_right_bracket) + else if(tok_list[ptr].type!=tok_rbracket) 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 \"]\""); return node; } @@ -818,17 +818,17 @@ nasal_ast nasal_parse::call_func() nasal_ast node(tok_list[ptr].line,ast_call_func); bool special_call=check_special_call(); ++ptr; - while(ptr=tok_list_size) break; else if(tok_list[ptr].type==tok_comma) ++ptr; - else if(tok_list[ptr].type!=tok_right_curve) + else if(tok_list[ptr].type!=tok_rcurve) 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 \")\""); return node; } @@ -840,7 +840,7 @@ nasal_ast nasal_parse::subvec() --ptr; node=nil_gen(); } - else node=calculation(); + else node=calc(); ++ptr; 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"); return node; @@ -890,11 +890,11 @@ nasal_ast nasal_parse::definition() die(error_line,"expected scalar"); return node; } - if(tok_list[ptr].type==tok_left_curve) - node.add_child(check_multi_scalar()?multi_scalar(false):calculation()); + if(tok_list[ptr].type==tok_lcurve) + node.add_child(check_multi_scalar()?multi_scalar(false):calc()); else - node.add_child(calculation()); - if(node.get_children()[0].get_type()==ast_identifier && node.get_children()[1].get_type()==ast_multi_scalar) + node.add_child(calc()); + 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"); 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()) @@ -905,11 +905,11 @@ nasal_ast nasal_parse::var_incurve_def() { nasal_ast node; 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(); 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 \")\""); return node; } @@ -920,14 +920,14 @@ nasal_ast nasal_parse::var_outcurve_def() node=multi_id(); 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 \")\""); return node; } nasal_ast nasal_parse::multi_id() { 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"); 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 nasal_ast node(tok_list[ptr].line,ast_multi_scalar); ++ptr; - while(ptr=tok_list_size) break; if(tok_list[ptr].type==tok_comma) ++ptr; - else if(tok_list[ptr].type!=tok_right_curve) + else if(tok_list[ptr].type!=tok_rcurve) 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 \")\""); return node; } @@ -972,7 +972,7 @@ nasal_ast nasal_parse::multi_assgin() { nasal_ast node(tok_list[ptr].line,ast_multi_assign); 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 \"=\""); return node; @@ -982,10 +982,10 @@ nasal_ast nasal_parse::multi_assgin() die(error_line,"expected value list"); return node; } - if(tok_list[ptr].type==tok_left_curve) - node.add_child(check_multi_scalar()?multi_scalar(false):calculation()); + if(tok_list[ptr].type==tok_lcurve) + node.add_child(check_multi_scalar()?multi_scalar(false):calc()); else - node.add_child(calculation()); + node.add_child(calc()); if(node.get_children()[1].get_type()==ast_multi_scalar && 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"); @@ -1008,14 +1008,14 @@ nasal_ast nasal_parse::loop() nasal_ast nasal_parse::while_loop() { 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 \"(\""); return node; } ++ptr; - node.add_child(calculation()); - if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve) + node.add_child(calc()); + if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_rcurve) { die(error_line,"expected \")\""); return node; @@ -1027,7 +1027,7 @@ nasal_ast nasal_parse::while_loop() nasal_ast nasal_parse::for_loop() { 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 \"(\""); return node; @@ -1045,18 +1045,18 @@ nasal_ast nasal_parse::for_loop() } else if(tok_list[ptr].type==tok_var) node.add_child(definition()); - else if(tok_list[ptr].type==tok_left_curve) + else if(tok_list[ptr].type==tok_lcurve) node.add_child( - check_multi_definition()? + check_multi_def()? definition(): ( check_multi_scalar()? multi_assgin(): - calculation() + calc() ) ); else - node.add_child(calculation()); + node.add_child(calc()); if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_semi) { die(error_line,"expected \";\""); @@ -1074,7 +1074,7 @@ nasal_ast nasal_parse::for_loop() --ptr; } else - node.add_child(calculation()); + node.add_child(calc()); if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_semi) { die(error_line,"expected \";\""); @@ -1086,15 +1086,15 @@ nasal_ast nasal_parse::for_loop() die(error_line,"expected calculation"); return node; } - if(tok_list[ptr].type==tok_right_curve) + if(tok_list[ptr].type==tok_rcurve) { node.add_child(null_node_gen()); --ptr; } else - node.add_child(calculation()); + node.add_child(calc()); ++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 \")\""); return node; @@ -1111,14 +1111,14 @@ nasal_ast nasal_parse::forei_loop() case tok_forindex: node.set_type(ast_forindex);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 \"(\""); return node; } // first expression // 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"); return node; @@ -1134,8 +1134,8 @@ nasal_ast nasal_parse::forei_loop() die(error_line,"expected vector"); return node; } - node.add_child(calculation()); - if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve) + node.add_child(calc()); + if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_rcurve) { die(error_line,"expected \")\""); return node; @@ -1151,7 +1151,7 @@ nasal_ast nasal_parse::new_iter_gen() if(tok_list[ptr].type==tok_var) { 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"); return node; @@ -1173,14 +1173,14 @@ nasal_ast nasal_parse::conditional() { nasal_ast node(tok_list[ptr].line,ast_conditional); 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 \"(\""); return node; } ++ptr; - tmp.add_child(calculation()); - if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve) + tmp.add_child(calc()); + if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_rcurve) { die(error_line,"expected \")\""); return node; @@ -1189,19 +1189,20 @@ nasal_ast nasal_parse::conditional() tmp.add_child(exprs_gen()); node.add_child(tmp); // end of if-expression - while(++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 \"(\""); return node; } nasal_ast tmp(tok_list[ptr].line,ast_elsif); ++ptr; - tmp.add_child(calculation()); - if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve) + tmp.add_child(calc()); + if(++ptr>=tok_list_size || tok_list[ptr].type!=tok_rcurve) { die(error_line,"expected \")\""); return node; @@ -1242,9 +1243,9 @@ nasal_ast nasal_parse::return_expr() if(++ptr