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
Unfortunately you’re not going to really understand this without having programming experience. It’s one of the most difficult computer science topics.
The bootstrap compiler is very bare bones. It can only support basic statements and is not a good compiler. You’ll want to make it so that you can, at least, construct a compiler in your new language from the bootstrap compiler. So there needs to be a decent amount of functionality.
Now, *actually* doing that is hard. I don’t know how it’s exactly done and I have a degree in CS. The thing is I’ve never written a compiler and never will need to, it’s very niche and very complex and I have no interest in writing my own language or working on one.
The compiler needs to be able to parse your language. Essentially, it needs to take some input like “for k in 1..10” and recognize that you want to iterate over a variable k 10 times. And then it needs to write code for that in assembly.
This is the hard part. You need to build an abstract architecture that can handle all of this. Compiler books go into this, and again, I’m not exactly sure how, but I do know that you need to formally represent your language with things such as Backus-Naur Form and the compiler needs to create abstract syntax trees. Backus Naur Form is a formal way to represent a language. An abstract syntax tree is a tree that contains valid arrangements of syntax of your language. If this is going over your head, it should, because there are all Cs topics that the layperson won’t understand (many CS people don’t use backus naur firm, and syntax trees are only ever used in compilers).
If you want to *really* know how a compiler works you need to read a textbook about it. And even then you’ll want to have a lot of programming experience otherwise a lot of concepts and a lot of understanding of why will go over your head. And there isn’t a good ELI5 explanation for something so complex and niche.
Latest Answers