[LC++]State Machines

Paul M Foster paulf at quillandmouse.com
Tue Dec 11 15:28:04 UTC 2001


I'm just playing with some ideas here, and looking for feedback. Anyone
ever heard of doing a state machine as a set of classes, with each state
as a separate class? I'm thinking about parsing a file containing
keywords and parameters. (Yes, I know you can use lex and yacc for this;
I'm just kicking around ideas.)

I haven't fleshed this out fully in my mind, but there might be a base
class that has a get_next_token() method. Each class inherits from the
base class and handles a specific state. The state class object would
process whatever it needed to, and then have a next() method that called
the get_next_token() method, interpreted the token, and determined what
the next state would be, etc.

Is this a really horrible idea? Intriguing?

Paul




More information about the tuxCPProgramming mailing list