compiler.md (1401B)
1 # Compiler 2 3 Programs are files that contain a bunch of text written by you, the programmer. 4 That text is parsed by a special program called a compiler, which transforms it 5 into a `abstract syntax tree` (`AST`), a data structure that ignores things like 6 whitespaces, comments, and where you stand on the tabs versus spaces debate. 7 8 The compiler then converts that AST to a lower-level representation called 9 `bytecode`. You can feed that bytecode into another program called a `runtime` 10 to evaluate it and get a result. So when you run a program, what you're really 11 doing is telling the runtime to evaluate the bytecode generated by the compiler 12 from the AST parsed from your source code. The details vary, but for most 13 languages this is an accurate high-level view. 14 15 Once again, the steps are: 16 17 1. Program is parsed into an AST 18 2. AST is compiled to bytecode 19 3. Bytecode is evaluated by the runtime 20 21 --- 22 23 As for TypeScript... 24 25 Where TypeScript is special is that instead of compiling straight to bytecode, 26 TypeScript compiles to... JavaScript Code! You then run that JavaScript code 27 like you normally would - in your browser, or with NodeJS, or by hand with a 28 paper and pen (for anyone reading this after the machine uprising has begun). 29 30 After TypeScript Compiler generates an AST for your program - but before it 31 emits code - it `typechecks` your code. 32 33 - from Programming TypeScript by Boris Cherny