Compiler DesignProgress: 0/1 completed
Subjects/Compiler Design

Phases of Compiler

Medium
11 mins read
Prerequisites
  • Finite Automata basics
  • Programming syntax structures

Introduction

Compiler ek language translator program hai jo high-level programming language code (like C++) ko compile karke low-level machine code target me convert karta hai. Yeh conversion 6 phases me pipeline structured format me complete hota hai.

Real-Life Analogy

💡 Translating & Proofreading an English Book to Hindi

Phased verification and translation

Concept TermReal-life Analogy Mapping
Lexical AnalysisDividing long paragraphs into individual vocabulary words (checking spelling).
Syntax AnalysisChecking sentence grammar (Subject + Verb + Object structure mapping).
Semantic AnalysisChecking logical sense (e.g., 'The table is drinking water' is grammatically correct, but logically invalid).
Code OptimizationRemoving duplicate sentences and paragraphs to make the book shorter and cheaper.

Detailed Concept Explanation

Compiler phases pipeline: 1. **Lexical Analyzer (Scanner)**: Input stream ko tokens (identifiers, keywords) me break karta hai. 2. **Syntax Analyzer (Parser)**: Tokens collection se Syntax Parse Tree check karta hai check syntax grammar rules. 3. **Semantic Analyzer**: Checks type checking and logical consistency. 4. **Intermediate Code Generator (ICG)**: Machine-independent code representation build karta hai. 5. **Code Optimizer**: Reduces execution clock cycles. 6. **Code Generator**: Converts intermediate code to target Assembly/Machine code.

Visual Diagram

Newdisk pe program
ReadyRAM Ready Queue
Dispatch
RunningCPU execution
TerminatedExit / Finished
I/O Wait
Waiting / BlockedI/O or Event
I/O Done
Note: Ready state queue holds processes waiting for CPU scheduler assignment.
Important Point
  • Symbol Table manager and Error Handler connect to all 6 phases.
  • Lexical analyzer uses Regular Expressions; Syntax analyzer uses Context-Free Grammar.
Mnemonic / Memory Trick

L-S-S-I-C-C (Little Students Study In Class Chambers)

Lexical, Syntax, Semantic, Intermediate code, Code optimization, Code generation

Mnemonic to remember the execution order of all compiler phases.
Avoid This Common Mistake
Students Lexical tokens calculation count string spaces and bracket groupings mismatch parameters.
GATE Exam Insights
Parsing tables (LL(1), LR(0), LALR) structures and conflicts calculations (Shift-Reduce) are hot exam items.

Practice Mini Quiz

Revision Summary (One-Page Notes)

  • Compiler transforms high-level source to machine code.
  • Operates in six sequential phases connected to the Symbol Table.