Fixed bugs in calculation & call_func

This commit is contained in:
Valk Richard Li 2019-10-22 22:50:59 +08:00 committed by GitHub
parent d595d5f26f
commit 5b2c10ca46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 20 deletions

View File

@ -1220,9 +1220,7 @@ abstract_syntax_tree nasal_parser::mul_div_operator_expr()
node.set_var_string(this_token.content); node.set_var_string(this_token.content);
break; break;
case __id: case __id:
node.set_node_type(__id); node=identifier_call_expr();
node.set_var_name(this_token.content);
node.add_child(identifier_call_expr());
break; break;
case __left_curve: case __left_curve:
parse.push(this_token); parse.push(this_token);
@ -1365,7 +1363,7 @@ abstract_syntax_tree nasal_parser::calculation_expr()
} }
else else
parse.push(this_token); parse.push(this_token);
temp=mul_div_operator_expr(); node=mul_div_operator_expr();
while(1) while(1)
{ {
get_token(); get_token();
@ -1382,19 +1380,19 @@ abstract_syntax_tree nasal_parser::calculation_expr()
case __add_operator: case __add_operator:
case __sub_operator: case __sub_operator:
case __link_operator: case __link_operator:
node.set_clear(); temp.set_clear();
node.set_node_type(this_token.type); temp.set_node_type(this_token.type);
node.add_child(temp); temp.add_child(node);
break; break;
case __semi:parse.push(this_token);return temp;break; case __semi:parse.push(this_token);return node;break;
case __unknown_operator: case __unknown_operator:
++error; ++error;
std::cout<<">>[Error] line "<<this_token.line<<": __unknown_operator '"<<this_token.content<<"'."<<std::endl; std::cout<<">>[Error] line "<<this_token.line<<": __unknown_operator '"<<this_token.content<<"'."<<std::endl;
return node;break; return node;break;
default:parse.push(this_token);return node;break; default:parse.push(this_token);return node;break;
} }
node.add_child(mul_div_operator_expr()); temp.add_child(mul_div_operator_expr());
temp=node; node=temp;
} }
return node; return node;
} }
@ -1539,11 +1537,12 @@ abstract_syntax_tree nasal_parser::parameter_function_expr()
abstract_syntax_tree nasal_parser::call_function_expr() abstract_syntax_tree nasal_parser::call_function_expr()
{ {
abstract_syntax_tree node; abstract_syntax_tree node;
abstract_syntax_tree temp;
node.set_node_type(__call_function); node.set_node_type(__call_function);
get_token();
while(this_token.type!=__right_curve) while(this_token.type!=__right_curve)
{ {
abstract_syntax_tree temp; get_token();
temp.set_clear();
switch(this_token.type) switch(this_token.type)
{ {
case __left_curve: case __left_curve:
@ -1615,8 +1614,12 @@ abstract_syntax_tree nasal_parser::call_function_expr()
std::cout<<">>[Error] line "<<this_token.line<<": expect a ',' after parameter or ')' to end the call."<<std::endl; std::cout<<">>[Error] line "<<this_token.line<<": expect a ',' after parameter or ')' to end the call."<<std::endl;
return node; return node;
} }
else if(this_token.type==__comma) if(this_token.type==__comma)
{
get_token(); get_token();
if(this_token.type!=__right_curve)
parse.push(this_token);
}
} }
get_token(); get_token();
switch(this_token.type) switch(this_token.type)
@ -1651,28 +1654,26 @@ abstract_syntax_tree nasal_parser::call_hash_expr()
abstract_syntax_tree nasal_parser::identifier_call_expr() abstract_syntax_tree nasal_parser::identifier_call_expr()
{ {
abstract_syntax_tree node; abstract_syntax_tree node;
node.set_var_name(this_token.content); std::string temp_name=this_token.content;
// __id has been checked // __id has been checked
get_token(); get_token();
switch(this_token.type) switch(this_token.type)
{ {
case __left_bracket: case __left_bracket:
node.set_node_type(__list_search); node=call_list_expr();
node.add_child(call_list_expr());
break; break;
case __left_curve: case __left_curve:
node.set_node_type(__call_function); node=call_function_expr();
node.add_child(call_function_expr());
break; break;
case __dot: case __dot:
node.set_node_type(__hash_search); node=call_hash_expr();
node.add_child(call_hash_expr());
break; break;
default: default:
node.set_node_type(__id); node.set_node_type(__id);
parse.push(this_token); parse.push(this_token);
break; break;
} }
node.set_var_name(temp_name);
abstract_syntax_tree temp; abstract_syntax_tree temp;
get_token(); get_token();
switch(this_token.type) switch(this_token.type)