Skip to content

Instantly share code, notes, and snippets.

@thevar1able
Created January 16, 2015 09:41
Show Gist options
  • Save thevar1able/2999caef505dc55e935d to your computer and use it in GitHub Desktop.
Save thevar1able/2999caef505dc55e935d to your computer and use it in GitHub Desktop.
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