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

> Like, how is the compiler for the lanuage you want to write actually represented in the compiler in the other language?

Compiler is a program that reads files and outputs executable programs. So you take any programming language that you’re proficient in and create a program that would read text files containing the code in NewLanguage™ and translate that code into something that a computer can execute.

> Is it literally writing the compiler in the language you want translated directly into the other language, or is this compiler in the other language instructions on how to translate what it says into the compiler language you want?

You can do any approach here. Your program in ExistingLanguage™ (for example, C++) can read the code of NewLanguage™ and translate it into the machine code of ARM64 processor. And you can run it then. Or it can translate that source to code in ExistingLanguage™ and compile it as any other ExistingLanguage™ program using their compilers. Or it can translate it to a completely different intermediary language that gets compiled or executed by some third tool.

Either way compiler is just a tool that translates code into different code and it doesn’t matter what language you use to accomplish that. The compiler language itself doesn’t have to understand the new language being compiled. That logic must be created by the creator of the compiler.

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