From 85310cf2ddbfb63c6eead9b282742b16e5405a25 Mon Sep 17 00:00:00 2001 From: Valk Richard Li <48872266+ValKmjolnir@users.noreply.github.com> Date: Wed, 13 Nov 2019 11:36:05 +0800 Subject: [PATCH] update --- balloon/abstract_syntax_tree.cpp | 60 +++++++++++++++++++++++++++----- balloon/loop.txt | 1 + 2 files changed, 52 insertions(+), 9 deletions(-) diff --git a/balloon/abstract_syntax_tree.cpp b/balloon/abstract_syntax_tree.cpp index 088bbdf..7121dc8 100644 --- a/balloon/abstract_syntax_tree.cpp +++ b/balloon/abstract_syntax_tree.cpp @@ -395,6 +395,7 @@ bool abstract_syntax_tree::condition_check() var abstract_syntax_tree::call_identifier() { var temp; + temp.set_type(__null_type); if(scope.search_var(name)) temp=scope.get_var(name); else @@ -407,7 +408,39 @@ var abstract_syntax_tree::call_identifier() { for(std::list::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] "; + print_detail_token(i->type); + std::cout<<":incorrect type \'"; + print_scalar(temp.get_type()); + std::cout<<"\'."<type==__call_hash && temp.get_type()==__var_hash) + { + + } + else if(i->type==__call_function && temp.get_type()==__var_function) + { + + } + else + { + exit_type=__error_value_type; + std::cout<<">>[Runtime-error] "; + print_detail_token(i->type); + std::cout<<":incorrect type \'"; + print_scalar(temp.get_type()); + std::cout<<"\'."<children.end()) - new_var=j->get_value(); + new_var=j->calculation(); new_var.set_name(_name); scope.add_new_var(new_var); } @@ -497,7 +530,13 @@ void abstract_syntax_tree::run_root() else if(i->type==__string) std::cout<str<type==__id) - std::cout<call_identifier().get_name()<call_identifier(); + if(t.get_type()==__var_number) + std::cout<type==__while) { scope.add_new_block_scope(); @@ -592,7 +631,7 @@ int abstract_syntax_tree::run_block() { ++j; if(j!=i->children.end()) - new_var=j->get_value(); + new_var=j->calculation(); new_var.set_name(_name); scope.add_new_var(new_var); } @@ -600,7 +639,6 @@ int abstract_syntax_tree::run_block() { std::cout<<">>[Runtime-error] redeclaration of \'"<<_name<<"\'."<type==__number) @@ -608,7 +646,13 @@ int abstract_syntax_tree::run_block() else if(i->type==__string) std::cout<str<type==__id) - std::cout<call_identifier().get_name()<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) { ; @@ -650,9 +694,7 @@ int abstract_syntax_tree::run_block() var temp; temp.set_type(__null_type); if(!(i->children.empty())) - { - - } + temp=i->calculation(); ret_stack.push(temp); return __return; } diff --git a/balloon/loop.txt b/balloon/loop.txt index 45758d6..2e9d7b4 100644 --- a/balloon/loop.txt +++ b/balloon/loop.txt @@ -2,6 +2,7 @@ var a=1; var sum=0; while(a!=100) { + a; sum+=a; a+=1; }