Resources
CDSemester 6CSE

Compiler Design Essentials

Lexical analysis, parsing, intermediate code, optimization.

12 min read3 sectionsExam-ready notes

Key points

  • Phases of a compiler
  • Lexer & tokens (regex/FA)
  • Top-down vs bottom-up parsing
  • FIRST & FOLLOW
  • Code optimization techniques

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.