0

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"?

2 Answers2

1

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.

Kilian Foth
  • 110,899
-2

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.

Tom Au
  • 893