From 7fe459c38b50e31873ec86fadb43df18e8df4e24 Mon Sep 17 00:00:00 2001 From: Valk Richard Li <48872266+ValKmjolnir@users.noreply.github.com> Date: Thu, 17 Oct 2019 23:18:45 +0800 Subject: [PATCH] Update & bug fixed --- version1.1/main.cpp | 4 +- version1.1/nasal_parser.h | 377 ++++++++++++++++++++++---------------- 2 files changed, 220 insertions(+), 161 deletions(-) diff --git a/version1.1/main.cpp b/version1.1/main.cpp index c25dc18..cc960a6 100644 --- a/version1.1/main.cpp +++ b/version1.1/main.cpp @@ -78,7 +78,9 @@ int main() pas.parse_main_work(); if(!pas.get_error_num()) { - ; + gen.set_ast_empty(); + gen.gen_process(lex.return_list()); + gen.gen_main_work(); } } else diff --git a/version1.1/nasal_parser.h b/version1.1/nasal_parser.h index f53c55a..10cfe4e 100644 --- a/version1.1/nasal_parser.h +++ b/version1.1/nasal_parser.h @@ -108,10 +108,7 @@ class nasal_parser void loop_expr(); bool else_if_check(); void if_else_expr(); - void add_sub_operator_expr(); void mul_div_operator_expr(); - void link_operator_expr(); - void compare_operator_expr(); void one_operator_expr(); void check_semi_at_end(); void statements_block(); @@ -133,13 +130,13 @@ void nasal_parser::return_expr() get_token(); switch(this_token.type) { + case __left_curve: case __number: case __string: case __id:parse.push(this_token);calculation_expr();break; case __func:function_generate_expr();break; case __left_bracket:list_generate_expr();break; case __left_brace:hash_generate_expr();break; - case __left_curve:in_curve_calc_expr();break; case __semi:parse.push(this_token);break; default: ++error; @@ -161,31 +158,34 @@ void nasal_parser::statements_block() get_token(); while(this_token.type!=__right_brace) { - token t; + //token t; switch(this_token.type) { case __var:definition_expr();check_semi_at_end();break; + case __sub_operator: + case __nor_operator: case __id: case __number: case __string:parse.push(this_token);calculation_expr();check_semi_at_end();break; case __if:parse.push(this_token);if_else_expr();break; case __left_curve: - t=this_token; - get_token(); - if(this_token.type==__var) - { - parse.push(t); - definition_expr(); - } - else - { - parse.push(this_token); - in_curve_calc_expr(); - } +// t=this_token; +// get_token(); +// if(this_token.type==__var) +// { +// parse.push(t); +// definition_expr(); +// } +// else +// { +// parse.push(this_token); +// parse.push(t); +// calculation_expr(); +// } + parse.push(this_token); + calculation_expr(); check_semi_at_end(); break; - case __sub_operator: - case __nor_operator:parse.push(this_token);calculation_expr();break; case __while: case __for: case __foreach: @@ -265,12 +265,12 @@ void nasal_parser::list_generate_expr() { switch(this_token.type) { + case __left_curve: case __number: case __string: case __id:parse.push(this_token);calculation_expr();break; case __left_bracket:list_generate_expr();break; case __left_brace:hash_generate_expr();break; - case __left_curve:in_curve_calc_expr();break; default: ++error; std::cout<<">>[Error] line "<>[Error] line "<>[Error] line "<>[Error] line "<>[Error] line "<>[Error] line "<>[Error] line "<>[Error] line "<>[Error] line "<>[Error] line "<>[Error] line "<>[Error] line "<>[Error] line "<>[Error] line "<>[Error] line "<>[Error] line "<>[Error] line "<