According to compiler definition, the compiler is a program that translates a program written in a programming language P (source code) into a program written in a machine language M (machine code).

And also "the compiler is self-compiling if it is written in P".

now the question is what is the meaning of the line- "the compiler is self-compiling if it is written in P"?


The meaning is exactly what you think it means. A compiler is a computer program, and as such it is written in a programming language. Any concrete compiler translates from language A to language B, while having itself being written in language C. If A == C, then the compiler is self-compiling (or self-hosting). Otherwise, it isn't.

The question you may be asking yourself is: How did the compiler get created in the first place? The answer is that large and complex computer programs aren't created all in one go. Most self-hosting compilers were initially written in lower-level languages with a much smaller set of supported features, and then extended, until they are completely self-hosting. This avoids the obvious paradox of how the first compiler came about.

| improve this answer | |
  • 3
    It doesn't necessarily have to be a "lower-level" language. E.g. the first CoffeeScript compiler was written in Ruby, which is roughly at the same level of abstraction as CoffeeScript, and at that time (CoffeeScript started out as an experiment in writing a compiler in Ruby) was actually higher-level than the basic first design of CoffeeScript. The current version of the CoffeeScript compiler, of course, is written in CoffeeScript. – Jörg W Mittag Sep 1 '17 at 14:17

The compiler is written in the language P. If the underlying program were written in some other language Q, the program would have to be translated to P in order to compile.

But if the program were written in P to begin with, there would be no need for such a translation. That would make the program "self-compiling."

Not all programs can be constructed this way, but when it is possible, the savings in time and money could be quite significant.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.