Fixed a deadly bug.
This commit is contained in:
parent
f6a6ea4eb1
commit
504b9fe140
|
@ -700,13 +700,7 @@ void abstract_syntax_tree::run_root()
|
||||||
else if(i->type==__equal || i->type==__add_equal || i->type==__sub_equal || i->type==__mul_equal || i->type==__div_equal || i->type==__link_equal)
|
else if(i->type==__equal || i->type==__add_equal || i->type==__sub_equal || i->type==__mul_equal || i->type==__div_equal || i->type==__link_equal)
|
||||||
i->assignment();
|
i->assignment();
|
||||||
else if(i->type==__add_operator || i->type==__sub_operator || i->type==__mul_operator || i->type==__div_operator || i->type==__link_operator || i->type==__or_operator || i->type==__and_operator || i->type==__nor_operator)
|
else if(i->type==__add_operator || i->type==__sub_operator || i->type==__mul_operator || i->type==__div_operator || i->type==__link_operator || i->type==__or_operator || i->type==__and_operator || i->type==__nor_operator)
|
||||||
{
|
|
||||||
var t=i->calculation();
|
var t=i->calculation();
|
||||||
if(t.get_type()==__var_number)
|
|
||||||
std::cout<<t.get_number()<<std::endl;
|
|
||||||
else if(t.get_type()==__var_string)
|
|
||||||
std::cout<<t.get_string()<<std::endl;
|
|
||||||
}
|
|
||||||
else if(i->type==__number || i->type==__string)
|
else if(i->type==__number || i->type==__string)
|
||||||
;
|
;
|
||||||
else if(i->type==__id)
|
else if(i->type==__id)
|
||||||
|
@ -757,7 +751,6 @@ int abstract_syntax_tree::run_loop()
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int ret=0;
|
int ret=0;
|
||||||
scope.add_new_local_scope();
|
|
||||||
|
|
||||||
abstract_syntax_tree condition=children.front();
|
abstract_syntax_tree condition=children.front();
|
||||||
abstract_syntax_tree blk=children.back();
|
abstract_syntax_tree blk=children.back();
|
||||||
|
@ -774,7 +767,6 @@ int abstract_syntax_tree::run_loop()
|
||||||
if(exit_type!=__process_exited_successfully)
|
if(exit_type!=__process_exited_successfully)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
scope.pop_last_local_scope();
|
|
||||||
--recursion_depth;
|
--recursion_depth;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -789,8 +781,6 @@ int abstract_syntax_tree::run_ifelse()
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int ret=0;
|
int ret=0;
|
||||||
scope.add_new_local_scope();
|
|
||||||
|
|
||||||
for(std::list<abstract_syntax_tree>::iterator i=children.begin();i!=children.end();++i)
|
for(std::list<abstract_syntax_tree>::iterator i=children.begin();i!=children.end();++i)
|
||||||
{
|
{
|
||||||
if((i->type==__if || i->type==__elsif) && i->children.front().condition_check())
|
if((i->type==__if || i->type==__elsif) && i->children.front().condition_check())
|
||||||
|
@ -804,7 +794,6 @@ int abstract_syntax_tree::run_ifelse()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
scope.pop_last_local_scope();
|
|
||||||
--recursion_depth;
|
--recursion_depth;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -922,6 +911,7 @@ int abstract_syntax_tree::run_block()
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
scope.add_new_local_scope();
|
scope.add_new_local_scope();
|
||||||
|
int ret=0;
|
||||||
for(std::list<abstract_syntax_tree>::iterator i=children.begin();i!=children.end();++i)
|
for(std::list<abstract_syntax_tree>::iterator i=children.begin();i!=children.end();++i)
|
||||||
{
|
{
|
||||||
if(i->type==__definition)
|
if(i->type==__definition)
|
||||||
|
@ -950,13 +940,7 @@ int abstract_syntax_tree::run_block()
|
||||||
else if(i->type==__equal || i->type==__add_equal || i->type==__sub_equal || i->type==__mul_equal || i->type==__div_equal || i->type==__link_equal)
|
else if(i->type==__equal || i->type==__add_equal || i->type==__sub_equal || i->type==__mul_equal || i->type==__div_equal || i->type==__link_equal)
|
||||||
i->assignment();
|
i->assignment();
|
||||||
else if(i->type==__add_operator || i->type==__sub_operator || i->type==__mul_operator || i->type==__div_operator || i->type==__link_operator || i->type==__or_operator || i->type==__and_operator || i->type==__nor_operator)
|
else if(i->type==__add_operator || i->type==__sub_operator || i->type==__mul_operator || i->type==__div_operator || i->type==__link_operator || i->type==__or_operator || i->type==__and_operator || i->type==__nor_operator)
|
||||||
{
|
i->calculation();
|
||||||
var t=i->calculation();
|
|
||||||
if(t.get_type()==__var_number)
|
|
||||||
std::cout<<t.get_number()<<std::endl;
|
|
||||||
else if(t.get_type()==__var_string)
|
|
||||||
std::cout<<t.get_string()<<std::endl;
|
|
||||||
}
|
|
||||||
else if(i->type==__while)
|
else if(i->type==__while)
|
||||||
{
|
{
|
||||||
int type=i->run_loop();
|
int type=i->run_loop();
|
||||||
|
@ -964,8 +948,8 @@ int abstract_syntax_tree::run_block()
|
||||||
{
|
{
|
||||||
if(type==__return)
|
if(type==__return)
|
||||||
{
|
{
|
||||||
--recursion_depth;
|
ret=type;
|
||||||
return type;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -979,19 +963,14 @@ int abstract_syntax_tree::run_block()
|
||||||
int type=i->run_ifelse();
|
int type=i->run_ifelse();
|
||||||
if(type)
|
if(type)
|
||||||
{
|
{
|
||||||
--recursion_depth;
|
ret=type;
|
||||||
return type;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(i->type==__continue)
|
else if(i->type==__continue || i->type==__break)
|
||||||
{
|
{
|
||||||
--recursion_depth;
|
ret=i->type;
|
||||||
return __continue;
|
break;
|
||||||
}
|
|
||||||
else if(i->type==__break)
|
|
||||||
{
|
|
||||||
--recursion_depth;
|
|
||||||
return __break;
|
|
||||||
}
|
}
|
||||||
else if(i->type==__return)
|
else if(i->type==__return)
|
||||||
{
|
{
|
||||||
|
@ -1000,15 +979,15 @@ int abstract_syntax_tree::run_block()
|
||||||
if(!(i->children.empty()))
|
if(!(i->children.empty()))
|
||||||
temp=i->children.front().calculation();
|
temp=i->children.front().calculation();
|
||||||
ret_stack.push(temp);
|
ret_stack.push(temp);
|
||||||
--recursion_depth;
|
ret=__return;
|
||||||
return __return;
|
break;
|
||||||
}
|
}
|
||||||
if(exit_type!=__process_exited_successfully)
|
if(exit_type!=__process_exited_successfully)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
scope.pop_last_local_scope();
|
scope.pop_last_local_scope();
|
||||||
--recursion_depth;
|
--recursion_depth;
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,9 @@ class balloon_scope
|
||||||
}
|
}
|
||||||
bool search_var(std::string name)
|
bool search_var(std::string name)
|
||||||
{
|
{
|
||||||
if(!scope_list.empty())
|
if(!scope_list.empty() && !scope_list.back().empty())
|
||||||
{
|
{
|
||||||
|
|
||||||
std::list<std::list<var> >::iterator i=scope_list.back().end();
|
std::list<std::list<var> >::iterator i=scope_list.back().end();
|
||||||
--i;
|
--i;
|
||||||
for(;;--i)
|
for(;;--i)
|
||||||
|
@ -46,7 +47,7 @@ class balloon_scope
|
||||||
}
|
}
|
||||||
void add_new_var(var t)
|
void add_new_var(var t)
|
||||||
{
|
{
|
||||||
if(!scope_list.empty())
|
if(!scope_list.empty() && !scope_list.back().empty())
|
||||||
{
|
{
|
||||||
std::list<std::list<var> >::iterator i=scope_list.back().end();
|
std::list<std::list<var> >::iterator i=scope_list.back().end();
|
||||||
--i;
|
--i;
|
||||||
|
@ -58,7 +59,7 @@ class balloon_scope
|
||||||
}
|
}
|
||||||
var get_var(std::string name)
|
var get_var(std::string name)
|
||||||
{
|
{
|
||||||
if(!scope_list.empty())
|
if(!scope_list.empty() && !scope_list.back().empty())
|
||||||
{
|
{
|
||||||
std::list<std::list<var> >::iterator i=scope_list.back().end();
|
std::list<std::list<var> >::iterator i=scope_list.back().end();
|
||||||
--i;
|
--i;
|
||||||
|
@ -83,7 +84,7 @@ class balloon_scope
|
||||||
var* get_addr(std::string name)
|
var* get_addr(std::string name)
|
||||||
{
|
{
|
||||||
var* addr=NULL;
|
var* addr=NULL;
|
||||||
if(!scope_list.empty())
|
if(!scope_list.empty() && !scope_list.back().empty())
|
||||||
{
|
{
|
||||||
std::list<std::list<var> >::iterator i=scope_list.back().end();
|
std::list<std::list<var> >::iterator i=scope_list.back().end();
|
||||||
--i;
|
--i;
|
||||||
|
@ -136,11 +137,8 @@ class balloon_scope
|
||||||
}
|
}
|
||||||
void pop_last_local_scope()
|
void pop_last_local_scope()
|
||||||
{
|
{
|
||||||
if(!scope_list.empty())
|
if(!scope_list.empty() && !scope_list.back().empty())
|
||||||
{
|
scope_list.back().pop_back();
|
||||||
std::list<std::list<var> > temp=scope_list.back();
|
|
||||||
temp.pop_back();
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue