diff --git a/nasal_ast.h b/nasal_ast.h index fe381fa..0645345 100644 --- a/nasal_ast.h +++ b/nasal_ast.h @@ -14,7 +14,7 @@ enum ast_node ast_func, // func keyword ast_hash, // hash, basic value type ast_vec, // vector, basic value type - ast_hashmember, // elements in hashmap + ast_pair, // pair of key and value in hashmap ast_call, // mark a sub-tree of calling an identifier ast_callh, // id.name ast_callv, // id[index] @@ -49,7 +49,7 @@ enum ast_node ast_forindex, // forindex keyword ast_foreach, // foreach keyword ast_while, // while - ast_new_iter, // iterator, used in forindex/foreach + ast_iter, // iterator, used in forindex/foreach ast_conditional, // mark a sub-tree of conditional expression ast_if, // if keyword ast_elsif, // elsif keyword diff --git a/nasal_codegen.h b/nasal_codegen.h index 4e55786..d6708e9 100644 --- a/nasal_codegen.h +++ b/nasal_codegen.h @@ -294,7 +294,7 @@ void nasal_codegen::find_symbol(const nasal_ast& node) find_symbol(node[1]); } // find iterator(foreach, forindex), check - else if(node.type()==ast_new_iter) + else if(node.type()==ast_iter) add_sym(node[0].str()); // check children else @@ -528,7 +528,7 @@ void nasal_codegen::call_func(const nasal_ast& ast) { if(!ast.size()) gen(op_callfv,0,ast.line()); - else if(ast[0].type()==ast_hashmember) + else if(ast[0].type()==ast_pair) { hash_gen(ast); gen(op_callfh,0,ast.line()); @@ -847,7 +847,7 @@ void nasal_codegen::forindex_gen(const nasal_ast& ast) gen(op_cnt,0,ast[1].line()); int ptr=code.size(); gen(op_findex,0,ast.line()); - if(ast[0].type()==ast_new_iter) + if(ast[0].type()==ast_iter) { const std::string& str=ast[0][0].str(); local.empty()? @@ -875,7 +875,7 @@ void nasal_codegen::foreach_gen(const nasal_ast& ast) gen(op_cnt,0,ast.line()); int ptr=code.size(); gen(op_feach,0,ast.line()); - if(ast[0].type()==ast_new_iter) + if(ast[0].type()==ast_iter) { const std::string& str=ast[0][0].str(); local.empty()? diff --git a/nasal_err.h b/nasal_err.h index c6edf71..d935e6e 100644 --- a/nasal_err.h +++ b/nasal_err.h @@ -67,11 +67,9 @@ public: { ++error; if(!line) - { std::cerr<<"["< files; - bool check_import(const nasal_ast&); - bool check_exist(const std::string&); - void linker(nasal_ast&,nasal_ast&&); + bool check_import(const nasal_ast&); + bool check_exist(const std::string&); + void linker(nasal_ast&,nasal_ast&&); nasal_ast file_import(nasal_ast&); nasal_ast load(nasal_ast&,uint16_t); public: @@ -22,9 +22,9 @@ bool nasal_import::check_import(const nasal_ast& node) /* only this kind of node can be recognized as 'import': call - id:import - call_func - string:'filename' + |_id:import + |_call_func + |_string:'filename' */ return ( node.type()==ast_call && diff --git a/nasal_opt.h b/nasal_opt.h index 037c3fe..afe7d06 100644 --- a/nasal_opt.h +++ b/nasal_opt.h @@ -20,14 +20,14 @@ void calc_const_num(nasal_ast& root) double res; switch(root.type()) { - case ast_add:res=vec[0].num()+vec[1].num();break; - case ast_sub:res=vec[0].num()-vec[1].num();break; - case ast_mult:res=vec[0].num()*vec[1].num();break; - case ast_div:res=vec[0].num()/vec[1].num();break; - case ast_less:res=vec[0].num()vec[1].num();break; - case ast_geq:res=vec[0].num()>=vec[1].num();break; + case ast_add: res=vec[0].num()+vec[1].num(); break; + case ast_sub: res=vec[0].num()-vec[1].num(); break; + case ast_mult:res=vec[0].num()*vec[1].num(); break; + case ast_div: res=vec[0].num()/vec[1].num(); break; + case ast_less:res=vec[0].num()vec[1].num(); break; + case ast_geq: res=vec[0].num()>=vec[1].num();break; } if(std::isinf(res) || std::isnan(res)) // inf and nan will cause number hashmap error in codegen return; diff --git a/nasal_parse.h b/nasal_parse.h index 32486b1..cc24262 100644 --- a/nasal_parse.h +++ b/nasal_parse.h @@ -63,7 +63,7 @@ private: nasal_ast id(); nasal_ast vec(); nasal_ast hash(); - nasal_ast hmem(); + nasal_ast pair(); nasal_ast func(); nasal_ast args(); nasal_ast lcurve_expr(); @@ -305,7 +305,7 @@ nasal_ast nasal_parse::hash() match(tok_lbrace); while(tokens[ptr].type!=tok_rbrace) { - node.add(hmem()); + node.add(pair()); if(tokens[ptr].type==tok_comma) match(tok_comma); else if(tokens[ptr].type==tok_id || tokens[ptr].type==tok_str)// first set of hashmember @@ -316,9 +316,9 @@ nasal_ast nasal_parse::hash() match(tok_rbrace,"expected \'}\' when generating hash"); return node; } -nasal_ast nasal_parse::hmem() +nasal_ast nasal_parse::pair() { - nasal_ast node(tokens[ptr].line,ast_hashmember); + nasal_ast node(tokens[ptr].line,ast_pair); if(tokens[ptr].type==tok_id) { node.add(id()); @@ -715,7 +715,7 @@ nasal_ast nasal_parse::callf() match(tok_lcurve); while(tokens[ptr].type!=tok_rcurve) { - node.add(special_call?hmem():calc()); + node.add(special_call?pair():calc()); if(tokens[ptr].type==tok_comma) match(tok_comma); else if(tokens[ptr].type==tok_eof) @@ -935,7 +935,7 @@ nasal_ast nasal_parse::iter_gen() if(tokens[ptr].type==tok_var) { match(tok_var); - node.set_type(ast_new_iter); + node.set_type(ast_iter); node.add(id()); match(tok_id); }