That would probably be a good way to structure the core of the lexical analyzer.
Just to clean up your idea since he is using C++, he can use it like: Code: enum myTokens {RESERVED_WORD, OPERATOR, VARIABLE, STRING, INVALID, NUMBER};
enum myTokens token_type;
char* token;
while(token = getNextToken()) // Your token function, whatever it is
{
token_type = getTokenType(token); // Your token examining function
switch (token_type)
{
case RESERVED_WORD: // some code here
break;
case OPERATOR: // some code here
break;
/// etc, etc
default: // in case you got some kind of invalid data
}
}
__________________ Desktop machine: 2 x Opteron 246, Asus K8N-DL, 2GB PC3200 ECC Reg., XFX GeForce 6600GT, 74gb WD Raptor, 2 x 19\" LCDs, Windows XP x64
Server machine: Intel P4 3.0GHz 2MB EM64T, ECS i865pe, 1GB PC3200, 36gb WD Raptor, Windows Server 2003
Laptop: Dell Inspiron 9100 (Intel P4 3.2GHz 1MB Prescott, i865pe, 512MB PC3200, Mobility Radeon 9700, DVD+R/DL Burner), Windows XP
Linux: P3 450Mhz, 386MB ram, Slackware 10.1 (Running mySQL/Apache) |