[LC++]State Machines

Manu Anand badboyanand at yahoo.com
Mon Dec 17 23:05:04 UTC 2001


--- Roberto Diaz <rdiazmartin at vivaldi.dhis.org> wrote:
> > 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 easier to do so using array of function pointers

-Manu



__________________________________________________
Do You Yahoo!?
Check out Yahoo! Shopping and Yahoo! Auctions for all of
your unique holiday gifts! Buy at http://shopping.yahoo.com
or bid at http://auctions.yahoo.com



More information about the tuxCPProgramming mailing list