Created
January 16, 2015 09:41
-
-
Save thevar1able/2999caef505dc55e935d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
token tryId(std::string str) | |
{ | |
token result ("INVALID", ""); | |
int state = 0; | |
for(auto x : str) | |
{ | |
switch(state) | |
{ | |
case 0: | |
if((x >= 'A' && x <= 'Z') || (x >= 'a' && x <= 'z') || x == '_') | |
{ | |
result.text.push_back(x); | |
state = 1; | |
} else return result; | |
break; | |
case 1: | |
if((x >= 'A' && x <= 'Z') || (x >= 'a' && x <= 'z') || x == '_' || (x >= '0' && x <= '9')) | |
{ | |
result.text.push_back(x); | |
} else return result; | |
break; | |
} | |
} | |
result.type = "ID"; | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment