0

I was reading on the TypeScript site and saw that the TypeScript compiler is itself written in TypeScript. "The TypeScript compiler is implemented in TypeScript and can be used in any JavaScript host." I don't understand how this can work, wouldn't that create a circular dependency? Chicken-and-egg-scenario? was the first version of the compiler written in something else?

5
  • 1
    A compiler is just some program that reads some input and produces some output. It can be written in any language you like. Including TypeScript. Aug 23, 2016 at 2:35
  • "was the first version of the compiler written in something else?" Yes. Or there was an interpreter before there was a compiler. Or somebody executed it by hand first time.
    – Jules
    Aug 23, 2016 at 8:34
  • It is called bootstrapping, yes for a new language you have to start with some other language, and then re-write (or convert in some way) the compiler to the new language. With the non-native compiler you generate a binary of the compiler, and with that you compile the native language version of the compiler and generate a binary, if that binary can then take the same native code and generate another working compiler you have bootstrapped that language.
    – old_timer
    Aug 23, 2016 at 20:47
  • @Jules was looking back thru these old answers and something caught my eye that i looked past before... what exactly do you mean by "executed it by hand"?
    – solidau
    Dec 7, 2016 at 1:40
  • As in, write the program you want to run (presumably the compiler) on a piece of paper, and then translate that by hand (presumably using the same or at least a very similar process to how the compiler itself works) into your output language. It's a tedious process, but if you get it right you'd only need to do it once...
    – Jules
    Dec 7, 2016 at 17:27

0

Browse other questions tagged or ask your own question.