[LC++]State Machines
Roberto Diaz
rdiazmartin at vivaldi.dhis.org
Mon Dec 17 06:57: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
What about to make a "state" class containing something like this:
state states[NENSTATES];
// init the state instances with tables like this
SYMBOL LOAD
a 1
b 23
c 15
.... so on ..
you can start your machine just this way
states[0].take (symbol);
and
void state::take (symbol s)
{
next_state = lookup_in_my_table (s);
if (!next_state) error ("this is not a language parsed by me");
next_state->take (symbol);
}
Regards
Roberto
More information about the tuxCPProgramming
mailing list