From 4606e3b90da51eb76eb7fb58978dc0cd376caa56 Mon Sep 17 00:00:00 2001 From: Valk Richard Li <48872266+ValKmjolnir@users.noreply.github.com> Date: Sun, 19 Jan 2020 17:30:36 +0800 Subject: [PATCH] update --- version2.0/main.cpp | 4 +++- version2.0/nasal_parse.h | 26 +++++++++++++++++++++++++- version2.0/test.nas | 1 + 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/version2.0/main.cpp b/version2.0/main.cpp index 6d5586e..01a3242 100644 --- a/version2.0/main.cpp +++ b/version2.0/main.cpp @@ -17,7 +17,9 @@ int main() #ifdef TARGET_OS_MAC std::cout<<">>[system] MacOS system."<> Nasal interpreter ver 2.0: https://github.com/ValKmjolnir/Nasal-Interpreter"<> Nasal interpreter ver 2.0 ."<> Code: https://github.com/ValKmjolnir/Nasal-Interpreter"<> More info: http://wiki.flightgear.org/Nasal_scripting_language"<> Input \"help\" to get help ."<get_token(); while(this_token.type==__or_operator) { + tmp_node.set_clear(); tmp_node.set_node_line(this_token.line); tmp_node.set_node_type(this_token.type); tmp_node.add_children(calc_node); @@ -241,6 +242,7 @@ abstract_syntax_tree nasal_parse::calculation() } if(this_token.type==__ques_mark) { + tmp_node.set_clear(); // '?' ';' tmp_node.set_node_line(this_token.line); tmp_node.set_node_type(__ques_mark); @@ -268,6 +270,7 @@ abstract_syntax_tree nasal_parse::and_calculation() this->get_token(); while(this_token.type==__and_operator) { + tmp_node.set_clear(); tmp_node.set_node_line(this_token.line); tmp_node.set_node_type(this_token.type); tmp_node.add_children(calc_node); @@ -287,6 +290,7 @@ abstract_syntax_tree nasal_parse::or_calculation() this->get_token(); while(this_token.type==__or_operator) { + tmp_node.set_clear(); tmp_node.set_node_line(this_token.line); tmp_node.set_node_type(this_token.type); tmp_node.add_children(calc_node); @@ -306,6 +310,7 @@ abstract_syntax_tree nasal_parse::additive_calculation() this->get_token(); while((this_token.type==__add_operator) || (this_token.type==__sub_operator)) { + tmp_node.set_clear(); tmp_node.set_node_line(this_token.line); tmp_node.set_node_type(this_token.type); tmp_node.add_children(calc_node); @@ -341,10 +346,29 @@ abstract_syntax_tree nasal_parse::multive_calculation() this->get_token(); while((this_token.type==__mul_operator) || (this_token.type==__div_operator)) { + tmp_node.set_clear(); tmp_node.set_node_line(this_token.line); tmp_node.set_node_type(this_token.type); tmp_node.add_children(calc_node); - tmp_node.add_children(scalar_generate()); + this->get_token(); + if((this_token.type==__sub_operator) || (this_token.type==__nor_operator)) + { + calc_node.set_clear(); + calc_node.set_node_line(this_token.line); + calc_node.set_node_type(this_token.type); + abstract_syntax_tree null_node; + null_node.set_node_line(this_token.line); + null_node.set_node_type(__number); + null_node.set_var_number("0"); + calc_node.add_children(null_node); + calc_node.add_children(scalar_generate()); + } + else + { + this->push_token(); + calc_node=scalar_generate(); + } + tmp_node.add_children(calc_node); calc_node=tmp_node; this->get_token(); } diff --git a/version2.0/test.nas b/version2.0/test.nas index 709d9b4..dff612b 100644 --- a/version2.0/test.nas +++ b/version2.0/test.nas @@ -98,6 +98,7 @@ var (r,g,b)=color; 1+1; 1+1-2+3-4+5-6; 1+1*8-9/3; +1*-1; 1*(1+2*(3+4*(5+6*(7+8*(9+10/(1+1)))))); ((-1*2+9))/7-1; ((({num:2})))["num"]*2*2*2;