Possible Duplicate:
How could the first C++ compiler be written in C++?

You probably heard that Microsoft released a new language called TypeScript which is a the typed superset of JavaScript.

The most interesting thing that makes me wonder is the fact that its compiler writen in TypeScript itself.

Call me ignorant but I really couldn't figure out in my head how that is possible. This is just like chicken and egg problem in my head because there is no compiler to compile TypeScript's compiler in the first place. How is it possible to write a compiler of the compiler of a programming language with that language?


2 Answers 2


It's called Bootstrapping. You're right that the first version has to be written in another language. But once that's done, you can write successive versions with the previously finished compiler.

  • Not necessarily - sometimes the compiler is written in the same language on a different platform, and except for the first version of a language anywhere, that's the usual these days.
    – ddyer
    Oct 3, 2012 at 16:57
  • 4
    @ddyer I took "the first version" as "the first version anywhere". Of course you can trivially use a cross compiler to port an existing interpreter to a platform the language hasn't been implemented for yet.
    – user7043
    Oct 3, 2012 at 17:22
  • 8
    It's not true that the very first version hast be written in another language. You have to somehow compile the very first compiler, but you don't have to do that by machine. You can do it by hand. Prof. Wirth, for example, simply chopped up the Oberon compiler into equal sized chunks and handed them out as homework assignments to be translated (into a variant of Fortran, I believe) by his students. So, in the end he did end up with a version written in another language, but it wasn't the first version, it was the second. And it wasn't "written" per se, it was translated. Oct 4, 2012 at 1:06
  • That's an awesome story!
    – Noein
    Sep 12, 2015 at 18:33
  • @JackG I think you can forgive him based on the fact that this was in the mid-80s. The skills you needed as a student and the tools you had at your hands were completely different than today. The kids were probably just happy that they weren't making punchcards. Oct 12, 2021 at 14:02

A slight variation is where the language itself is interpreted, so the compiler is written in the language itself, runs in the interpreter and compiles itself. These languages (classically, Lisp) have very different runtime representations for compiled and interpreted code, but the compiled form is required to preserve the same semantics.

  • 3
    Of course, this requires having an interpreter in the first place. While this gets around the letter of the title (it's a pity so many people are so confused about the relationships of languages, compilers and interpreters), it's exactly equivalent once we shed the misconception that a compiler is somehow more of a language implementation than an interpreter. IOW bootstrapping is relevant regardless of whether the language implementations in question are interpreters or compilers.
    – user7043
    Oct 3, 2012 at 17:21
  • you could build that interpreter in hardware :)
    – jwenting
    Oct 4, 2012 at 3:54
  • you could also build that interpreter in software if you're not a masochist :)
    – Jack G
    Dec 30, 2017 at 21:47

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