From ccd1026819a4500187ba61ad43bdee039c1a4ff3 Mon Sep 17 00:00:00 2001 From: Valk Richard Li <48872266+ValKmjolnir@users.noreply.github.com> Date: Wed, 11 Sep 2019 10:29:00 -0500 Subject: [PATCH] Update --- .../version0.16.1/abstract_syntax_tree.h | 22 +++++++-- version0.16/version0.16.1/ast_generator.h | 46 ++++++++++++++++++- version0.16/version0.16.1/main.cpp | 4 +- 3 files changed, 63 insertions(+), 9 deletions(-) diff --git a/version0.16/version0.16.1/abstract_syntax_tree.h b/version0.16/version0.16.1/abstract_syntax_tree.h index cf03b19..2c44cc3 100644 --- a/version0.16/version0.16.1/abstract_syntax_tree.h +++ b/version0.16/version0.16.1/abstract_syntax_tree.h @@ -31,11 +31,23 @@ class ast_tree_node { return type; } + int return_line() + { + return line; + } 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; @@ -60,24 +72,24 @@ class ast_tree_node std::cout<<" "; if(type==__number) { - std::cout<<"["; + std::cout<<"[ number:"; if(num==0 && fnum!=0) std::cout<::iterator i=children.begin();i!=children.end();++i) i->print(tab_num+1); for(int i=0;i>[Error] parse error:missing number or string at line "<>[Error] parse error in line "<>[Parse] Error(s) occurred,stop."<> Nasal interpreter by ValKmjolnir"<> input [help] to find help."<> Input [help] to find help."<> "; @@ -60,7 +60,7 @@ int main() pas.parse_process(lex.return_list()); cod.input_token_stack(pas.return_stack()); cod.gen_main_prog(); -// cod.print_gen_tree(); + cod.print_ast(); } else if(command=="run") {