- software that takes code written in one language and converts it to another
- PHP -> C
- C -> Machine Code
- code written for humans is hard for computers to understand
- code written for computers is hard of humans to understand
11100101 11011001 11010010 11110001
- Front End - Takes source file and turns it into an intermediate representation
- Middle End - Makes performance optimisations
- Back End - Turns intermediate representation into the target code
- Tokenizer (sometimes called a Lexer)
- Parser
- Code Generator
Takes your code and turns it into understandable single chunks.
def hello()
becomes
token: def
token: identifier (hello)
token: open_parenthesis
token: close_parenthesis
Turns tokens into an Intermediate Representation
1 + 1
becomes
token: 1
token: +
token: 1
becomes
(+)
/ \
(1) (1)
Takes our Intermediate Representation
and turns it into the code we care about.
(+)
/ \
(1) (1)
becomes
add(1,1)
- just another form of compiler. It keeps code at the same level of abstraction.
- Babel es2015 stuff
- what we're going to write today
- a compiler is just a program, doing normal programmy things
- the main parts of a compiler
- Front / Middle / Back ends
- Tokenizer
- Parser
- Code Generator
- the difference between a Transpiler and a Compiler
- how we could make a (very quick and dirty) compiler
- thanks to Destroy All Software
- slides and code https://github.com/tosbourn-ltd/compiler-talk
- @tosbourn on twitter if you want to tweet questions later
- https://tosbourn.com/simple-cs/