From e2ee9cff4c77859137f0b9527e8c0b3a47970ad1 Mon Sep 17 00:00:00 2001 From: Valk Richard Li <48872266+ValKmjolnir@users.noreply.github.com> Date: Sat, 13 Feb 2021 14:37:21 +0800 Subject: [PATCH] update --- nasal_codegen.h | 4 ++++ nasal_lexer.h | 29 ++++++++++++++++------------- nasal_parse.h | 13 +++++++++++++ 3 files changed, 33 insertions(+), 13 deletions(-) diff --git a/nasal_codegen.h b/nasal_codegen.h index 523b28e..9d77022 100644 --- a/nasal_codegen.h +++ b/nasal_codegen.h @@ -776,6 +776,10 @@ void nasal_codegen::calculation_gen(nasal_ast& ast) calculation_gen(ast.get_children()[0]); gen(op_unot,0); break; + case ast_definition: + single_def(ast); + call_id(ast.get_children()[0]); + break; } return; } diff --git a/nasal_lexer.h b/nasal_lexer.h index 19afd0e..2d6fa4d 100644 --- a/nasal_lexer.h +++ b/nasal_lexer.h @@ -104,7 +104,7 @@ private: std::vector res; std::vector token_list; int get_token_type(std::string); - void die(std::string,int,int); + void die(std::string,std::string,int,int); std::string identifier_gen(); std::string number_gen(); std::string string_gen(); @@ -148,10 +148,13 @@ int nasal_lexer::get_token_type(std::string tk_str) return tok_null; } -void nasal_lexer::die(std::string error_info,int line=-1,int column=-1) +void nasal_lexer::die(std::string code,std::string error_info,int line=-1,int column=-1) { ++error; - std::cout<<">> [lexer] line "<> [lexer] line "<=res_size) { line_code+=token_str; - die("["+line_code+"_] incorrect number.",line,line_code.length()); + die(line_code,"incorrect number.",line,line_code.length()); return "0"; } while(ptr=res_size) { line_code+=token_str; - die("["+line_code+"_] incorrect number.",line,line_code.length()); + die(line_code,"incorrect number.",line,line_code.length()); return "0"; } if(ptr=res_size) { line_code+=token_str; - die("["+line_code+"_] incorrect number.",line,line_code.length()); + die(line_code,"incorrect number.",line,line_code.length()); return "0"; } while(ptr=res_size) - die("["+line_code+"_] get EOF when generating string.",line,line_code.length()); + die(line_code,"get EOF when generating string.",line,line_code.length()); return token_str; } @@ -345,7 +348,7 @@ void nasal_lexer::scanner() line_code+=res[ptr]; token new_token(line,get_token_type(token_str),token_str); if(!new_token.type) - die("["+line_code+"_] incorrect operator.",line,line_code.length()); + die(line_code,"incorrect operator.",line,line_code.length()); token_list.push_back(new_token); ++ptr; } @@ -380,7 +383,7 @@ void nasal_lexer::scanner() else { line_code+=res[ptr++]; - die("["+line_code+"_] unknown character.",line,line_code.length()); + die(line_code,"unknown character.",line,line_code.length()); } } token tk(line,tok_eof,""); diff --git a/nasal_parse.h b/nasal_parse.h index f6a627a..87b95ec 100644 --- a/nasal_parse.h +++ b/nasal_parse.h @@ -150,6 +150,8 @@ void nasal_parse::die(int line,std::string info) { ++error; std::cout<<">> [parse] line "<