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?
Asked
Active
Viewed 229 times
0
-
1A compiler is just some program that reads some input and produces some output. It can be written in any language you like. Including TypeScript. – Jörg W Mittag Aug 23 '16 at 02: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 '16 at 08: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 '16 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 07 '16 at 01: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 07 '16 at 17:27