Re: How does a language compile itself?

"Dwight VandenBerghe" <dwight@pentasoft.com>
22 May 1997 21:48:15 -0400

          From comp.compilers

Related articles
How does a language compile itself? crp333@worldnet.att.net (J KILLEA) (1997-05-17)
Re: How does a language compile itself? dwight@pentasoft.com (Dwight VandenBerghe) (1997-05-22)
Re: How does a language compile itself? pardo@cs.washington.edu (1997-05-22)
Re: How does a language compile itself? walter@bytecraft.com (Walter Banks) (1997-05-25)
Re: How does a language compile itself? dgay@barnowl.CS.Berkeley.EDU (1997-05-30)
Re: How does a language compile itself? cliffc@risc.sps.mot.com (Cliff Click) (1997-06-02)
Re: How does a language compile itself? mark@omnifest.uwm.edu (1997-06-04)
| List of all articles for this month |
From: "Dwight VandenBerghe" <dwight@pentasoft.com>
Newsgroups: comp.compilers
Date: 22 May 1997 21:48:15 -0400
Organization: Pentasoft Corporation
References: 97-05-209
Keywords: tools

J KILLEA <crp333@worldnet.att.net> wrote
> At the "java.sun.com" Web site I noted the statement that the compiler
> for Oak (now evolved into Java) was written in Oak. Not being a CS
> person, I do not understand how this can be. The working version of
> the compiler for Oak must be in binary form (i.e., already compiled).
> But if the source code for the first Oak compiler was also written in
> Oak, how did the compiler source code get compiled??


It's one of the great joys of programming; you really have to try it
to understand. Here's the idea. You come up with the simplest, most
bone-head version of the language that is actually useful, and then
you write the first version of the compiler in that language. At this
point you can't actually compile your compiler, because you don't have
an executable yet, as you correctly pointed out. When you have
written this first compiler, you then sit down with a large thermos of
coffee and you hand-translate your program into, say, C. This is
amazingly tedious. When you have finally come up with a C version of
your compiler, you test it by running your original program -- the
first compiler that your wrote in the new language -- through your C
version, which is of course executable because you compiled it with
your local C compiler. After a while you get it running, so that your
C version works and actually generates correct (although very stupid)
output code.


At this point you do the magic: you run your original program through
the C version, and you make an executable of your original program
... which is, of course, a compiler for the language in which it,
itself, is written. Now, you see, the C version has suddenly become
redundant, because your original program does the same thing that the
C version does. To test it, you run your original program's source
code through the newly-created executable, and make sure that you get
the same code as that that was produced by the C version. When you do
... then you dump the C version. It is quite an experience, and you
have to stay very conscious because you are in constant danger of
getting confused as to just which version is what, and deleting the
wrong one by accident. Then you add features to your language by
changing the original program, running the new source code through the
current compiler, testing it, and when it works, replacing the old
version with the new.


It's like magic. I really mean it: you have to experience it to see
what the thrill is all about. First there was nothing, and then you
make up this new language that the world has never seen before, and
then you go through this mickey-mouse rigamarole described above, and
then suddenly, poof, you pull out the rug and the genie is just
floating there in space, all by itself. Even though you were the one
who did it, you still can't quite believe it. It still makes me
smile, and I've been doing this kind of stuff for over three decades
now.


Dwight
--


Post a followup to this message

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