1. Compiler Phases
1. Lexical Analysis (tokens)
2. Syntax Analysis (parse tree)
3. Semantic Analysis (type checks)
4. Intermediate Code Generation
5. Code Optimization
6. Code Generation
+ Symbol table & error handler throughout
2. Lexing & Parsing
Lexer: regex → NFA → DFA → tokens
Parser
- Top-down: Recursive descent, LL(1)
- Bottom-up: LR, SLR, LALR, CLR
FIRST/FOLLOW for LL(1) table construction
Left recursion & left factoring needed for predictive parsers
3. Intermediate Code & Optimization
IR forms: Three-address code, quadruples, triples, DAG
Optimizations
- Constant folding
- Common subexpression elimination
- Dead code elimination
- Loop invariant code motion
- Strength reduction
Peephole optimization on small instruction windows.