diff --git a/balloon/abstract_syntax_tree.cpp b/balloon/abstract_syntax_tree.cpp index 5134364..322a4fd 100644 --- a/balloon/abstract_syntax_tree.cpp +++ b/balloon/abstract_syntax_tree.cpp @@ -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) 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) - { var t=i->calculation(); - if(t.get_type()==__var_number) - std::cout<type==__number || i->type==__string) ; else if(i->type==__id) @@ -757,7 +751,6 @@ int abstract_syntax_tree::run_loop() return 0; } int ret=0; - scope.add_new_local_scope(); abstract_syntax_tree condition=children.front(); abstract_syntax_tree blk=children.back(); @@ -774,7 +767,6 @@ int abstract_syntax_tree::run_loop() if(exit_type!=__process_exited_successfully) break; } - scope.pop_last_local_scope(); --recursion_depth; return ret; } @@ -789,8 +781,6 @@ int abstract_syntax_tree::run_ifelse() return 0; } int ret=0; - scope.add_new_local_scope(); - for(std::list::iterator i=children.begin();i!=children.end();++i) { if((i->type==__if || i->type==__elsif) && i->children.front().condition_check()) @@ -804,7 +794,6 @@ int abstract_syntax_tree::run_ifelse() break; } } - scope.pop_last_local_scope(); --recursion_depth; return ret; } @@ -922,6 +911,7 @@ int abstract_syntax_tree::run_block() return 0; } scope.add_new_local_scope(); + int ret=0; for(std::list::iterator i=children.begin();i!=children.end();++i) { 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) 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) - { - var t=i->calculation(); - if(t.get_type()==__var_number) - std::cout<calculation(); else if(i->type==__while) { int type=i->run_loop(); @@ -964,8 +948,8 @@ int abstract_syntax_tree::run_block() { if(type==__return) { - --recursion_depth; - return type; + ret=type; + break; } else { @@ -979,19 +963,14 @@ int abstract_syntax_tree::run_block() int type=i->run_ifelse(); if(type) { - --recursion_depth; - return type; + ret=type; + break; } } - else if(i->type==__continue) + else if(i->type==__continue || i->type==__break) { - --recursion_depth; - return __continue; - } - else if(i->type==__break) - { - --recursion_depth; - return __break; + ret=i->type; + break; } else if(i->type==__return) { @@ -1000,15 +979,15 @@ int abstract_syntax_tree::run_block() if(!(i->children.empty())) temp=i->children.front().calculation(); ret_stack.push(temp); - --recursion_depth; - return __return; + ret=__return; + break; } if(exit_type!=__process_exited_successfully) break; } scope.pop_last_local_scope(); --recursion_depth; - return 0; + return ret; } diff --git a/balloon/balloon_scope.h b/balloon/balloon_scope.h index 22a5a2d..004c1bb 100644 --- a/balloon/balloon_scope.h +++ b/balloon/balloon_scope.h @@ -23,8 +23,9 @@ class balloon_scope } bool search_var(std::string name) { - if(!scope_list.empty()) + if(!scope_list.empty() && !scope_list.back().empty()) { + std::list >::iterator i=scope_list.back().end(); --i; for(;;--i) @@ -46,7 +47,7 @@ class balloon_scope } void add_new_var(var t) { - if(!scope_list.empty()) + if(!scope_list.empty() && !scope_list.back().empty()) { std::list >::iterator i=scope_list.back().end(); --i; @@ -58,7 +59,7 @@ class balloon_scope } var get_var(std::string name) { - if(!scope_list.empty()) + if(!scope_list.empty() && !scope_list.back().empty()) { std::list >::iterator i=scope_list.back().end(); --i; @@ -83,7 +84,7 @@ class balloon_scope var* get_addr(std::string name) { var* addr=NULL; - if(!scope_list.empty()) + if(!scope_list.empty() && !scope_list.back().empty()) { std::list >::iterator i=scope_list.back().end(); --i; @@ -136,11 +137,8 @@ class balloon_scope } void pop_last_local_scope() { - if(!scope_list.empty()) - { - std::list > temp=scope_list.back(); - temp.pop_back(); - } + if(!scope_list.empty() && !scope_list.back().empty()) + scope_list.back().pop_back(); return; } };