diff --git a/version0.15/version0.15.2/nasal_lexer.h b/version0.15/version0.15.2/nasal_lexer.h deleted file mode 100644 index 40dd597..0000000 --- a/version0.15/version0.15.2/nasal_lexer.h +++ /dev/null @@ -1,408 +0,0 @@ -#ifndef __NASAL_LEXER_H__ -#define __NASAL_LEXER_H__ - -#include -#include -#include -#include - -#define OPERATOR 1 // operator -#define IDENTIFIER 2 // id -#define NUMBER 3 // number -#define RESERVEWORD 4 // reserve word -#define STRING 5 // string -#define DYNAMIC_ID 6 // id... -#define FAIL -1 //fail -#define SCANEND -2 //complete scanning -#define ERRORFOUND -3 //error occurred - -std::string reserve_word[15]= -{ - "for","foreach","forindex","while", - "var","func","break","continue","return", - "if","else","elsif","nil","and","or" -}; - -int isReserveWord(std::string &p) -{ - for(int i=0;i<15;++i) - if(reserve_word[i]==p) - return i+1; - return FAIL; -} - -bool isLetter(char t) -{ - return (('a'<=t) && (t<='z') || ('A'<=t) && (t<='Z')); -} - -bool isNumber(char t) -{ - return (('0'<=t) && (t<='9')); -} - -bool isHex(char t) -{ - return ((('0'<=t) && (t<='9')) || (('a'<=t) && (t<='f'))); -} - -bool isOct(char t) -{ - return (('0'<=t) && (t<='7')); -} - -class resource_programme_process -{ - private: - char *resource; - public: - resource_programme_process() - { - resource=NULL; - resource=new char[16777216]; - } - ~resource_programme_process() - { - if(resource) - delete []resource; - } - char* use_file() - { - return resource; - } - void input_file(std::string& filename) - { - std::ifstream fin(filename); - if(fin.fail()) - { - std::cout<<">>[Error] Cannot load file: "< lexer; - public: - void scanner(int &syn,const char* source,std::string &__token,int &ptr,int &line) - { - char temp; - temp=source[ptr]; - while(temp==' ' || temp=='\n' || temp=='\t' || temp=='\r' || temp<0 || temp>127) - { - ++ptr; - if(temp=='\n') - ++line; - temp=source[ptr]; - } - __token=""; - if(isLetter(temp) || temp=='_') - { - __token+=temp; - ++ptr; - temp=source[ptr]; - while(isLetter(temp) || isNumber(temp) || temp=='_') - { - __token+=temp; - ++ptr; - temp=source[ptr]; - } - syn=isReserveWord(__token); - if(syn==FAIL) - syn=IDENTIFIER; - else - syn=RESERVEWORD; - if((syn==IDENTIFIER) && source[ptr]=='.' && source[ptr+1]=='.' && source[ptr+2]=='.') - { - __token+="..."; - syn=DYNAMIC_ID; - ptr+=3; - } - } - else if(isNumber(temp)) - { - if((source[ptr]=='0') && (source[ptr+1]=='x')) - { - __token+=source[ptr]; - __token+=source[ptr+1]; - ptr+=2; - temp=source[ptr]; - while(isNumber(temp) || isHex(temp)) - { - __token+=temp; - ++ptr; - temp=source[ptr]; - } - } - else if((source[ptr]=='0') && (source[ptr+1]=='o')) - { - __token+=source[ptr]; - __token+=source[ptr+1]; - ptr+=2; - temp=source[ptr]; - while(isNumber(temp) || isOct(temp)) - { - __token+=temp; - ++ptr; - temp=source[ptr]; - } - } - else - { - int PointCnt=0; - while(isNumber(temp)) - { - __token+=temp; - ++ptr; - temp=source[ptr]; - if(temp=='.' && !PointCnt) - { - ++PointCnt; - __token+=temp; - ++ptr; - temp=source[ptr]; - } - } - } - syn=NUMBER; - } - else if(temp=='(' || temp==')' || temp=='[' || temp==']' || temp=='{' || - temp=='}' || temp==',' || temp==';' || temp=='|' || temp==':' || - temp=='?' || temp=='.' || temp=='`' || temp=='&'|| - temp=='%' || temp=='$' || temp=='^') - { - __token+=temp; - ++ptr; - syn=OPERATOR; - } - else if(temp=='\'') - { - syn=STRING; - __token+=temp; - ++ptr; - temp=source[ptr]; - while(temp!='\'') - { - if(temp=='\\') - { - __token+=temp; - - ++ptr; - temp=source[ptr]; - __token+=temp; - - ++ptr; - temp=source[ptr]; - } - else - { - __token+=temp; - ++ptr; - temp=source[ptr]; - } - if(temp==0 || temp=='\n') - break; - } - //add the last char \" - if(temp=='\'') - { - __token+=temp; - ++ptr; - } - else - __token+=" __missing_end_of_string"; - } - else if(temp=='=' || temp=='+' || temp=='-' || temp=='*' || temp=='!' || temp=='/' || temp=='<' || temp=='>' || temp=='~') - { - syn=OPERATOR; - __token+=temp; - ++ptr; - temp=source[ptr]; - if(temp=='=') - { - __token+=temp; - ++ptr; - } - } - else if(temp=='\\') - { - syn=OPERATOR; - __token+=temp; - ++ptr; - temp=source[ptr]; - if(temp=='=' || temp=='n' || temp=='t' || temp=='r' || temp=='\\' || temp=='\'' || temp=='\"') - { - __token+=temp; - ++ptr; - } - } - else if(temp=='\"') - { - syn=STRING; - __token+=temp; - ++ptr; - temp=source[ptr]; - while(temp!='\"') - { - if(temp=='\\') - { - __token+=temp; - - ++ptr; - temp=source[ptr]; - __token+=temp; - - ++ptr; - temp=source[ptr]; - } - else - { - __token+=temp; - ++ptr; - temp=source[ptr]; - } - if(temp==0 || temp=='\n') - break; - } - //add the last char \" - if(temp=='\"') - { - __token+=temp; - ++ptr; - } - else - __token+=" __missing_end_of_string"; - } - else if(temp==0) - { - syn=SCANEND; - return; - } - else - { - syn=FAIL; - std::cout<<">>[Error] Unexpected error occurred: "<>[Error] Cannot identify "<>[Lexer] max size: "<0)//all Syn type is larger than zero - { - temp.line=line; - temp.type=syn; - temp.content=__token; - lexer.push_back(temp); - } - } - std::cout<<">>[Lexer] Complete scanning."<::iterator i=lexer.begin();i!=lexer.end();++i) - { - temp=*i; - std::cout<<"line "<& return_list() - { - return lexer; - } -}; - - - - -#endif