diff --git a/abstract_syntax_tree.cpp b/abstract_syntax_tree.cpp new file mode 100644 index 0000000..e6dc5fb --- /dev/null +++ b/abstract_syntax_tree.cpp @@ -0,0 +1,757 @@ +#ifndef __ABSTRACT_SYNTAX_TREE_CPP__ +#define __ABSTRACT_SYNTAX_TREE_CPP__ +#include "abstract_syntax_tree.h" + + +int exit_type=0; +std::stack ret_stack;// for function ret use + +var abstract_syntax_tree::calculation() +{ + var temp; + temp.set_type(__null_type); + if(this->type==__number) + { + temp.set_type(__var_number); + temp.set_number(number); + return temp; + } + else if(this->type==__string) + { + temp.set_type(__var_string); + temp.set_string(str); + return temp; + } + else if(this->type==__id) + { + temp=this->call_identifier(); + return temp; + } + else if(this->type==__array) + { + temp=this->array_generation(); + return temp; + } + else if(this->type==__hash) + { + temp=this->hash_generation(); + return temp; + } + else if(this->type==__function) + { + temp.set_type(__function); + temp.set_function(*this); + return temp; + } + if(this->type==__nor_operator) + { + temp.set_type(__var_number); + temp=children.front().calculation(); + if(temp.get_type()!=__var_number) + { + exit_type=__error_value_type; + std::cout<<">>[Runtime-error] line "<type==__add_operator) + { + temp.set_type(__var_number); + var left_child=children.front().calculation(); + var right_child=children.back().calculation(); + if(left_child.get_type()==__var_number && right_child.get_type()==__var_number) + temp.set_number(left_child.get_number()+right_child.get_number()); + else + { + exit_type=__error_value_type; + std::cout<<">>[Runtime-error] line "<type==__sub_operator) + { + temp.set_type(__var_number); + std::list::iterator i=children.begin(); + ++i; + if(i==children.end()) + { + temp=children.front().calculation(); + if(temp.get_type()==__var_number) + temp.set_number(temp.get_number()*(-1)); + else + { + exit_type=__error_value_type; + std::cout<<">>[Runtime-error] line "<>[Runtime-error] line "<type==__mul_operator) + { + temp.set_type(__var_number); + var left_child=children.front().calculation(); + var right_child=children.back().calculation(); + if(left_child.get_type()==__var_number && right_child.get_type()==__var_number) + temp.set_number(left_child.get_number()*right_child.get_number()); + else + { + exit_type=__error_value_type; + std::cout<<">>[Runtime-error] line "<type==__div_operator) + { + temp.set_type(__var_number); + var left_child=children.front().calculation(); + var right_child=children.back().calculation(); + if(left_child.get_type()==__var_number && right_child.get_type()==__var_number) + { + temp.set_number(left_child.get_number()/right_child.get_number()); + if(std::isnan(temp.get_number()) || std::isinf(temp.get_number())) + { + exit_type=__sigfpe_arithmetic_exception; + std::cout<<">>[Runtime-error] line "<>[Runtime-error] line "<type==__link_operator) + { + temp.set_type(__var_string); + var left_child=children.front().calculation(); + var right_child=children.back().calculation(); + if(left_child.get_type()==__var_string && right_child.get_type()==__var_string) + temp.set_string(left_child.get_string()+right_child.get_string()); + else + { + exit_type=__error_value_type; + std::cout<<">>[Runtime-error] line "<type==__cmp_equal) + { + temp.set_type(__var_number); + var left_child=children.front().calculation(); + var right_child=children.back().calculation(); + if(left_child.get_type()==right_child.get_type()) + { + if(left_child.get_type()==__var_number) + temp.set_number((double)(left_child.get_number()==right_child.get_number())); + else if(left_child.get_type()==__var_string) + temp.set_number((double)(left_child.get_string()==right_child.get_string())); + else + { + exit_type=__error_value_type; + std::cout<<">>[Runtime-error] line "<>[Runtime-error] line "<type==__cmp_not_equal) + { + temp.set_type(__var_number); + var left_child=children.front().calculation(); + var right_child=children.back().calculation(); + if(left_child.get_type()==right_child.get_type()) + { + if(left_child.get_type()==__var_number) + temp.set_number((double)(left_child.get_number()!=right_child.get_number())); + else if(left_child.get_type()==__var_string) + temp.set_number((double)(left_child.get_string()!=right_child.get_string())); + else + { + exit_type=__error_value_type; + std::cout<<">>[Runtime-error] line "<>[Runtime-error] line "<type==__cmp_less) + { + temp.set_type(__var_number); + var left_child=children.front().calculation(); + var right_child=children.back().calculation(); + if(left_child.get_type()==right_child.get_type()) + { + if(left_child.get_type()==__var_number) + temp.set_number((double)(left_child.get_number()>[Runtime-error] line "<>[Runtime-error] line "<type==__cmp_more) + { + temp.set_type(__var_number); + var left_child=children.front().calculation(); + var right_child=children.back().calculation(); + if(left_child.get_type()==right_child.get_type()) + { + if(left_child.get_type()==__var_number) + temp.set_number((double)(left_child.get_number()>right_child.get_number())); + else if(left_child.get_type()==__var_string) + temp.set_number((double)(left_child.get_string()>right_child.get_string())); + else + { + exit_type=__error_value_type; + std::cout<<">>[Runtime-error] line "<\' but use \'"; + print_scalar(left_child.get_type()); + std::cout<<"\'."<>[Runtime-error] line "<\' but use \'"; + print_scalar(left_child.get_type()); + std::cout<<"\' and \'"; + print_scalar(right_child.get_type()); + std::cout<<"\'."<type==__cmp_less_or_equal) + { + temp.set_type(__var_number); + var left_child=children.front().calculation(); + var right_child=children.back().calculation(); + if(left_child.get_type()==right_child.get_type()) + { + if(left_child.get_type()==__var_number) + temp.set_number((double)(left_child.get_number()<=right_child.get_number())); + else if(left_child.get_type()==__var_string) + temp.set_number((double)(left_child.get_string()<=right_child.get_string())); + else + { + exit_type=__error_value_type; + std::cout<<">>[Runtime-error] line "<>[Runtime-error] line "<type==__cmp_more_or_equal) + { + temp.set_type(__var_number); + var left_child=children.front().calculation(); + var right_child=children.back().calculation(); + if(left_child.get_type()==right_child.get_type()) + { + if(left_child.get_type()==__var_number) + temp.set_number((double)(left_child.get_number()>=right_child.get_number())); + else if(left_child.get_type()==__var_string) + temp.set_number((double)(left_child.get_string()>=right_child.get_string())); + else + { + exit_type=__error_value_type; + std::cout<<">>[Runtime-error] line "<=\' but use \'"; + print_scalar(left_child.get_type()); + std::cout<<"\'."<>[Runtime-error] line "<=\' but use \'"; + print_scalar(left_child.get_type()); + std::cout<<"\' and \'"; + print_scalar(right_child.get_type()); + std::cout<<"\'."<type==__or_operator) + { + temp.set_type(__var_number); + var left_child=children.front().calculation(); + var right_child=children.back().calculation(); + if(left_child.get_type()==__var_number && right_child.get_type()==__var_number) + temp.set_number((double)(left_child.get_number() || right_child.get_number())); + else + { + exit_type=__error_value_type; + std::cout<<">>[Runtime-error] line "<type==__and_operator) + { + temp.set_type(__var_number); + var left_child=children.front().calculation(); + var right_child=children.back().calculation(); + if(left_child.get_type()==__var_number && right_child.get_type()==__var_number) + temp.set_number((double)(left_child.get_number() && right_child.get_number())); + else + { + exit_type=__error_value_type; + std::cout<<">>[Runtime-error] line "<>[Runtime-error] line "<>[Runtime-error] line "<>[Runtime-error] line "<::iterator i=children.begin();i!=children.end();++i) + { + if(i->type==__call_array && temp.get_type()==__var_array) + { + var place=i->children.front().calculation(); + if(place.get_type()==__var_number) + temp=temp.get_array_member((int)place.get_number()); + else + { + exit_type=__error_value_type; + std::cout<<">>[Runtime-error] line "<type); + std::cout<<": incorrect type \'"; + print_scalar(temp.get_type()); + std::cout<<"\'."<type==__call_hash && temp.get_type()==__var_hash) + { + temp=temp.get_hash_member(i->name); + if(temp.get_type()==__null_type) + { + exit_type=__get_value_failure; + std::cout<<">>[Runtime-error] line "<name<<"\'."<type==__call_function && temp.get_type()==__var_function) + temp=temp.get_function().run_func(); + else + { + exit_type=__error_value_type; + std::cout<<">>[Runtime-error] line "<type); + std::cout<<": incorrect type \'"; + print_scalar(temp.get_type()); + std::cout<<"\'."<::iterator i=children.begin();i!=children.end();++i) + new_var.append_array(i->calculation()); + return new_var; +} + +var abstract_syntax_tree::hash_generation() +{ + var new_var; + new_var.set_type(__var_hash); + if(!children.empty()) + for(std::list::iterator i=children.begin();i!=children.end();++i) + { + var temp; + temp=i->children.front().calculation(); + temp.set_name(i->name); + new_var.append_hash(temp); + } + return new_var; +} + +var abstract_syntax_tree::get_value() +{ + var temp; + temp.set_type(type); + if(type==__id) + temp=call_identifier(); + else if(type==__number) + temp.set_number(number); + else if(type==__string) + temp.set_string(str); + else if(type==__array) + { + var new_var; + for(std::list::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] line "<::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->calculation(); + new_var.set_name(_name); + scope.add_new_var(new_var); + } + else + { + std::cout<<">>[Runtime-error] line "<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==__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) + std::cout<number<type==__string) + std::cout<str<type==__id) + { + var t=i->call_identifier(); + if(t.get_type()==__var_number) + std::cout<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->type!=__else && i->children.front().condition_check()) + { + ret=i->children.back().run_block(); + break; + } + else + { + ret=i->children.back().run_block(); + break; + } + } + scope.pop_last_local_scope(); + return ret; +} + +var abstract_syntax_tree::run_func() +{ + var ret; + scope.add_new_block_scope(); + scope.add_new_local_scope(); + + //get return + scope.pop_last_block_scope(); + ret=ret_stack.top(); + ret_stack.pop(); + return ret; +} + +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->calculation(); + new_var.set_name(_name); + scope.add_new_var(new_var); + } + else + { + std::cout<<">>[Runtime-error] line "<type==__number) + std::cout<number<type==__string) + std::cout<str<type==__id) + { + var t=i->call_identifier(); + if(t.get_type()==__var_number) + std::cout<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==__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==__while) + { + int type=i->run_loop(); + if(type) + { + if(type==__return) + return type; + else + { + std::cout<<"[Runtime-error] line "<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) + { + var temp; + temp.set_type(__null_type); + if(!(i->children.empty())) + temp=i->calculation(); + ret_stack.push(temp); + return __return; + } + if(exit_type!=__process_exited_successfully) + break; + } + scope.pop_last_local_scope(); + return 0; +} + + +#endif diff --git a/abstract_syntax_tree.h b/abstract_syntax_tree.h new file mode 100644 index 0000000..93cefb0 --- /dev/null +++ b/abstract_syntax_tree.h @@ -0,0 +1,214 @@ +#ifndef __ABSTRACT_SYNTAX_TREE_H__ +#define __ABSTRACT_SYNTAX_TREE_H__ + +class var; + +class abstract_syntax_tree +{ + protected: + int type; + int line; + double number; + std::string str; + std::string name; + std::list children; + public: + abstract_syntax_tree() + { + type=0; + line=0; + number=0; + str=""; + name=""; + children.clear(); + return; + } + abstract_syntax_tree(const abstract_syntax_tree& p) + { + type=p.type; + line=p.line; + number=p.number; + str=p.str; + name=p.name; + children=p.children; + return; + } + ~abstract_syntax_tree() + { + children.clear(); + return; + } + abstract_syntax_tree& operator=(const abstract_syntax_tree& p) + { + type=p.type; + line=p.line; + number=p.number; + str=p.str; + name=p.name; + children.clear(); + children=p.children; + return *this; + } + void set_clear() + { + type=0; + line=0; + number=0; + str=""; + name=""; + children.clear(); + return; + } + void print_tree(const int n) + { + std::string _str=""; + for(int i=0;iprint_tree(n+1); + } + return; + } + void set_type(const int _type) + { + type=_type; + return; + } + void set_line(const int _line) + { + line=_line; + return; + } + void set_string(std::string _str) + { + str=_str; + return; + } + void set_number(std::string _str) + { + if(_str=="nil") + { + number=0; + return; + } + if((int)_str.length()>2 && (_str[1]=='x' || _str[1]=='o')) + { + double num=0; + double pw=1; + if(_str[1]=='x') + for(int i=(int)_str.length()-1;i>1;--i) + { + if('0'<=_str[i] && _str[i]<='9') + num+=(_str[i]-'0')*pw; + else if('a'<=_str[i] && _str[i]<='f') + num+=(10+_str[i]-'a')*pw; + else if('A'<=_str[i] && _str[i]<='F') + num+=(10+_str[i]-'A')*pw; + pw*=16; + } + else + for(int i=(int)_str.length()-1;i>1;--i) + { + num+=(_str[i]-'0')*pw; + pw*=8; + } + number=num; + return; + } + int dot_place=-1; + for(int i=0;i<(int)_str.length();++i) + if(_str[i]=='.') + { + dot_place=i; + break; + } + if(dot_place==-1) + { + number=0; + double pw=1; + for(int i=(int)_str.length()-1;i>=0;--i) + { + number+=(_str[i]-'0')*pw; + pw*=10; + } + } + else + { + number=0; + double pw=0.1; + for(int i=dot_place+1;i<(int)_str.length();++i) + { + number+=(_str[i]-'0')*pw; + pw/=10; + } + pw=1; + for(int i=dot_place-1;i>=0;--i) + { + number+=(_str[i]-'0')*pw; + pw*=10; + } + } + return; + } + void set_name(std::string _str) + { + name=_str; + return; + } + void add_child(abstract_syntax_tree p) + { + children.push_back(p); + return; + } + int get_type() + { + return type; + } + int get_line() + { + return line; + } + double get_number() + { + return number; + } + std::string get_string() + { + return str; + } + std::string get_name() + { + return name; + } + std::list& get_children() + { + return children; + } + var calculation(); + bool condition_check(); + var call_identifier(); + var array_generation(); + var hash_generation(); + var get_value(); + void run_root(); + int run_loop(); + int run_ifelse(); + var run_func(); + int run_block(); +}; + +#endif diff --git a/balloon.h b/balloon.h new file mode 100644 index 0000000..e9d6efa --- /dev/null +++ b/balloon.h @@ -0,0 +1,22 @@ +#ifndef __BALLOON_H__ +#define __BALLOON_H__ + +#include +#include +#include +#include +#include +#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_parse.h b/balloon_parse.h new file mode 100644 index 0000000..2fb3e3b --- /dev/null +++ b/balloon_parse.h @@ -0,0 +1,988 @@ +#ifndef __BALLOON_PARSE_H__ +#define __BALLOON_PARSE_H__ + +class balloon_parse +{ + private: + std::stack parse; + token this_token; + int error; + int warning; + abstract_syntax_tree root; + public: + void get_token() + { + if(!parse.empty()) + { + this_token=parse.top(); + parse.pop(); + } + else + this_token.type=0; + return; + } + void get_detail_token_stream(std::list& tk_list) + { + root.set_clear(); + while(!parse.empty()) + parse.pop(); + if(tk_list.empty()) + return; + std::stack temp; + for(std::list::iterator i=tk_list.begin();i!=tk_list.end();++i) + temp.push(*i); + while(!temp.empty()) + { + parse.push(temp.top()); + temp.pop(); + } + return; + } + void print_parse_stack() + { + if(parse.empty()) + return; + std::stack temp; + int line=parse.top().line; + std::cout<>[Abstract-syntax-tree]"<>[Runtime] process begins at addr:"<<(void*)(&root)<<"."<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-warning] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse-error] line "<>[Parse] complete generating."< global; + std::list > > scope_list; + public: + void set_clear() + { + global.clear(); + scope_list.clear(); + return; + } + bool search_var(std::string name) + { + if(!scope_list.empty()) + { + std::list >::iterator i=scope_list.back().end(); + --i; + for(;;--i) + { + for(std::list::iterator j=i->begin();j!=i->end();++j) + if(j->get_name()==name) + return true; + if(i==scope_list.back().begin()) + break; + } + } + if(!global.empty()) + { + for(std::list::iterator i=global.begin();i!=global.end();++i) + if(i->get_name()==name) + return true; + } + return false; + } + void add_new_var(var t) + { + if(!scope_list.empty()) + { + std::list >::iterator i=scope_list.back().end(); + --i; + i->push_back(t); + return; + } + global.push_back(t); + return; + } + var get_var(std::string name) + { + if(!scope_list.empty()) + { + std::list >::iterator i=scope_list.back().end(); + --i; + // get the last scope block(std::list >) + for(;;--i) + { + for(std::list::iterator j=i->begin();j!=i->end();++j) + if(j->get_name()==name) + return *j; + if(i==scope_list.back().begin()) + break; + } + } + if(!global.empty()) + { + for(std::list::iterator i=global.begin();i!=global.end();++i) + if(i->get_name()==name) + return *i; + } + return error_var; + } + void add_new_block_scope() + { + std::list > new_list; + scope_list.push_back(new_list); + return; + } + void add_new_local_scope() + { + if(!scope_list.empty()) + { + std::list > >::iterator i=scope_list.end(); + --i; + std::list new_list; + i->push_back(new_list); + } + return; + } + void pop_last_block_scope() + { + if(!scope_list.empty()) + scope_list.pop_back(); + return; + } + void pop_last_local_scope() + { + if(!scope_list.empty()) + { + std::list > temp=scope_list.back(); + temp.pop_back(); + } + return; + } +}; + +balloon_scope scope; + +#endif diff --git a/balloon_type.h b/balloon_type.h new file mode 100644 index 0000000..d1b14db --- /dev/null +++ b/balloon_type.h @@ -0,0 +1,174 @@ +#ifndef __BALLOON_TYPE_H__ +#define __BALLOON_TYPE_H__ + + +enum token_type +{ + __token_number=1, + __token_string, + __reserve_word, + __token_identifier, + __token_operator +}; +void print_token(int type) +{ + std::string str; + switch(type) + { + case __token_number: str="number ";break; + case __token_string: str="string ";break; + case __reserve_word: str="reserve word ";break; + case __token_identifier:str="identifier ";break; + case __token_operator: str="operator ";break; + default: str="unknown ";break; + } + std::cout< >= + __and_operator,__or_operator,__nor_operator, // and or ! + __add_operator,__sub_operator, // + - + __mul_operator,__div_operator,__link_operator, // * / ~ + __add_equal,__sub_equal, // += -= + __mul_equal,__div_equal,__link_equal, // *= /= ~= + __left_brace,__right_brace, // {} + __left_bracket,__right_bracket, // [] + __left_curve,__right_curve, // () + __semi,__comma,__colon,__dot, // ; , : . + __var,__func,__return, + __if,__elsif,__else, + __continue,__break, + __for,__forindex,__foreach,__while, + __nil, + //operators & reserve words + __number,__string,__id,__dynamic_id, + //basic elements + + __null_node, + __block, + __array, + __hash, + __root, + __loop, + __ifelse, + __function, + __parameter, + __definition, + __assignment, + __call_array, + __call_hash, + __call_function +}; +void print_detail_token(int type) +{ + std::string context=""; + switch(type) + { + case __equal: context="="; break; + case __cmp_equal: context="==";break; + case __cmp_not_equal: context="!=";break; + case __cmp_less: context="<"; break; + case __cmp_less_or_equal: context="<=";break; + case __cmp_more: context=">"; break; + case __cmp_more_or_equal: context=">=";break; + case __and_operator: context="and";break; + case __or_operator: context="or"; break; + case __nor_operator: context="!"; break; + case __add_operator: context="+"; break; + case __sub_operator: context="-"; break; + case __mul_operator: context="*"; break; + case __div_operator: context="/"; break; + case __link_operator: context="~"; break; + case __add_equal: context="+=";break; + case __sub_equal: context="-=";break; + case __mul_equal: context="*=";break; + case __div_equal: context="/=";break; + case __link_equal: context="~=";break; + case __left_brace: context="{"; break; + case __right_brace: context="}"; break; + case __left_bracket: context="["; break; + case __right_bracket: context="]"; break; + case __left_curve: context="("; break; + case __right_curve: context=")"; break; + case __semi: context=";"; break; + case __comma: context=","; break; + case __colon: context=":"; break; + case __dot: context="."; break; + case __var: context="var"; break; + case __func: context="func";break; + case __continue: context="continye"; break; + case __break: context="break"; break; + case __for: context="for"; break; + case __forindex: context="forindex";break; + case __foreach: context="foreach";break; + case __while: context="while";break; + case __if: context="if";break; + case __elsif: context="elsif";break; + case __else: context="else";break; + case __return: context="return";break; + case __nil: context="nil";break; + case __id: context="id";break; + case __dynamic_id: context="id...";break; + case __number: context="num";break; + case __string: context="str";break; + + case __null_node: context="null node";break; + case __block: context="block";break; + case __array: context="array";break; + case __hash: context="hash";break; + case __root: context="root";break; + case __loop: context="loop";break; + case __ifelse: context="if-else";break; + case __function: context="function";break; + case __parameter: context="parameter";break; + case __definition: context="definition";break; + case __assignment: context="assignment";break; + case __call_array: context="call array";break; + case __call_hash: context="call hash";break; + case __call_function: context="call func";break; + default: context="undefined token";break; + } + std::cout< balloon_array; + std::list balloon_hash; + abstract_syntax_tree function; + public: + var() + { + type=__null_type; + number=0; + str=""; + name=""; + balloon_array.clear(); + balloon_hash.clear(); + function.set_clear(); + return; + } + var(const var& p) + { + type=p.type; + number=p.number; + str=p.str; + name=p.name; + balloon_array=p.balloon_array; + balloon_hash=p.balloon_hash; + function=p.function; + return; + } + var& operator=(const var& p) + { + type=p.type; + number=p.number; + str=p.str; + name=p.name; + balloon_array.clear(); + balloon_hash.clear(); + function.set_clear(); + balloon_array=p.balloon_array; + balloon_hash=p.balloon_hash; + function=p.function; + return *this; + } + void set_type(int); + void set_name(std::string); + void set_number(double); + void set_string(std::string); + void set_function(abstract_syntax_tree&); + void append_array(var); + void append_hash(var); + int get_type(); + std::string get_name(); + double get_number(); + std::string get_string(); + var& get_array_member(int); + var& get_hash_member(std::string); + abstract_syntax_tree& get_function(); +}; + +var error_var; + +void var::set_type(int _type) +{ + type=_type; + return; +} + +void var::set_name(std::string _name) +{ + name=_name; + return; +} + +void var::set_number(double _num) +{ + number=_num; + return; +} + +void var::set_string(std::string _str) +{ + str=_str; + return; +} + +void var::set_function(abstract_syntax_tree& p) +{ + function=p; + return; +} + +void var::append_array(var _new_var) +{ + balloon_array.push_back(_new_var); + return; +} + +void var::append_hash(var _new_var) +{ + balloon_hash.push_back(_new_var); + return; +} + +int var::get_type() +{ + return type; +} + +std::string var::get_name() +{ + return name; +} + +double var::get_number() +{ + return number; +} + +std::string var::get_string() +{ + return str; +} + +var& var::get_array_member(int _place) +{ + if(balloon_array.empty()) + { + std::cout<<">>[Runtime-error] overflow when searching member "<<_place<<" but the max size of array \'"<::iterator i=balloon_array.begin();i!=balloon_array.end();++i,++cnt) + if(cnt==_place) + return *i; + std::cout<<">>[Runtime-error] overflow when searching member "<<_place<<" but the max size of array \'"<::iterator i=balloon_hash.begin();i!=balloon_hash.end();++i) + if(i->name==_name) + return *i; + std::cout<<">>[Runtime-error] hash \'"<> Balloon interpreter by ValKmjolnir"<> Input [help] to find help."<> "; + std::getline(std::cin,command); + if(command=="help") + { + std::cout<<">> Balloon interpreter by ValKmjolnir"<> 1. [ ] |input file name to load the file."<> 2. [cls ] |clear the screen."<> 3. [exit ] |shut down the interpreter."<> 4. [lexer ] |run and show the lexer. (-lexer)"<> 5. [parser] |run parser and see parse stack & parse result(s). (-parser)"<> 6. [ast ] |print the abstract syntax tree."<> 7. [del ] |delete program in memory."<> 8. [run ] |run the programme in stack. (-lexer -parser)"<> 9. [rs ] |check the source program."<>[Delete] Complete."<>[Lexer] error(s) found,stop."<>[Parse] error(s) found,stop."<>[Lexer] error(s) found,stop."<>[Parse] error(s) found,stop."<>[Lexer] error(s) found,stop."<