If you want to make money online : Register now

[Solved]: Why would we want a self-hosting compiler?

, , No Comments
Problem Detail: 

I understand that a self-hosting compiler is a compiler which can compile the code of the language that it is written in into different language but I don't understand why we would want to do that. What are the benefits (and drawbacks) of a compiler which is self-hosting?

Asked By : Haych

Answered By : Gilles

There's no direct technical benefit for a compiler to be self-hosting. If anything, it makes things more complicated, because you have to have a working compiler before you can compile the compiler — the bootstrapping problem. (Solved either by having another implementation of the same language — often an interpreter — or by keeping around binaries of a previous compiler version.)

Compiler writers often like the language that they're writing a compiler for. This is the primary reason why many compilers are self-hosting.

Having a compiler that compiles itself does have an indirect technical benefit: it's a litmus test. A compiler is a complex program. If the language is comfortable enough to write a program in, that's a sign that it's comfortable enough for a large class of programs. If the compiler can compile itself without bugs, that's a sign that it's in a good enough shape to compile other programs with confidence.

Best Answer from StackOverflow

Question Source : http://cs.stackexchange.com/questions/56897

3.2K people like this

 Download Related Notes/Documents


Post a Comment

Let us know your responses and feedback