diff --git a/balloon/abstract_syntax_tree.cpp b/balloon/abstract_syntax_tree.cpp new file mode 100644 index 0000000..c4fef75 --- /dev/null +++ b/balloon/abstract_syntax_tree.cpp @@ -0,0 +1,65 @@ +#ifndef __ABSTRACT_SYNTAX_TREE_CPP__ +#define __ABSTRACT_SYNTAX_TREE_CPP__ + +balloon_scope global; +var abstract_syntax_tree::get_value() +{ + var temp; + temp.set_type(type); + if(type==__number) + temp.set_number(number); + else if(type==__string) + temp.set_string(str); + else if(type==__array) + { + var new_var; + } + else if(type==__hash) + { + var new_var; + } + else if(type==__function) + temp.set_function(*this); + if(name.length()!=0) + temp.set_name(name); + return temp; +} +void abstract_syntax_tree::run_root() +{ + global.set_clear(); + int beg_time,end_time; + int exit_type=__process_exited_successfully; + beg_time=time(NULL); + 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(!global.search_var(_name)) + { + new_var.set_name(_name); + global.add_var(new_var); + } + else + { + std::cout<<">>[Runtime-error] redeclaration of \'"<<_name<<"\'."<>[Runtime] process exited after "< #include #include +#include #include "balloon_type.h" #include "abstract_syntax_tree.h" #include "balloon_var.h" #include "balloon_lexer.h" #include "balloon_parse.h" +#include "balloon_scope.h" + +#include "abstract_syntax_tree.cpp" #endif diff --git a/balloon/balloon_parse.h b/balloon/balloon_parse.h index 4da62d3..86e5422 100644 --- a/balloon/balloon_parse.h +++ b/balloon/balloon_parse.h @@ -75,6 +75,12 @@ class balloon_parse root.print_tree(1); return; } + void run_tree() + { + std::cout<<">>[Runtime] process begins at addr:"<<(void*)(&root)<<"."< scope; + var error_var; + public: + void set_clear() + { + scope.clear(); + return; + } + bool search_var(std::string name) + { + for(std::list::iterator i=scope.begin();i!=scope.end();++i) + if(i->get_name()==name) + return true; + return false; + } + void add_var(var t) + { + scope.push_back(t); + return; + } + var& get_var(std::string name) + { + for(std::list::iterator i=scope.begin();i!=scope.end();++i) + if(i->get_name()==name) + return *i; + std::cout<<">>[Runtime-error] \'"<>[Runtime-error] hash \'"<>[Parse] error(s) found,stop."<>[Lexer] error(s) found,stop."<