From f235c168cac56533d2b6423fda45adabff07547a Mon Sep 17 00:00:00 2001 From: Valk Richard Li <48872266+ValKmjolnir@users.noreply.github.com> Date: Mon, 13 Jul 2020 03:05:02 -0700 Subject: [PATCH] update --- version3.0/main.cpp | 12 +++-- version3.0/nasal_enum.h | 2 +- version3.0/nasal_parse.h | 95 +++++++++++++++++++++++++++++++--------- 3 files changed, 83 insertions(+), 26 deletions(-) diff --git a/version3.0/main.cpp b/version3.0/main.cpp index 8b2a4be..b5497bf 100644 --- a/version3.0/main.cpp +++ b/version3.0/main.cpp @@ -43,8 +43,10 @@ void del_func() void lex_func() { lexer.scanner(resource.get_file()); - if(!lexer.get_error()) lexer.print_token(); - else std::cout<<">> [lexer] error occurred,stop.\n"; + if(!lexer.get_error()) + lexer.print_token(); + else + std::cout<<">> [lexer] error occurred,stop.\n"; return; } @@ -55,9 +57,11 @@ void par_func() { parse.set_toklist(lexer.get_token_list()); parse.main_process(); - if(parse.get_error()) std::cout<<">> [parse] error occurred,stop.\n"; + if(parse.get_error()) + std::cout<<">> [parse] error occurred,stop.\n"; } - else std::cout<<">> [lexer] error occurred,stop.\n"; + else + std::cout<<">> [lexer] error occurred,stop.\n"; return; } diff --git a/version3.0/nasal_enum.h b/version3.0/nasal_enum.h index 06bb846..56e91e8 100644 --- a/version3.0/nasal_enum.h +++ b/version3.0/nasal_enum.h @@ -34,7 +34,7 @@ enum ast_node ast_for,ast_forindex,ast_foreach,ast_while, ast_if,ast_elsif,ast_else, ast_multi_id,ast_multi_scalar, - ast_definition,ast_multi_assign,ast_calculation, + ast_definition,ast_multi_assign, ast_continue,ast_break,ast_return, }; diff --git a/version3.0/nasal_parse.h b/version3.0/nasal_parse.h index 00d6cb7..f0d2ee4 100644 --- a/version3.0/nasal_parse.h +++ b/version3.0/nasal_parse.h @@ -78,6 +78,9 @@ private: nasal_ast call_func(); nasal_ast subvec(); nasal_ast definition(); + nasal_ast normal_def(); + nasal_ast var_incurve_def(); + nasal_ast var_outcurve_def(); nasal_ast multi_id(); nasal_ast multi_scalar(); nasal_ast multi_assgin(); @@ -198,7 +201,7 @@ bool nasal_parse::check_special_call() int check_ptr=ptr+1; int curve_cnt=1; bool ret=false; - while(check_ptr=tok_list_size || tok_list[ptr].type!=tok_comma || tok_list[ptr].type!=tok_right_curve) + else if(ptr>=tok_list_size || (tok_list[ptr].type!=tok_comma && tok_list[ptr].type!=tok_right_curve)) { ++error; error_info(error_line,lack_comma); + break; } } if(ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve) @@ -841,28 +849,73 @@ nasal_ast nasal_parse::definition() if(tok_list[ptr].type==tok_var) { ++ptr; - // unfinished + switch(tok_list[ptr].type) + { + case tok_identifier:node.add_child(normal_def()); break; + case tok_left_curve:node.add_child(var_outcurve_def()); break; + default: + ++error; + error_info(error_line,lack_identifier); + return node; + } } else if(tok_list[ptr].type==tok_left_curve) + node.add_child(var_incurve_def()); + ++ptr; + if(ptr>=tok_list_size || tok_list[ptr].type!=tok_equal) { - ++ptr; - node.add_child(multi_id()); - ++ptr; - if(ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve) - { - ++error; - error_info(error_line,lack_right_curve); - return node; - } - ++ptr; - if(ptr>=tok_list_size || tok_list[ptr].type!=tok_equal) - { - ++error; - error_info(error_line,lack_equal); - return node; - } - ++ptr; - // unfinished + ++error; + error_info(error_line,lack_equal); + return node; + } + ++ptr; + // unfinished + return node; +} +nasal_ast nasal_parse::normal_def() +{ + nasal_ast node; + node.set_line(tok_list[ptr].line); + node.set_str(tok_list[ptr].str); + node.set_type(ast_identifier); + return node; +} +nasal_ast nasal_parse::var_incurve_def() +{ + nasal_ast node; + ++ptr;// check_multi_definition will check the 'var' + ++ptr; + if(ptr>=tok_list_size || tok_list[ptr].type!=tok_identifier) + { + ++error; + error_info(error_line,lack_identifier); + return node; + } + node=multi_id(); + ++ptr; + if(ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve) + { + ++error; + error_info(error_line,lack_right_curve); + } + return node; +} +nasal_ast nasal_parse::var_outcurve_def() +{ + nasal_ast node; + ++ptr; + if(ptr>=tok_list_size || tok_list[ptr].type!=tok_identifier) + { + ++error; + error_info(error_line,lack_identifier); + return node; + } + node=multi_id(); + ++ptr; + if(ptr>=tok_list_size || tok_list[ptr].type!=tok_right_curve) + { + ++error; + error_info(error_line,lack_right_curve); } return node; }