From 150135a73332dda63d0449e64b5fe93b3898ddb8 Mon Sep 17 00:00:00 2001 From: Valk Richard Li <48872266+ValKmjolnir@users.noreply.github.com> Date: Thu, 18 Jun 2020 08:54:54 -0700 Subject: [PATCH] update --- version3.0/nasal.ebnf | 2 +- version3.0/nasal_enum.h | 2 ++ version3.0/nasal_parse.h | 53 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/version3.0/nasal.ebnf b/version3.0/nasal.ebnf index e93e53e..fcf370d 100644 --- a/version3.0/nasal.ebnf +++ b/version3.0/nasal.ebnf @@ -111,7 +111,7 @@ while_loop::= while '(' calculation ')' expressions ; for_loop::= - for '(' [definition] ';' [calculation] ';' [calculation] ')' expressions + for '(' [definition|calculation] ';' [calculation] ';' [calculation] ')' expressions ; forei_loop::= (forindex | foreach) '(' (definition | assignment) ';' calculation ')' expressions diff --git a/version3.0/nasal_enum.h b/version3.0/nasal_enum.h index 3840461..1486d5d 100644 --- a/version3.0/nasal_enum.h +++ b/version3.0/nasal_enum.h @@ -52,6 +52,7 @@ enum parse_error lack_scalar, lack_identifier, lack_calculation, + lack_token, }; void error_info(int line,int error_type,std::string error_str="") @@ -74,6 +75,7 @@ void error_info(int line,int error_type,std::string error_str="") case lack_scalar: detail="expected scalar here."; break; case lack_identifier: detail="expected identifier here."; break; case lack_calculation: detail="expected arithmetic-expression here."; break; + case lack_token: detail="expected \'"+error_str+"\' here."; break; } std::cout<tok_list_size) + { + ++error; + error_info(tok_list.back().line,lack_token,"loop"); + return node; + } switch(tok_list[ptr].type) { case tok_while: node=while_loop(); break; @@ -750,21 +756,68 @@ nasal_ast nasal_parse::loop() nasal_ast nasal_parse::while_loop() { nasal_ast node; + node.set_line(tok_list[ptr].line); + node.set_type(ast_while); + ++ptr; + if(ptrtok_list_size || tok_list[ptr].type!=tok_right_curve) + { + ++error; + error_info(node.get_line(),lack_right_curve); + } + ++ptr; + node.add_child(exprs_gen()); return node; } nasal_ast nasal_parse::for_loop() { nasal_ast node; + node.set_line(tok_list[ptr].line); + node.set_type(ast_for); + ++ptr; + if(ptr>tok_list_size || tok_list[ptr].type!=tok_left_curve) + { + ++error; + error_info(node.get_line(),lack_left_curve); + } + ++ptr; + // unfinished return node; } nasal_ast nasal_parse::forei_loop() { nasal_ast node; + node.set_line(tok_list[ptr].line); + switch(tok_list[ptr].type) + { + case tok_forindex: node.set_type(ast_forindex);break; + case tok_foreach: node.set_type(ast_foreach); break; + } + ++ptr; + if(ptr>tok_list_size || tok_list[ptr].type!=tok_left_curve) + { + ++error; + error_info(node.get_line(),lack_left_curve); + } + ++ptr; + // unfinished return node; } nasal_ast nasal_parse::conditional() { nasal_ast node; + node.set_line(tok_list[ptr].line); + node.set_type(ast_if); return node; } nasal_ast nasal_parse::continue_expr()