diff --git a/version2.0/nasal_enum.h b/version2.0/nasal_enum.h index 55ced29..f8f70f4 100644 --- a/version2.0/nasal_enum.h +++ b/version2.0/nasal_enum.h @@ -52,6 +52,7 @@ enum parse_token_type __multi_id, __multi_scalar, __parameters, + __special_para, __defult_parameter, __vector,__hash, __hash_member, @@ -131,6 +132,7 @@ void print_parse_token(int type) case __multi_id: context="identifiers"; break; case __multi_scalar: context="scalars"; break; case __parameters: context="parameters"; break; + case __special_para: context="id:scalar"; break; case __defult_parameter: context="para=scalar"; break; case __vector: context="vector"; break; case __hash: context="hash"; break; @@ -169,6 +171,9 @@ enum parse_error_type parameter_lack_part, // parameter lack a ')' or identifier parameter_lack_curve, // parameter lack a ',' or ')' + special_call_lack_id, + special_call_lack_colon, + call_func_lack_comma, call_hash_lack_id, // lack identifier when calling a hash call_vector_lack_bracket, // lack ']' when calling a vector @@ -232,6 +237,21 @@ void print_parse_error(int error_type,int line,int error_token_type=__stack_end) std::cout<get_token(); while(this_token.type==__or_operator) + { + tmp_node.set_clear(); + tmp_node.set_node_line(this_token.line); + tmp_node.set_node_type(this_token.type); + tmp_node.add_children(calc_node); + tmp_node.add_children(cmp_calculation()); + calc_node=tmp_node; + this->get_token(); + } + this->push_token(); + return calc_node; +} + +abstract_syntax_tree nasal_parse::cmp_calculation() +{ + abstract_syntax_tree calc_node; + abstract_syntax_tree tmp_node; + calc_node=additive_calculation(); + this->get_token(); + while((this_token.type==__cmp_equal) || (this_token.type==__cmp_not_equal) || + (this_token.type==__cmp_less) || (this_token.type==__cmp_more) || + (this_token.type==__cmp_less_or_equal) || (this_token.type==__cmp_more_or_equal) + ) { tmp_node.set_clear(); tmp_node.set_node_line(this_token.line); @@ -519,9 +543,85 @@ abstract_syntax_tree nasal_parse::scalar_generate() abstract_syntax_tree call_func_node; call_func_node.set_node_line(this_token.line); call_func_node.set_node_type(__call_function); - - - // unfinished + this->get_token(); + if(this_token.type!=__right_curve) + { + bool scalar_para=true; + if(this_token.type==__id) + { + this->get_token(); + if(this_token.type==__colon) + { + scalar_para=false; + this->push_token(); + this->push_token(); + while(this_token.type!=__right_curve) + { + abstract_syntax_tree special_para_node; + abstract_syntax_tree id_node; + this->get_token(); + special_para_node.set_node_line(this_token.line); + special_para_node.set_node_type(__special_para); + if(this_token.type!=__id) + { + ++error; + print_parse_error(special_call_lack_id,this_token.line,this_token.type); + break; + } + id_node.set_node_line(this_token.line); + id_node.set_node_type(__id); + id_node.set_var_name(this_token.str); + special_para_node.add_children(id_node); + this->get_token(); + if(this_token.type!=__colon) + { + ++error; + print_parse_error(special_call_lack_colon,this_token.line,this_token.type); + break; + } + special_para_node.add_children(calculation()); + call_func_node.add_children(special_para_node); + this->get_token(); + if((this_token.type!=__comma) && (this_token.type!=__right_curve)) + { + ++error; + print_parse_error(call_func_lack_comma,this_token.line,this_token.type); + break; + } + if(this_token.type==__comma) + { + this->get_token(); + if(this_token.type!=__right_curve) + this->push_token(); + } + } + } + else + { + this->push_token(); + this->push_token(); + } + } + if(scalar_para) + while(this_token.type!=__right_curve) + { + call_func_node.add_children(calculation()); + this->get_token(); + if((this_token.type!=__comma) && (this_token.type!=__right_curve)) + { + ++error; + print_parse_error(call_func_lack_comma,this_token.line,this_token.type); + break; + } + if(this_token.type==__comma) + { + this->get_token(); + if(this_token.type!=__right_curve) + this->push_token(); + } + } + } + scalar_node.add_children(call_func_node); } else if(this_token.type==__left_bracket) {