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.02K 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

I’m not an expert, but think this may help: I think the question is more about why a compiler is necessary in the first place– at the end of the day, the processor has what is called an Instruction set, the actual commands it can perform. What the CPU takes are these commands and the data on which they operate, sometimes called machine code. These are very low level operations like adding numbers, moving values from Memory to cache — you give it a command like add, subtract, copy to/ from RAM, and the values to add/copy/ move/ etc. Doing anything of utility requires many of these simple steps, written in a form that is barely human readable. All other languages must ultimately be compiled into machine code that your processor can understand. There are intermediate steps– assembly is in a sense a slightly more readable version of what the processor actually uses (which are all 1s and 0s, but nobody programs in actual binary, ever.) So compilers take source code in a higher level language that humans can read and understand and output the processors instruction set commands to achieve the goals described in the source code, in a way the processor can understand with its limited vocabulary. I hope that makes sense.

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