Home computickets How can the compiler be written in the same language that it...

How can the compiler be written in the same language that it compiles?




I read several similar questions but did not find a full-fledged answer.
As the C compiler can be written on C, because someone has to compile the compiler itself in the machine code. Will there be a broadcast in the assembler in essence equal to compilation? (Except for the fact that the assembler commands will need to be then replaced by binary code)

Answer 1, Authority 100%

C compiler is written on the previous version of the compiler. But when it was long ago, there was a moment when the C compiler was written on something else. I unfortunately, I do not know this moment.

But with the plus compiler, everything is easier – first was written by CFRONT – the program on C, which translated the “Plus Code” into the blue, and then compiled.

with other languages ​​also happened. For example, GO was first written on Si, and then the code was so modified, whatever it looks like GO code (https://go-review.googlesource.com/c/go/+/5652 ).

Therefore, with a clean SI compiler for the X86, it was most likely so – at some point just for the platform accessible at that time they took the C compiler and corrected code generation. And ready. And we already generate binaries for a new platform.

But how did the very first compiler appear then? There is a good article https://jameshfisher.com/2018/01/11/ bootstrapping-ac-compiler / which describes how it can be done in step by step.

And here https://stackoverflow.com/questions/65751457 / How-Could-One-Possibly-bootstrap-ac-compilerfrom-source Ask almost the same as you.

That is, at first everything is written with handles in memory, in zolics and units, then the tools are gradually increasing and in the end, such iterations can be reached to the modern world. Here people write the simplest SI compiler https://github.com/rdtscp/c-bootstrap

And whether the transmission in the assembler is essentially equal to the compilation

If we have an assembler compiler, then yes. Why “compiler”? Because the assemblers are different. The same Flat Assembler has such a bit of syntax that I would be afraid of calling his compiler “program to replace the binary code” .

Yes, the process when the compiler compiles itself is called bootstrapping. And it is not related to HTML.

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions