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

coding_ninza
  • 117
  • 5
  • see also: [Why are self-hosting compilers considered a rite of passage for new languages?](https://softwareengineering.stackexchange.com/q/263651/31260) – gnat Sep 01 '17 at 14:08
  • The line doesn't *have* a meaning. It is a *definition*. Definitions don't *have* meaning, they *give* meaning. This line gives a meaning to the term "self-compiling", namely that "self-compiling" means "the implementation language is the same as the source language". – Jörg W Mittag Sep 01 '17 at 14:19

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
  • 107,706
  • 45
  • 295
  • 310
  • 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 01 '17 at 14:17
-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
  • 7
  • 17