It would be a bit of work, but reinventing the wheel is always great academically. You could probably do a keyword driven parsing rather than having to read a whole book.
Basically:
Code:
Token input = GetToken();
if (input == TOK_OPAREN)
push input;
else if (input == TOK_CLPAREN)
{
stackVal = pop;
if (stackVal != TOK_OPAREN)
Error("expected open parenthese\n");
}
else
{
switch(input)
{
case TOK_NUMOFSETS:
if ((input = GetToken()) != TOK_NUMBER)
Error("expected a number\n");
else
numOfSets = input.value;
break;
case other tokens ... etc.
default:
Error("Unknown keyword");
}
}
Where GetToken() is something like:
Code:
string = GetCharFromFile();
if (string == '(')
return(TOK_OPAREN);
else if (string == ')')
return(TOK_CLPAREN);
else
{
while (not a space and not a ')' and not a '(')
string += GetCharFromFile();
compare string to your stuff and return the correct token
}
Not the most efficient but simple and fairly easy to implement.
edit:
That input.value thing, make Token a struct and when you recognize a number just convert the string with atoi and put the result in input.value