From 24bfbd8f0ee33448613a8c699c9375aa22997ac6 Mon Sep 17 00:00:00 2001 From: Valk Richard Li <48872266+ValKmjolnir@users.noreply.github.com> Date: Fri, 29 May 2020 10:25:48 -0700 Subject: [PATCH] update --- version2.0/nasal_lexer.h | 63 ++++++++++++++++++---------------------- 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/version2.0/nasal_lexer.h b/version2.0/nasal_lexer.h index b138f40..97fa384 100644 --- a/version2.0/nasal_lexer.h +++ b/version2.0/nasal_lexer.h @@ -174,42 +174,40 @@ void resource_file::print_resource() int size=source_code.size(); int line=1; std::cout<=0 && unicode_str.length()) { - // print unicode - std::string tmp=""; - for(;i=0) break; - tmp.push_back(source_code[i]); - } - std::cout<& res,int& ptr,int& line) { + int res_size=res.size(); std::string token_str=""; - while(IS_IDENTIFIER_BODY(res[ptr])) + while(ptr=res.size()) break; } // check dynamic identifier "..." - if(ptr+2& res,int& ptr,int& lin std::string nasal_lexer::number_gen(std::vector& res,int& ptr,int& line) { + int res_size=res.size(); bool scientific_notation=false;// numbers like 1e8 are scientific_notation std::string token_str=""; - while(IS_NUMBER_BODY(res[ptr])) + while(ptr& res,int& ptr,int& line) break; } ++ptr; - if(ptr>=res.size()) - break; } - if(scientific_notation && ptr& res,int& ptr,int& line) } std::string nasal_lexer::string_gen(std::vector& res,int& ptr,int& line) { + int res_size=res.size(); std::string token_str=""; char str_begin=res[ptr]; ++ptr; - if(ptr>=res.size()) return token_str; - while(ptr=res_size) return token_str; + while(ptr& res,int& ptr,int& line) } } ++ptr; - if(ptr>=res.size()) break; } // check if this string ends with a " or ' - if(ptr>=res.size()) + if(ptr>=res_size) { ++error; std::cout<<">> [Lexer] line "<& res) detail_token_list.clear(); error=0; - int line=1; + int line=1,ptr=0,res_size=res.size(); std::string token_str; - int ptr=0; - while(ptr=res.size()) break; + if(ptr>=res_size) break; if(IS_IDENTIFIER_HEAD(res[ptr])) { token_str=identifier_gen(res,ptr,line); @@ -399,7 +394,7 @@ void nasal_lexer::scanner(std::vector& res) else if(IS_NOTE_HEAD(res[ptr])) { // avoid note - while(ptrstr; - int strback=tempstr.length()-1; - if(tempstr.length()>3 &&tempstr[strback]=='.' && tempstr[strback-1]=='.' && tempstr[strback-2]=='.') + int len=tempstr.length(),strback=tempstr.length()-1; + if(tempstr[strback]=='.' && tempstr[strback-1]=='.' && tempstr[strback-2]=='.') { detail_token.str=""; - for(int j=0;j