#ifndef __ABSTRACT_SYNTAX_TREE_CPP__ #define __ABSTRACT_SYNTAX_TREE_CPP__ #include "abstract_syntax_tree.h" int exit_type=0; bool abstract_syntax_tree::check() { bool ret=false; if(this->type==__cmp_equal) { } else if(this->type==__cmp_not_equal) { } else if(this->type==__cmp_less) { } else if(this->type==__cmp_less_or_equal) { } else if(this->type==__cmp_more) { } else if(this->type==__cmp_more_or_equal) { } else if(this->type==__or_operator) { } else if(this->type==__and_operator) { } return true; } var abstract_syntax_tree::call_id() { var temp; if(scope.search_var(name)) temp=scope.get_var(name); else { std::cout<<">>[Runtime-error] cannot find a var named \'"<::iterator i=children.begin();i!=children.end();++i) { new_var=i->get_value(); temp.append_array(new_var); } } else if(type==__hash) { var new_var; for(std::list::iterator i=children.begin();i!=children.end();++i) { new_var=i->children.begin()->get_value(); new_var.set_name(i->name); temp.append_array(new_var); } } else if(type==__function) temp.set_function(*this); else { std::cout<<">>[Runtime-error] incorrect value."<::iterator i=children.begin();i!=children.end();++i) { if(i->type==__definition) { var new_var; std::list::iterator j=i->children.begin(); std::string _name=j->name; if(!scope.search_var(_name)) { ++j; if(j!=i->children.end()) new_var=j->get_value(); new_var.set_name(_name); scope.add_new_var(new_var); } else { std::cout<<">>[Runtime-error] redeclaration of \'"<<_name<<"\'."<type==__number) std::cout<number<type==__string) std::cout<str<type==__id) std::cout<call_id().get_name()<type==__while) { scope.add_new_block_scope(); i->run_loop(); scope.pop_last_block_scope(); } else if(i->type==__ifelse) { scope.add_new_block_scope(); i->run_ifelse(); scope.pop_last_block_scope(); } if(exit_type!=__process_exited_successfully) break; } end_time=time(NULL); std::cout<<"--------------------------------------------------------------------------------------"<>[Runtime] process exited after "<::iterator i=children.begin();i!=children.end();++i) { if(i->children.front().check()) { ret=i->children.back().run_block(); break; } } scope.pop_last_local_scope(); return ret; } void abstract_syntax_tree::run_func() { scope.add_new_block_scope(); scope.add_new_local_scope(); scope.pop_last_block_scope(); return; } int abstract_syntax_tree::run_block() { scope.add_new_local_scope(); for(std::list::iterator i=children.begin();i!=children.end();++i) { if(i->type==__definition) { var new_var; std::list::iterator j=i->children.begin(); std::string _name=j->name; if(!scope.search_var(_name)) { ++j; if(j!=i->children.end()) new_var=j->get_value(); new_var.set_name(_name); scope.add_new_var(new_var); } else { std::cout<<">>[Runtime-error] redeclaration of \'"<<_name<<"\'."<type==__number) std::cout<number<type==__string) std::cout<str<type==__id) std::cout<call_id().get_name()<type==__while) { int type=i->run_loop(); if(type) { if(type==__return) return type; else { std::cout<<"[Runtime-error] incorrect use of break/continue."<type==__ifelse) { int type=i->run_ifelse(); if(type) return type; } else if(i->type==__continue) return __continue; else if(i->type==__break) return __break; else if(i->type==__return) return __return; if(exit_type!=__process_exited_successfully) break; } scope.pop_last_local_scope(); return 0; } #endif