Turning source into executable code.
WHAT THE STAGES ARE
- Lexical analysis: source into tokens
- Parsing: tokens into a tree
- Semantic analysis: type checking and resolution
Intermediate representation Optimisation Code generation Assembly and linking
WHAT A GRAMMAR DEFINES
The valid structure of the language.
WHAT PARSER GENERATORS PROVIDE
Parsers produced from a grammar description.
WHAT HAND-WRITTEN PARSERS PROVIDE
Better error messages, and more control.
WHAT MOST PRODUCTION COMPILERS USE
Hand-written parsers, for that reason.
WHAT AN INTERMEDIATE REPRESENTATION PROVIDES
A form suited to analysis and transformation, independent of source and target.
WHY THAT MATTERS
Optimisations are written once, and front ends and back ends can be combined.
WHAT COMMON OPTIMISATIONS DO
Remove unreachable and unused code Evaluate constants at compile time Move invariant work out of loops Inline small functions Allocate registers well
WHAT REGISTER ALLOCATION IS
Deciding which values live in the limited registers.
WHY IT MATTERS SO MUCH
It has among the largest effects on generated code quality.
WHAT COMPILER FRAMEWORKS PROVIDE
Optimisation and code generation, so you write only a front end.