Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question

marked as duplicate by delnan, Martin Beckett, Doc Brown, maple_shaft Oct 3 '12 at 19:12

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2  
stackoverflow.com/questions/193560/… –  jk. Oct 3 '12 at 15:56
2  
2  
@jk. Sadly we can't close it as duplicate of those, so I propose we move it to SO and close it as duplicate there. –  delnan Oct 3 '12 at 16:02
add comment

2 Answers

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.

share|improve this answer
    
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 '12 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. –  delnan Oct 3 '12 at 17:22
2  
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. –  Jörg W Mittag Oct 4 '12 at 1:06
add comment

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.

share|improve this answer
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. –  delnan Oct 3 '12 at 17:21
    
you could build that interpreter in hardware :) –  jwenting Oct 4 '12 at 3:54
add comment

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