forked from xxq250/Nasal-Interpreter
Update lexer : char recognition
This commit is contained in:
@@ -6,14 +6,15 @@
|
||||
#include <list>
|
||||
#include <cstring>
|
||||
|
||||
#define OPERATOR 1 //<EFBFBD><EFBFBD><EFBFBD><EFBFBD> or <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define IDENTIFIER 2 //<EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʶ<EFBFBD><EFBFBD>
|
||||
#define NUMBER 3 //<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define RESERVEWORD 4 //<EFBFBD>ؼ<EFBFBD><EFBFBD><EFBFBD>
|
||||
#define STRING 5 //<EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define FAIL -1 //ʧ<EFBFBD><EFBFBD>
|
||||
#define SCANEND -2 //ɨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
#define ERRORFOUND -3 //<2F>쳣<EFBFBD><ECB3A3><EFBFBD><EFBFBD>
|
||||
#define OPERATOR 1 //operator
|
||||
#define IDENTIFIER 2 //id
|
||||
#define NUMBER 3 //number
|
||||
#define RESERVEWORD 4 //reserve word
|
||||
#define STRING 5 //string
|
||||
#define CHAR 6 //char
|
||||
#define FAIL -1 //fail
|
||||
#define SCANEND -2 //complete scanning
|
||||
#define ERRORFOUND -3 //error occurred
|
||||
|
||||
std::string reserve_word[15]=
|
||||
{
|
||||
@@ -218,13 +219,27 @@ class nasal_lexer
|
||||
}
|
||||
else if(temp=='(' || temp==')' || temp=='[' || temp==']' || temp=='{' ||
|
||||
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=='\'')
|
||||
{
|
||||
__token+=temp;
|
||||
++ptr;
|
||||
temp=source[ptr];
|
||||
__token+=temp;
|
||||
++ptr;
|
||||
temp=source[ptr];
|
||||
__token+=temp;
|
||||
++ptr;
|
||||
if(temp!='\'')
|
||||
std::cout<<">>[Lexer] Abnormal char type detected: "<<__token<<" ."<<std::endl;
|
||||
syn=CHAR;
|
||||
}
|
||||
else if(temp=='=' || temp=='+' || temp=='-' || temp=='*' || temp=='!' || temp=='/' || temp=='<' || temp=='>' || temp=='~')
|
||||
{
|
||||
syn=OPERATOR;
|
||||
@@ -346,6 +361,8 @@ class nasal_lexer
|
||||
std::cout<<"( ReserveWord | ";
|
||||
else if(temp.type==STRING)
|
||||
std::cout<<"( String | ";
|
||||
else if(temp.type==CHAR)
|
||||
std::cout<<"( Char | ";
|
||||
std::cout<<temp.content<<" )"<<std::endl;
|
||||
}
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user