In article <[email protected]>,
Tim Chase <[email protected]> wrote:
> In the past, I've done NFA with a state machine:
What I've done at times is have each state be a function. The function
returns an (output, next_state) tuple, and the main loop becomes something
like this:
state = start
for input in whatever:
output, state = state(input)
and the states look like:
def start(input):
next_state = blah
output = blah
return (output, next_state)
It's not always the right organization (and is almost certainly not for
machines with large numbers of states), but I've found it useful for a lot
of ad-hoc file parsing that I've done.
--
http://mail.python.org/mailman/listinfo/python-list