Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct

John Nagle nagle at
Sat Mar 17 19:44:32 CET 2012

On 3/17/2012 9:31 AM, Antti J Ylikoski wrote:
> On 17.3.2012 17:47, Roy Smith wrote:
>> In article<gR09r.22645$I33.16090 at>,
>> Antti J Ylikoski<antti.ylikoski at> wrote:
>>> I came across the problem, which would be the clearest way to program
>>> such algorithms with a programming language such as Python, which has
>>> no GOTO statement.
>> Oh, my, I can't even begin to get my head around all the nested
>> conditionals. And that for a nearly trivial machine with only 5 states.
>> Down this path lies madness.

    Right.  Few programs should be written as state machines.
As a means of rewriting Knuth's algorithms, it's inappropriate.

    Some should.  LALR(1) parsers, such as what YACC and Bison
generate, are state machines.  They're huge collections of nested
switch statements.

    Python doesn't have a "switch" or "case" statement.  Which is
surprising, for a language that loves dictionary lookups.
You can create a dict full of function names and lambdas, but
it's clunky looking.

				John Nagle

More information about the Python-list mailing list