Compiler Design notes

10 chapter notes, in syllabus order. Each starts with the key points.

Unit 1

Compiler Design: Phases, Roles & Real-World ImpactUnit 1 of Compiler Design introduces the fundamental concepts of compilers—what they are, why they exist, their architecture, and the phases they undergo to translate high-level code into machine code, with real-world applications in Nepalese software and systems.11 min read

Unit 2

Lexical Analysis: Tokens, Lexemes, Automata & ScannersUnit 2 of Compiler Design covers the first phase of compilation—lexical analysis—where source code is broken into meaningful tokens (lexemes) using regular expressions, finite automata, and scanners. This note explains token classification, DFA/NFA construction, scanner design, and real-world applications in compilers 12 min read

Unit 3

Syntax Analysis: Parsing, Grammars, and Abstract Syntax TreesUnit 3 of Compiler Design explores how compilers analyze the syntactic structure of source code using grammars, parsing techniques, and abstract syntax trees (ASTs). This note covers context-free grammars (CFGs), parsing algorithms (top-down and bottom-up), and the role of ASTs in semantic analysis, with visual traces 7 min read

Unit 4

Top-Down Parsing: Recursive Descent, LL(1), Predictive Parsing & BacktrackingUnit 4 of Compiler Design explores top-down parsing techniques, covering recursive descent parsing, LL(1) grammars, parsing tables, and backtracking methods with worked examples, real-world applications, and visual traces of parsing steps.12 min read

Unit 5

Bottom-Up Parsing: LR, SLR, LALR, CLR Parsers & Shift-ReduceUnit 5 of Compiler Design explores bottom-up parsing techniques—LR(0), SLR, LALR, and CLR parsers—covering their definitions, parsing tables, shift-reduce conflicts, and how they handle grammars. It includes worked examples, parsing table construction, and comparisons with top-down methods.13 min read

Unit 6

Syntax-Directed Translation: Semantic Rules, Attribute Grammars & Code GenerationUnit 6 of Compiler Design explores how compilers generate intermediate or target code by embedding semantic actions in grammar rules, using attribute grammars, and implementing translation schemes (L-attributed, S-attributed). It covers translation of arithmetic expressions, declarations, and control structures with st7 min read

Unit 7

Type Checking: Rules, Errors & Semantic AnalysisUnit 7 of Compiler Design explores type checking—how compilers enforce data type consistency in source code, detect errors, and ensure semantic correctness before code execution. This note covers type systems (static vs. dynamic), type rules, type compatibility, and real-world applications in compilers like Java and C+11 min read

Unit 8

Intermediate Code Generation: Three-Address Code, Stack Machines, DAGsUnit 8 of Compiler Design covers how compilers generate intermediate representations (three-address code, stack machines, DAGs) that balance machine independence and efficiency, including their syntax, semantics, and translation from parse trees. This note explains each form, their trade-offs, and real-world applicatio14 min read

Unit 9

Code Optimization: Techniques, Trade-offs & Real-World ImpactUnit 9 of Compiler Design explores how compilers optimize generated code for speed, size, and energy efficiency—covering loop optimizations, data flow analysis, peephole optimization, and trade-offs between aggressive vs. conservative approaches. Students learn how these techniques transform intermediate code into fast10 min read

Unit 10

Code Generation: Target Code, Register Allocation, Instruction SelectionUnit 10 of Compiler Design explores how compilers translate intermediate code into efficient machine code, covering target architectures, register allocation, instruction selection, and peephole optimization. This note explains the process, techniques, and real-world applications with visual traces and comparisons.11 min read