Update
This commit is contained in:
parent
225b079fc7
commit
493b09acfe
|
@ -11,14 +11,7 @@
|
|||
#define NUMBER 3 // number
|
||||
#define RESERVEWORD 4 // reserve word
|
||||
#define STRING 5 // string
|
||||
#define CHAR 6 // char
|
||||
#define CALL_LIST 7 // id[
|
||||
#define CALL_FUNC 8 // id(
|
||||
#define FUNC_HEAD 9 // func(
|
||||
#define DYNAMIC_ID 10 // id...
|
||||
#define IF_HEAD 11 // if (
|
||||
#define ELSIF_HEAD 12 // elsif (
|
||||
#define WHILE_HEAD 13 // while (
|
||||
#define DYNAMIC_ID 6 // id...
|
||||
#define FAIL -1 //fail
|
||||
#define SCANEND -2 //complete scanning
|
||||
#define ERRORFOUND -3 //error occurred
|
||||
|
@ -176,33 +169,11 @@ class nasal_lexer
|
|||
syn=IDENTIFIER;
|
||||
else
|
||||
syn=RESERVEWORD;
|
||||
if((syn==IDENTIFIER) && ((source[ptr]=='(') || (source[ptr]=='[') || (source[ptr]=='.' && source[ptr+1]=='.' && source[ptr+2]=='.')))
|
||||
if((syn==IDENTIFIER) && source[ptr]=='.' && source[ptr+1]=='.' && source[ptr+2]=='.')
|
||||
{
|
||||
__token+=source[ptr];
|
||||
if(source[ptr]=='(')
|
||||
syn=CALL_FUNC;
|
||||
else if(source[ptr]=='[')
|
||||
syn=CALL_LIST;
|
||||
else if(source[ptr]=='.' && source[ptr+1]=='.' && source[ptr+2]=='.')
|
||||
{
|
||||
__token+="..";
|
||||
syn=DYNAMIC_ID;
|
||||
ptr+=2;
|
||||
}
|
||||
++ptr;
|
||||
}
|
||||
else if((syn==RESERVEWORD) && ((__token=="func") || (__token=="if") || (__token=="elsif") || (__token=="while")) && (source[ptr]=='('))
|
||||
{
|
||||
if(__token=="func")
|
||||
syn=FUNC_HEAD;
|
||||
else if(__token=="if")
|
||||
syn=IF_HEAD;
|
||||
else if(__token=="elsif")
|
||||
syn=ELSIF_HEAD;
|
||||
else if(__token=="while")
|
||||
syn=WHILE_HEAD;
|
||||
__token+=source[ptr];
|
||||
++ptr;
|
||||
__token+="...";
|
||||
syn=DYNAMIC_ID;
|
||||
ptr+=3;
|
||||
}
|
||||
}
|
||||
else if(isNumber(temp))
|
||||
|
@ -263,17 +234,40 @@ class nasal_lexer
|
|||
}
|
||||
else if(temp=='\'')
|
||||
{
|
||||
syn=STRING;
|
||||
__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;
|
||||
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=='~')
|
||||
{
|
||||
|
@ -396,22 +390,8 @@ class nasal_lexer
|
|||
std::cout<<"( ReserveWord | ";
|
||||
else if(temp.type==STRING)
|
||||
std::cout<<"( String | ";
|
||||
else if(temp.type==CHAR)
|
||||
std::cout<<"( Char | ";
|
||||
else if(temp.type==CALL_LIST)
|
||||
std::cout<<"( Call list head | ";
|
||||
else if(temp.type==CALL_FUNC)
|
||||
std::cout<<"( Call func head | ";
|
||||
else if(temp.type==FUNC_HEAD)
|
||||
std::cout<<"( Func head | ";
|
||||
else if(temp.type==DYNAMIC_ID)
|
||||
std::cout<<"( Identifier | ";
|
||||
else if(temp.type==IF_HEAD)
|
||||
std::cout<<"( If head | ";
|
||||
else if(temp.type==ELSIF_HEAD)
|
||||
std::cout<<"( Elsif head | ";
|
||||
else if(temp.type==WHILE_HEAD)
|
||||
std::cout<<"( While head | ";
|
||||
std::cout<<temp.content<<" )"<<std::endl;
|
||||
}
|
||||
return;
|
||||
|
|
|
@ -8,30 +8,28 @@ enum token_type
|
|||
{
|
||||
__stack_end=1,
|
||||
__equal,// =
|
||||
__cmp_equal,// ==
|
||||
__cmp_not_equal,// !=
|
||||
__cmp_equal,__cmp_not_equal,// == !=
|
||||
__cmp_less,__cmp_less_or_equal,// < <=
|
||||
__cmp_more,__cmp_more_or_equal,// > >=
|
||||
__and_operator,__or_operator,__nor_operator,// and or !
|
||||
__add_operator,__sub_operator,__mul_operator,__div_operator,__link_operator,// + - * / ~
|
||||
__add_equal,__sub_equal,__mul_equal,__div_equal,__link_equal,// += -= *= /= ~=
|
||||
__add_operator,__sub_operator,// + -
|
||||
__mul_operator,__div_operator,__link_operator,// * / ~
|
||||
__add_equal,__sub_equal,// += -=
|
||||
__mul_equal,__div_equal,__link_equal,// *= /= ~=
|
||||
__left_brace,__right_brace,// {}
|
||||
__left_bracket,__right_bracket,// []
|
||||
__left_curve,__right_curve,// ()
|
||||
__semi,// ;
|
||||
__comma,// ,
|
||||
__colon,// :
|
||||
__dot,// .
|
||||
__var,
|
||||
__func,
|
||||
__id,__dynamic_id,
|
||||
__return,
|
||||
__semi,__comma,__colon,__dot,// ; , : .
|
||||
|
||||
__var,__func,__return,
|
||||
__if,__elsif,__else,
|
||||
__continue,__break,__for,__forindex,__foreach,__while,
|
||||
__id,__dynamic_id,
|
||||
__continue,__break,
|
||||
__for,__forindex,__foreach,__while,
|
||||
//end of operators & reserve words
|
||||
__two_operator,
|
||||
__scalar,__data_list,
|
||||
__number,__string,__char,
|
||||
__number,__string,
|
||||
__list,
|
||||
__hash,
|
||||
__hash_member,__hash_member_list,
|
||||
|
@ -81,7 +79,6 @@ cmp_seq par[]=
|
|||
|
||||
{{__number},__scalar},
|
||||
{{__string},__scalar},
|
||||
{{__char},__scalar},
|
||||
{{__calculation},__scalar},
|
||||
|
||||
{{__call_list},__call},
|
||||
|
@ -442,9 +439,6 @@ void print_token(int type)
|
|||
case __string:
|
||||
context="string";
|
||||
break;
|
||||
case __char:
|
||||
context="char";
|
||||
break;
|
||||
case __continue:
|
||||
context="continue";
|
||||
break;
|
||||
|
@ -818,14 +812,12 @@ class nasal_parser
|
|||
else if((*i).content==".")
|
||||
temp_parse.type=__dot;
|
||||
}
|
||||
else if(((*i).type==NUMBER) || ((*i).type==STRING) || ((*i).type==CHAR))
|
||||
else if(((*i).type==NUMBER) || ((*i).type==STRING))
|
||||
{
|
||||
if((*i).type==NUMBER)
|
||||
temp_parse.type=__number;
|
||||
else if((*i).type==STRING)
|
||||
temp_parse.type=__string;
|
||||
else if((*i).type==CHAR)
|
||||
temp_parse.type=__char;
|
||||
}
|
||||
else if(((*i).content=="+") || ((*i).content=="-") || ((*i).content=="*") || ((*i).content=="/") || ((*i).content=="~") || ((*i).content=="!"))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue