diff --git a/version0.15/version0.15.2/abstract_syntax_tree.h b/version0.15/version0.15.2/abstract_syntax_tree.h index 78f6d64..58fa067 100644 --- a/version0.15/version0.15.2/abstract_syntax_tree.h +++ b/version0.15/version0.15.2/abstract_syntax_tree.h @@ -9,6 +9,7 @@ class ast_tree_node int line; int type; std::list children; + double num; public: ast_tree_node() { @@ -43,13 +44,13 @@ class ast_tree_node { return children; } - virtual void print_all_tree(int tabnum=0) + void print_all_tree(int tabnum=0) { for(int i=0;i::iterator i=children.begin(); + sum=i->run()+(++i)->run(); + return sum; + } + else if(type==__sub_operator) + { + double sum=0; + std::list::iterator i=children.begin(); + sum=i->run()-(++i)->run(); + return sum; + } + else + { + for(std::list::iterator i=children.begin();i!=children.end();++i) + std::cout<run()<=0;--i) { - num+=acc*((long long int)(str[i]-'0')); + num+=acc*((double)(str[i]-'0')); acc*=10; } } else { - fnum=0; + num=0; double acc=1; double aff=0.1; for(int i=DotPlace+1;i<(int)str.length();++i) { - fnum+=aff*((double)(str[i]-'0')); + num+=aff*((double)(str[i]-'0')); aff*=0.1; } for(int i=DotPlace-1;i>=0;--i) { - fnum+=acc*((double)(str[i]-'0')); + num+=acc*((double)(str[i]-'0')); acc*=10; } } diff --git a/version0.15/version0.15.2/code_generator.h b/version0.15/version0.15.2/code_generator.h index f315499..0050787 100644 --- a/version0.15/version0.15.2/code_generator.h +++ b/version0.15/version0.15.2/code_generator.h @@ -60,7 +60,17 @@ class code_generator parse=temp; return; } - void run() + void print_gen_tree() + { + root.print_all_tree(); + return; + } + void run_gen_tree() + { + root.run(); + return; + } + void gen_ast() { root.return_list().clear(); bool iserror=false; @@ -75,17 +85,21 @@ class code_generator } parse.pop(); } + std::stack temp_ast; while(!node_stack.empty()) { - root.return_list().push_back(node_stack.top()); + temp_ast.push(node_stack.top()); node_stack.pop(); } + while(!temp_ast.empty()) + { + root.return_list().push_back(temp_ast.top()); + temp_ast.pop(); + } if(iserror) return; std::cout<<">>[Parse] 0 error(s)."<>[Parse] Complete checking."<> 3. [exit ] |shut down the interpreter."<> 4. [lexer ] |run and show the lexer. (-lexer)"<> 5. [parser] |run parser. (-parser)"<> 6. [del ] |delete program in memory."<> 7. [run ] |run the programme in stack. (-lexer -parser)"<> 8. [rs ] |check the source program."<> 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."<