Re: Using Prolog to Compile Things

JT <gkt37@dial.pipex.com>
22 May 1999 02:59:32 -0400

          From comp.compilers

Related articles
Using Prolog to Compile Things nickroberts@callnetuk.com (Nick Roberts) (1999-05-16)
Re: Using Prolog to Compile Things gsg@mimuw.edu.pl (1999-05-20)
Re: Using Prolog to Compile Things fjh@cs.mu.OZ.AU (1999-05-21)
Re: Using Prolog to Compile Things bmd@cs.kuleuven.ac.be (1999-05-21)
Re: Using Prolog to Compile Things anton@mips.complang.tuwien.ac.at (1999-05-22)
Re: Using Prolog to Compile Things gkt37@dial.pipex.com (JT) (1999-05-22)
Re: Using Prolog to Compile Things Daniel.Diaz@inria.fr (1999-05-22)
Re: Using Prolog to Compile Things bmd@cs.kuleuven.ac.be (1999-05-27)
Re: Using Prolog to Compile Things bromage@cs.mu.OZ.AU (1999-05-27)
Re: Using Prolog to Compile Things hunk@alpha1.csd.uwm.edu (1999-06-02)
Re: Using Prolog to Compile Things nickroberts@callnetuk.com (Nick Roberts) (1999-06-06)
Re: Using Prolog to Compile Things guerby@acm.org (Laurent Guerby) (1999-06-12)
| List of all articles for this month |

From: JT <gkt37@dial.pipex.com>
Newsgroups: comp.compilers
Date: 22 May 1999 02:59:32 -0400
Organization: UUNET WorldCom server (post doesn't reflect views of UUNET WorldCom
References: 99-05-069
Keywords: prolog

Nick Roberts wrote:


> Has anyone on this ng experience or knowledge of the use of Prolog to
> implement a native-code compiler for a typical high-level imperative
> language? I am toying with the idea of using Prolog for the lexer, the
> parser, the intermediate (library) code generator, and the end-code
> generator (and even, in effect, for linking!), i.e. the 'whole shebang'.
> I'm even toying with the idea of having (most) of the IDE written in Prolog,
> and thus tightly integrating the compiler and IDE.
>
> This is an open source project (possibly GPL or similar), and a bit
> experimental, and it's not a project that has a budget of millions (well
> that's one way of putting it :-), so I'm willing to make the speed sacrifice
> (I'm not so sure my co-projectees are, but that's mp ;-). I'm particularly
> interested in the idea of using Prolog's natural searching abilities to
> search for truly optimal code.


Well, a couple of years ago I decided to write a smallish compiler for
my job, to improve the system they had (still have). I'd read an
article in byte about how easy this was in prolog, how it almost wrote
itself etc., so got hold of a public domain version and had a
go. Bearing in mind that I'd no experience in writing compilers, my
prolog was not marvelous and the implementation I had was buggy, I
spent two rather hellish months getting nowhere. The main problem was
the behaviour of prolog: a bug in my prolog, or the program I was
trying to parse, both caused backtracks. Asserts didn't help. I'd even
got to the point of considering asserting the current rule into the
database so I could find out where it failed (a sort of audit
trail).


Finally I realised I was wasting my time. You might well argue that
someone in my position & lack of knowledge was trying to run before I
could walk and perhaps that's true, but I switched to C++. Speaking
of trying to run before I could walk, I still had no compiler writing
experience, I had never done C++ and I didn't understand OO. Still, I
started making progress immediately and in six months I got a robust
working compiler out the door. I can only conclude that prolog (which,
incidentally, I do understand and can use properly, in its full
declarative style) is either not appropriate for compiler writing, or
I was doing something deeply wrong - I'd love to know, and I'll follow
up any postings here. Recommendation - get someone who's been there
done that to help you, or stay away from prolog.


Hope it helps.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.