Compiler Design — Exam Power Notes
Quick Revision Guide
1. What Is a Compiler?
A compiler is system software that translates high-level source code into a target form such as machine code or
intermediate code. It also detects and reports programming errors.
2. Compiler Phases
The major phases are: Lexical Analysis, Syntax Analysis, Semantic Analysis, Intermediate Code Generation, Code
Optimization, and Code Generation. Symbol-table management and error handling support these phases.
Phase Purpose
Lexical Analysis Converts characters into tokens.
Syntax Analysis Checks grammar and builds a parse structure.
Semantic Analysis Checks meaning, types, declarations, and scope.
Intermediate Code Generation Produces a machine-independent representation.
Code Optimization Improves efficiency while preserving behavior.
Code Generation Produces target instructions.
3. Lexical Analysis
The scanner groups source characters into tokens such as keywords, identifiers, operators, literals, and punctuation.
Regular expressions and finite automata are commonly used for token patterns.
4. Syntax Analysis
The parser checks whether tokens follow the language grammar. Common approaches include top-down and bottom-up
parsing. The result can be a parse tree or abstract syntax tree (AST).
5. Semantic Analysis
This phase checks rules that grammar alone cannot establish, including type compatibility, declarations, function
arguments, and scope.
6. Intermediate Representation
An intermediate representation (IR) provides a machine-independent form between source and target code. Three-address
code is a common example.
7. Code Optimization
Optimization improves execution speed, memory usage, or code size without changing intended program behavior.
Examples include constant folding, dead-code elimination, and common subexpression elimination.
8. Code Generation
The code generator converts IR into target instructions. Typical tasks include instruction selection and register allocation.
9. Compiler vs Interpreter
A compiler generally translates a program before execution, while an interpreter executes or translates program instructions
during execution. Exact implementation details vary by language and runtime.
10. Important Terms
Quick Revision Guide
1. What Is a Compiler?
A compiler is system software that translates high-level source code into a target form such as machine code or
intermediate code. It also detects and reports programming errors.
2. Compiler Phases
The major phases are: Lexical Analysis, Syntax Analysis, Semantic Analysis, Intermediate Code Generation, Code
Optimization, and Code Generation. Symbol-table management and error handling support these phases.
Phase Purpose
Lexical Analysis Converts characters into tokens.
Syntax Analysis Checks grammar and builds a parse structure.
Semantic Analysis Checks meaning, types, declarations, and scope.
Intermediate Code Generation Produces a machine-independent representation.
Code Optimization Improves efficiency while preserving behavior.
Code Generation Produces target instructions.
3. Lexical Analysis
The scanner groups source characters into tokens such as keywords, identifiers, operators, literals, and punctuation.
Regular expressions and finite automata are commonly used for token patterns.
4. Syntax Analysis
The parser checks whether tokens follow the language grammar. Common approaches include top-down and bottom-up
parsing. The result can be a parse tree or abstract syntax tree (AST).
5. Semantic Analysis
This phase checks rules that grammar alone cannot establish, including type compatibility, declarations, function
arguments, and scope.
6. Intermediate Representation
An intermediate representation (IR) provides a machine-independent form between source and target code. Three-address
code is a common example.
7. Code Optimization
Optimization improves execution speed, memory usage, or code size without changing intended program behavior.
Examples include constant folding, dead-code elimination, and common subexpression elimination.
8. Code Generation
The code generator converts IR into target instructions. Typical tasks include instruction selection and register allocation.
9. Compiler vs Interpreter
A compiler generally translates a program before execution, while an interpreter executes or translates program instructions
during execution. Exact implementation details vary by language and runtime.
10. Important Terms