hex and oct number can be recognized

This commit is contained in:
Valk Richard Li 2019-08-24 07:37:18 -05:00 committed by GitHub
parent 01bfda8f5e
commit 09685f4223
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 45 additions and 6 deletions

View File

@ -40,6 +40,16 @@ bool isNumber(char t)
return (('0'<=t) && (t<='9')); 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 class resource_programme_process
{ {
private: private:
@ -161,20 +171,49 @@ class nasal_lexer
} }
else if(isNumber(temp)) else if(isNumber(temp))
{ {
int PointCnt=0; if((source[ptr]=='0') && (source[ptr+1]=='x'))
while(isNumber(temp))
{ {
__token+=temp; __token+=source[ptr];
++ptr; __token+=source[ptr+1];
ptr+=2;
temp=source[ptr]; temp=source[ptr];
if(temp=='.' && !PointCnt) while(isNumber(temp) || isHex(temp))
{ {
++PointCnt;
__token+=temp; __token+=temp;
++ptr; ++ptr;
temp=source[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; syn=NUMBER;
} }
else if(temp=='(' || temp==')' || temp=='[' || temp==']' || temp=='{' || else if(temp=='(' || temp==')' || temp=='[' || temp==']' || temp=='{' ||