eli5: In bootstrapping, how is the compiler written in the other langauge such that it can then compile the original language i.e. the bootstrap compiler?

1.01K viewsOtherTechnology

So I’ve already posted this question on Stack Overflow, but I wanted to ask it here as well, since I am not sure if they will simply say it is a duplicate (even though the other answers from other questions don’t answer what I asked in a way that helps me).

[https://stackoverflow.com/questions/78539284/in-bootstrapping-how-is-the-compiler-written-in-the-other-langauge-such-that-it](https://stackoverflow.com/questions/78539284/in-bootstrapping-how-is-the-compiler-written-in-the-other-langauge-such-that-it)

So I was wondering if there were direct examples people could give of how the bootstrap compiler is actually written such that it actually represents the language you want to write in another language, because my head can’t wrap itself around it and most sources are fairly vague and just assume you know how it is done.

Hell, maybe if people try and explain it in a metaphorical way and walk me through how the bootstrap compiler is written to represent language X in language Y, that might help too, since I am not a programmer, but this concept is stressing me out from knowing I don’t understand it.

In: Technology

17 Answers

Anonymous 0 Comments

Imagine a set of rules that when followed translate English to German. You could write that set of rules in English, or German, or French. It doesn’t really matter what language the rules are written in as long as they work.

In this analogy English is the source language (maybe C or Java). German is the target language (probably machine code). The compiler is the set of translation rules. French is the language the compiler was created in.

But this doesn’t quite capture the concept of “boot strapping”. To understand boot strapping you have to recognize that target language (machine code) is great for computers but hard for humans to understand.

So we invent a language A that’s a bit easier for humans to read and write, and build a translator from that to machine code (using machine code to build it, which is hard work, but not too hard because A isn’t very different from machine code)

Then we invent a language B that’s a bit easier for humans to read than A, and we write a translator from B to machine code, using A. Again, not easy but easier than if we had to write it in machine code.

“Rinse and repeat”, after a few iterations we have a language that is easy enough for humans called F. And a translator from F to machine code written in E.

As a final step we write a better translator from F to machine code, written in F itself. And we translate it to machine code using our translator written in E.

From now on we can improve the compilation (translation) time needed or the efficiency of the machine code produced (run time) by improving our F compiler written in F .

You are viewing 1 out of 17 answers, click here to view all answers.