in reply to Are state machines just for parsing?
#!/usr/bin/perl -w # State transition table # # Current Inputs Next Action $next{'initial'}{'left' } = ['red', sub { print "Red \n"} ]; $next{'initial'}{'right'} = ['blue', sub { print "Blue\n"} ]; $next{'red'} {'left' } = ['blue', sub { print "Blue\n"} ]; $next{'red'} {'right'} = ['end', sub { print "End \n"} ]; $next{'blue'} {'left' } = ['blue', sub { print "Blue\n"} ]; $next{'blue'} {'right'} = ['red', sub { print "Red \n"} ]; $next{'end'} {'left' } = ['end', sub { print "End \n"} ]; $next{'end'} {'right'} = ['end', sub { print "End \n"} ]; @arbitrary_inputs = qw/left left right left left right right left/; $state = 'initial'; for (@arbitrary_inputs) { $action = $next{$state}{$_}->[1]; $action->(); $state = $next{$state}{$_}->[0]; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Are state machines just for parsing?
by samtregar (Abbot) on Dec 08, 2004 at 02:55 UTC | |
by Anonymous Monk on Aug 12, 2005 at 16:59 UTC | |
|
Re^2: Are state machines just for parsing?
by sleepingsquirrel (Chaplain) on Dec 08, 2004 at 16:47 UTC |