Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #21870

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

Date 2012-03-19 02:02 +0100
From Kiuhnm <kiuhnm03.4t.yahoo.it>
Newsgroups comp.lang.python
Subject Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct
References (2 earlier) <mailman.758.1331996530.3037.python-list@python.org> <4f64a9e5$0$1385$4fafbaef@reader2.news.tin.it> <mailman.759.1331999612.3037.python-list@python.org> <4f64d00a$0$1390$4fafbaef@reader1.news.tin.it> <mailman.768.1332026927.3037.python-list@python.org>
Message-ID <4f6685a2$0$1389$4fafbaef@reader2.news.tin.it> (permalink)
Organization TIN.IT (http://www.tin.it)

Show all headers | View raw


On 3/18/2012 0:28, Michael Torrie wrote:
> I am familiar with how one
> might implement a decompiler, as well as a compiler (having written a
> simple one in the past), but even now I don't see a connection between a
> decompiler and the process of converting a knuth algorithm into a python
> python implementation.  I was hoping you would shed some light on that.
>   But alas, I'm not really as much of an "interested reader" as you would
> like me to be.

Many ASM languages don't have structured control flow statements but 
only jmps, which are roughly equivalent to gotos. A good decompiler will 
need to analize the net of jmps and try to rewrite the code using 
structured control flow statements.
The idea is to maximize readability, of course.

>> Here's an example of rewriting:
>> <snip>
>
> Thank you.  Your example makes more clear your assertion about "labels"
> and how really A1 and A5 were the only real labels in the example.
> Though I still do not really see why "states" is not a good equivalence
> for labels in this case.  As well, Roy's idea for doing the state
> machines, which works equally well as the nested if statements, is more
> pythonic, which is generally preferred in Python.

What I don't like about the entire issue is that (pseudo-)code shouldn't 
be cut and pasted or blindly ported to another language.
Python is a very expressive language. I don't think you like it when 
someone writes C code in Python. Now we're writing ASM code in Python!
If you want to emulate a DFA, do it, but if you want to implement an 
algorithm whose pseudo-code happens to use labels and gotos, please use 
higher-level control flow statements (unless you're pressed on time and 
you need it done yesterday, of course).

Regarding labels and state, I simply meant that they're completely 
different things, in fact this program has two labels but infinitely 
many states:
A1:  cur = cur + 1
A2:  goto A1
I was being pedantic, to say it your way ;)

Kiuhnm

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Antti J Ylikoski <antti.ylikoski@tkk.fi> - 2012-03-17 16:03 +0200
  Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Mel Wilson <mwilson@the-wire.com> - 2012-03-17 10:39 -0400
  Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Kiuhnm <kiuhnm03.4t.yahoo.it> - 2012-03-17 15:45 +0100
    Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Michael Torrie <torriem@gmail.com> - 2012-03-17 09:01 -0600
      Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Kiuhnm <kiuhnm03.4t.yahoo.it> - 2012-03-17 16:12 +0100
        Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Michael Torrie <torriem@gmail.com> - 2012-03-17 09:53 -0600
          Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Kiuhnm <kiuhnm03.4t.yahoo.it> - 2012-03-17 18:55 +0100
            Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Michael Torrie <torriem@gmail.com> - 2012-03-17 17:28 -0600
              Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-03-18 01:54 +0000
                Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-03-18 11:03 +0000
              Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Kiuhnm <kiuhnm03.4t.yahoo.it> - 2012-03-19 02:02 +0100
                Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-03-19 01:02 -0400
                Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Kiuhnm <kiuhnm03.4t.yahoo.it> - 2012-03-19 11:24 +0100
  Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Roy Smith <roy@panix.com> - 2012-03-17 11:47 -0400
    Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Antti J Ylikoski <antti.ylikoski@tkk.fi> - 2012-03-17 18:31 +0200
      Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct John Nagle <nagle@animats.com> - 2012-03-17 11:44 -0700
  Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Evan Driscoll <driscoll@cs.wisc.edu> - 2012-03-17 21:59 -0500
  Re: Programming D. E. Knuth in Python with the Deterministic Finite Automaton construct Albert van der Horst <albert@spenarnc.xs4all.nl> - 2012-03-18 11:08 +0000

csiph-web