A compiler translates high-level code (C/C++) into low-level code (Assembly/Machine Code). Gate Smashers Take: Think of a compiler as a factory assembly line. Raw source code goes in; machine code comes out. The line has 6 phases.
Converting expressions into Three-Address Code (TAC), Quadruples, Triples, and Indirect Triples. Syntax trees and Directed Acyclic Graphs (DAG) are highly tested here for minimizing subexpressions. 5. Code Optimization compiler design gate smashers
[ Source Code ] │ ▼ ┌─────────────────────────┐ │ Lexical Analyzer │ <───> [ Symbol Table ] └─────────────────────────┘ │ Tokens ▼ ┌─────────────────────────┐ │ Syntax Analyzer │ <───> [ Symbol Table ] └─────────────────────────┘ │ Parse Tree ▼ ┌─────────────────────────┐ │ Semantic Analyzer │ <───> [ Symbol Table ] └─────────────────────────┘ │ Decorated Tree ▼ ┌─────────────────────────┐ │ Intermediate Code Gen. │ <───> [ Symbol Table ] └─────────────────────────┘ │ Intermediate Code ▼ ┌─────────────────────────┐ │ Code Optimizer │ └─────────────────────────┘ │ Optimized Code ▼ ┌─────────────────────────┐ │ Code Generator │ <───> [ Symbol Table ] └─────────────────────────┘ │ ▼ [ Target Machine Code ] Auxiliary Components A compiler translates high-level code (C/C++) into low-level
Uses both synthesized and inherited attributes (evaluated left-to-right). Code Optimization The focus here is on efficiency. Be ready for questions on: Common Sub-expression Elimination Dead Code Elimination Loop Optimization (Code Motion, Strength Reduction) 3. The "Gate Smashers" Approach: Tips for Success To study effectively, follow these tactical steps: The line has 6 phases
Uses Symbol Tables to store variable information. 📝 Phase 4: Intermediate Code Generation (ICG) Task: Converts the tree into a machine-independent code. Common Format: Three-Address Code (3AC) .
Optimization restructures the intermediate code to make the final executable run faster or consume fewer system resources (RAM, power). Common Optimization Techniques
It makes it easier to optimize code and adapt the compiler for different hardware architectures.