Update
This commit is contained in:
parent
9e31e3d956
commit
64e314b539
|
@ -52,6 +52,7 @@ enum parse_token_type
|
||||||
__multi_id,
|
__multi_id,
|
||||||
__multi_scalar,
|
__multi_scalar,
|
||||||
__parameters,
|
__parameters,
|
||||||
|
__special_para,
|
||||||
__defult_parameter,
|
__defult_parameter,
|
||||||
__vector,__hash,
|
__vector,__hash,
|
||||||
__hash_member,
|
__hash_member,
|
||||||
|
@ -131,6 +132,7 @@ void print_parse_token(int type)
|
||||||
case __multi_id: context="identifiers"; break;
|
case __multi_id: context="identifiers"; break;
|
||||||
case __multi_scalar: context="scalars"; break;
|
case __multi_scalar: context="scalars"; break;
|
||||||
case __parameters: context="parameters"; break;
|
case __parameters: context="parameters"; break;
|
||||||
|
case __special_para: context="id:scalar"; break;
|
||||||
case __defult_parameter: context="para=scalar"; break;
|
case __defult_parameter: context="para=scalar"; break;
|
||||||
case __vector: context="vector"; break;
|
case __vector: context="vector"; break;
|
||||||
case __hash: context="hash"; break;
|
case __hash: context="hash"; break;
|
||||||
|
@ -169,6 +171,9 @@ enum parse_error_type
|
||||||
parameter_lack_part, // parameter lack a ')' or identifier
|
parameter_lack_part, // parameter lack a ')' or identifier
|
||||||
parameter_lack_curve, // parameter lack a ',' or ')'
|
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_hash_lack_id, // lack identifier when calling a hash
|
||||||
call_vector_lack_bracket, // lack ']' when calling a vector
|
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<<error_info_head<<line<<": expect a \')\' or identifier here."<<std::endl;break;
|
std::cout<<error_info_head<<line<<": expect a \')\' or identifier here."<<std::endl;break;
|
||||||
case parameter_lack_curve:
|
case parameter_lack_curve:
|
||||||
std::cout<<error_info_head<<line<<": expect a \')\' or \',\' here."<<std::endl;break;
|
std::cout<<error_info_head<<line<<": expect a \')\' or \',\' here."<<std::endl;break;
|
||||||
|
case special_call_lack_id:
|
||||||
|
std::cout<<error_info_head<<line<<": expect an identifier here but get \'";
|
||||||
|
print_parse_token(error_token_type);
|
||||||
|
std::cout<<"\' ."<<std::endl;
|
||||||
|
break;
|
||||||
|
case special_call_lack_colon:
|
||||||
|
std::cout<<error_info_head<<line<<": expect an \':\' here but get \'";
|
||||||
|
print_parse_token(error_token_type);
|
||||||
|
std::cout<<"\' ."<<std::endl;
|
||||||
|
break;
|
||||||
|
case call_func_lack_comma:
|
||||||
|
std::cout<<error_info_head<<line<<": expect a \',\' here but get \'";
|
||||||
|
print_parse_token(error_token_type);
|
||||||
|
std::cout<<"\' ."<<std::endl;
|
||||||
|
break;
|
||||||
case call_hash_lack_id:
|
case call_hash_lack_id:
|
||||||
std::cout<<error_info_head<<line<<": expect an identifier after \'.\' ."<<std::endl;break;
|
std::cout<<error_info_head<<line<<": expect an identifier after \'.\' ."<<std::endl;break;
|
||||||
case call_vector_lack_bracket:
|
case call_vector_lack_bracket:
|
||||||
|
|
|
@ -26,6 +26,7 @@ class nasal_parse
|
||||||
abstract_syntax_tree calculation();
|
abstract_syntax_tree calculation();
|
||||||
abstract_syntax_tree and_calculation();
|
abstract_syntax_tree and_calculation();
|
||||||
abstract_syntax_tree or_calculation();
|
abstract_syntax_tree or_calculation();
|
||||||
|
abstract_syntax_tree cmp_calculation();
|
||||||
abstract_syntax_tree additive_calculation();
|
abstract_syntax_tree additive_calculation();
|
||||||
abstract_syntax_tree multive_calculation();
|
abstract_syntax_tree multive_calculation();
|
||||||
abstract_syntax_tree assign_calculation();
|
abstract_syntax_tree assign_calculation();
|
||||||
|
@ -349,9 +350,32 @@ abstract_syntax_tree nasal_parse::or_calculation()
|
||||||
{
|
{
|
||||||
abstract_syntax_tree calc_node;
|
abstract_syntax_tree calc_node;
|
||||||
abstract_syntax_tree tmp_node;
|
abstract_syntax_tree tmp_node;
|
||||||
calc_node=additive_calculation();
|
calc_node=cmp_calculation();
|
||||||
this->get_token();
|
this->get_token();
|
||||||
while(this_token.type==__or_operator)
|
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_clear();
|
||||||
tmp_node.set_node_line(this_token.line);
|
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;
|
abstract_syntax_tree call_func_node;
|
||||||
call_func_node.set_node_line(this_token.line);
|
call_func_node.set_node_line(this_token.line);
|
||||||
call_func_node.set_node_type(__call_function);
|
call_func_node.set_node_type(__call_function);
|
||||||
|
this->get_token();
|
||||||
|
if(this_token.type!=__right_curve)
|
||||||
// unfinished
|
{
|
||||||
|
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)
|
else if(this_token.type==__left_bracket)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue