[Tutor] OT self-implementation?

Max Noel maxnoel_fr at yahoo.fr
Sat Jul 2 03:40:18 CEST 2005


On Jul 2, 2005, at 01:43, Brian van den Broek wrote:

> This sounds, to the untutored, rather like magic. (It reminds me of a
> line from the German mathematician and philosopher, Gottlob Frege,
> who, in a book on the foundations of arithmetic, characterized an
> opposing position as akin to "trying to pull yourself out of the swamp
> by your own top-knot" -- which, I can only assume, is even funnier in
> the original 19th c. German ;-) Naively, one thinks that to write
> anything in C, you'd have to *have* C to write in, etc.

     Actually, there's not much to it that's magic. The idea is that  
before being able to self-implement a language, you implement it in  
another language first (usually, but not always, ASM). Before C was  
written in C, it was written in assembly language.
     To get a C compiler that's itself written in C, here's what you do:

1. Obtain a C compiler. Any C compiler, let's call it "fooCC". It  
doesn't matter as long as it compiles correctly.
2. Your C compiler will be called "barCC". Write its source code in  
C. Not hard to do as C code is just ASCII text.
3. Compile barCC's source code with fooCC. The resulting compiler  
(let's call it "bazCC") is not barCC yet. It produces the same output  
as barCC, but the process is not complete as it was itself produced  
using a compiler that wasn't written in C.
4. Compile barCC's source code with bazCC. Since bazCC and barCC  
produce the same output, what you get is equivalent to barCC compiled  
with barCC itself: it *is* barCC. You have your compiler.
5. (optional) Make sure the previous statement is true: recompile  
barCC with barCC, and assert that the output is identical to the  
compiler produced in 4.

     The whole process is called "bootstrappping" (from the  
Adventures of Baron Munchausen, as you mentioned), and exists for all  
compiled languages (including assembly). In fact, every language  
except microcode was at some point either bootstrapped or cross- 
compiled.

-- Max
maxnoel_fr at yahoo dot fr -- ICQ #85274019
"Look at you hacker... A pathetic creature of meat and bone, panting  
and sweating as you run through my corridors... How can you challenge  
a perfect, immortal machine?"


	

	
		
___________________________________________________________________________ 
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger 
Téléchargez cette version sur http://fr.messenger.yahoo.com


More information about the Tutor mailing list