From edf75ebe9a8adf1f3500de52baad3fdd5e231fb2 Mon Sep 17 00:00:00 2001 From: Valk Richard Li <48872266+ValKmjolnir@users.noreply.github.com> Date: Fri, 5 Jun 2020 16:16:32 +0800 Subject: [PATCH] Delete abstract_syntax_tree.h --- version0.18/abstract_syntax_tree.h | 243 ----------------------------- 1 file changed, 243 deletions(-) delete mode 100644 version0.18/abstract_syntax_tree.h diff --git a/version0.18/abstract_syntax_tree.h b/version0.18/abstract_syntax_tree.h deleted file mode 100644 index f67ab08..0000000 --- a/version0.18/abstract_syntax_tree.h +++ /dev/null @@ -1,243 +0,0 @@ -#ifndef __ABSTRACT_SYNTAX_TREE_H__ -#define __ABSTRACT_SYNTAX_TREE_H__ - -class ast_tree_node -{ - protected: - int line; - int type; - std::list children;// for node that can be extended - - double num; // for number - std::string str; // for string - public: - ast_tree_node() - { - line=0; - type=__root; - children.clear(); - - num=0; - str=""; - } - void set_line(int _line) - { - line=_line; - return; - } - int return_type() - { - return type; - } - int return_line() - { - return line; - } - double run() - { - if(type==__number) - return num; - else if(type==__root) - { - std::cout<<">>[Result(s)]"<::iterator i=children.begin();i!=children.end();++i) - std::cout<run()<::iterator i=children.begin(); - double left_child=i->run(); - ++i; - double right_child=i->run(); - switch(type) - { - case __add_operator:return left_child+right_child;break; - case __sub_operator:return left_child-right_child;break; - case __mul_operator:return left_child*right_child;break; - case __div_operator:return left_child/right_child;break; - } - } - return 0; - } - void add_child(ast_tree_node& new_child) - { - children.push_back(new_child); - return; - } - ast_tree_node& return_last_child() - { - std::list::iterator i; - for(i=children.begin();i!=children.end();++i) - ; - --i; - return *i; - } - void clear_tree() - { - line=0; - type=__root; - children.clear(); - - num=0; - str=""; - return; - } - int child_num() - { - int cnt=0; - for(std::list::iterator i=children.begin();i!=children.end();++i) - ++cnt; - return cnt; - } - void print(int tab_num) - { - for(int i=0;i::iterator i=children.begin();i!=children.end();++i) - i->print(tab_num+1); - for(int i=0;i=0;--i) - { - num+=acc*((double)(str[i]-'0')); - acc*=10; - } - } - else - { - num=0; - double acc=1; - double aff=0.1; - for(int i=DotPlace+1;i<(int)str.length();++i) - { - num+=aff*((double)(str[i]-'0')); - aff*=0.1; - } - for(int i=DotPlace-1;i>=0;--i) - { - num+=acc*((double)(str[i]-'0')); - acc*=10; - } - } - return; - } -}; -class string_expr:public ast_tree_node -{ - public: - string_expr():ast_tree_node() - { - type=__string; - } - void set_str(std::string& t) - { - str=t; - return; - } - std::string& return_str() - { - return str; - } -}; - -#endif