(Maybe off topic) Can someone explain what a finite state machine is?

Chris Angelico rosuav at gmail.com
Tue Jul 19 09:39:20 EDT 2011


On Tue, Jul 19, 2011 at 11:32 PM, Matty Sarro <msarro at gmail.com> wrote:
> Hey everyone. I am currently reading through an RFC, and it mentions
> that a client and server half of a transaction are embodied by finite
> state machines. I am reading through the wikipedia article for finite
> state machines, and sadly it's going a bit above my head. I don't
> really have a background in engineering, and would really love to
> understand what is being said. Does anyone have a simple way to
> explain it?

Sure.

You have a program (the machine) that can be in any one of a number of
states, and has well-defined rules that shift it from one state to
another. For instance, suppose you want to build a parser that handles
a simple "name = value" notation. Your states are:

1) Reading name
2) Reading value

In state #1, finding an equals sign transitions you to state #2.

In state #2, finding end-of-line transitions you to state #1 (and,
presumably, saves the name/value pair somewhere).

This is an extremely simple example with two states and two
transitions. It can get a lot more complicated than that!

Hope that helps!

Chris Angelico



More information about the Python-list mailing list