From 48f774cb859c4bc674e900052b0350c4fec75cc1 Mon Sep 17 00:00:00 2001 From: Valk Richard Li <48872266+ValKmjolnir@users.noreply.github.com> Date: Sat, 9 Nov 2019 00:03:25 +0800 Subject: [PATCH] fixed a bug which causes g++ parse error. --- version1.3/nasal_vm.h | 105 +++++++++++------------------------------- 1 file changed, 26 insertions(+), 79 deletions(-) diff --git a/version1.3/nasal_vm.h b/version1.3/nasal_vm.h index 6570960..00dfa1a 100644 --- a/version1.3/nasal_vm.h +++ b/version1.3/nasal_vm.h @@ -159,14 +159,13 @@ class var class var_scope_manager { private: - std::list> scope_list; - std::list scope_type; + std::list > scope_list; var error_var; public: var_scope_manager() { scope_list.clear(); - std::string str="__nas_strc_error_ret"; + std::string str="__nas_strc_lang_error_ret"; error_var.set_name(str); error_var.set_type(__null_type); return; @@ -174,105 +173,66 @@ class var_scope_manager void set_clear() { scope_list.clear(); - scope_type.clear(); return; } var& search_var(std::string str) { - for(std::list>::iterator i=scope_list.begin();i!=scope_list.end();++i) + std::list>::iterator i=scope_list.end(); + --i; + for(;;--i) + { for(std::list::iterator j=i->begin();j!=i->end();++j) if(j->get_name()==str) return *j; + if(i==scope_list.begin()) + break; + } std::cout<>[Runtime-error] could not find the var '"<>::iterator i=scope_list.begin(); - std::list::iterator t=scope_type.begin(); - // get global scopes - for(;i!=scope_list.end();++i,++t) + if(scope_list.empty()) { - if(*t!=__function) + std::cout<>[Runtime-error] empty scope list."<>::iterator i=scope_list.end(); + --i; + for(std::list::iterator j=i->begin();j!=i->end();++j) + { + if(j->get_name()==new_var.get_name()) { - for(std::list::iterator j=i->begin();j!=i->end();++j) - if(j->get_name()==new_var.get_name()) - { - std::cout<>[Runtime-error] redeclaration of var '"<>[Runtime-error] redeclaration of var '"<::iterator j=i->begin();j!=i->end();++j) - if(j->get_name()==new_var.get_name()) - { - std::cout<>[Runtime-error] redeclaration of var '"<push_back(new_var); - } - else - std::cout<>[Runtime-error] empty scope list."<push_back(new_var); return; } - void add_new_scope(int type) + void add_new_scope() { std::list new_list; scope_list.push_back(new_list); - scope_type.push_back(type); return; } void pop_last_scope() { if(!scope_list.empty()) - { scope_list.pop_back(); - scope_type.pop_back(); - } else std::cout<>[Runtime-error] scope poped empty thing."<>[Code] runtime got the ast-root: "<<((void *)&tree)<<"->"<<((void *)&root)<<"."<>[Runtime] process exited after "<>[Runtime] runtime got the ast-root: "<<((void *)&tree)<<"->"<<((void *)&root)<<"."<