are you gonna consider the bad users that put something like "xy++"?

maybe you can create an array of invalid values, constants, and operators. then all you have to do is read char by char and look for it in an array.
if its in the invalid values you can raise a message. if its in the constants you can put it in a constants array, you do the same with the rest of the caracters...

damn! i really dont remember how to do that the "by the book" way.... maybe you can look on the web for "compilers". lexical, syntactic and semantical analysis and so on...

sorry if i misspelled some words