+5  A: 

Generally the first version of the compiler is written in a different language, and then each subsequent version is written in that language and compiled with the older version. Once you've compiled version x with version x-1, you can use the newly built version x to recompile itself, taking advantage of any new optimizations that version introduces; GCC does its releases that way

Michael Mrozek
+1 I've built a simple Lisp interpreter in JAVA.
Achilles
so... why can't you just use the first version of the compiler? Why would you want a double-level compiler?
froadie
@froadie You mean why not compile every version with version 1? Usually new versions of a compiler generate better machine code than the previous versions, so building with the newest version will make the compiler itself as fast/efficient as possible. Also if the language itself is changing and you want to use those newer features in the compiler's source code, you'll need to build with a more recent version
Michael Mrozek
+1  A: 

It is. You usually need a bootstrap version of the language either compiled or interpreted from another language.

And to bend your mind a little more, years ago I read the history of a Pascal compiler written as a grad student project. It written in Pascal and compiled with the system's built-in Pascal compiler. Eventually, it was good enough to replace the system's built-in Pascal compiler. Unfortunately, they found a bug in code generation, but the fix for the code generator triggered the bug in the compiler, generating a bad compiler. To fix it required hand-patching the binaries from the installed compiler to then apply the patch to the source to replace itself.

plinth
+1  A: 

The first pass of the compiler is normally written in something else until the language is well-formed enough to be able to compile it's own compiler, then you can get into the x is written in x.

Lazarus
+1  A: 

It's only a problem for the very first version ever. Once I have V1.0 of the compiler working I can write V2.0 in my language and use the V1.0 compiler to compile it. Then I can write V3.0 and use V2.0 to compile that, use V3.0 to compile V4.0 and so on.

joefis
A: 

At the very beginning, the real first compiler of that language, was written not in that language of course. Very second could be written in that language. Moreover, given a spec of a language, you can implement a basic core in a bootstrap compiler, and then write the full compliant compiler in that language using the subset understood by the "bootstrap" compiler. Second generation compilers can forget "bootstrap" compiler too.

ShinTakezou
+1  A: 

At some point, you need a compiler (or interpreter) written in a different language. But it doesn't need to be efficient and can be done in a language that makes parsing and prototyping easy (LISP is popular). Once you have used this to compile the "self-compiler", you can discard it and use the result.

Michael Borgwardt
Not necessarily. The very first "compiler" can also be a human, in which case you do not need a bootstrap compiler in a different language *at all*. This is how the first compilers for most of Niklaus Wirth's languages were written: he basically assigned them to his students :-)
Jörg W Mittag