[comp.lang.prolog] Running backwards

naim@uswat.uswest.com (Naim Abdullah) (09/17/90)

Jonathan.Bowen@prg.oxford.ac.uk (Jonathan Bowen) writes of a compiler that
he has written in Prolog and speculates of using it as a disassembler:

>Prolog in principle
>can run backwards, so it may be possible to supply some object code and
>produce a high-level program or programs as output. The main problem is
>running the necessary arithmetic backwards (i.e. avoiding the use of
>"is") and I am currently looking into this. Has anyone else done any
>similar work or can anyone supply any useful references?

The CLP(R) interpreter can do a better job of running backwards than
vanilla Prolog interpreters. This is because it views arithmetic
predicates as constraints rather than unidirectional special predicates.

Try using CLP(R) in order to go backwards. You may be surprised.

The CLP(R) interpreter can be obtained from Monash University. A CLP(R) compiler
has also been written at IBM and is available free of charge for academic
research (this is recollection of the license; do not quote me on it).

          Naim

Jonathan.Bowen@prg.oxford.ac.uk (Jonathan Bowen) (09/18/90)

In article <11138@uswat.UUCP> naim@uswat.uswest.com (Naim Abdullah) writes:
>The CLP(R) interpreter can do a better job of running backwards than
>vanilla Prolog interpreters. This is because it views arithmetic
>predicates as constraints rather than unidirectional special predicates.

Yes, I heard about Constraint Logic Programming at the recent PLILP'90
workshop in Linkoping, and thought there that it could be applied to
reverse compilation.  Wouldn't I need a CLP(N) rather than CLP(R)
interpreter for my application, or isn't there a problem sticking to
natural numbers in CLP(R)?

I have now converted my original (very simple) compiler (if, while,
assignment, skip, sequential composition, variable declaration) to a
decompiler which successfully takes flat object code and a symbol table
and produces all possible programs (apart from redundant skips and
variable declarations) as output, at least for small examples.

I haven't yet produced a single Prolog program which works *both*,
but maybe this is not useful.

--
Jonathan Bowen, <Jonathan.Bowen@prg.oxford.ac.uk>, Oxford University.