Different Phases of Compiler
Different Phases of Compiler
Different Phases of
compiler
From Code to Execution->
-BY
PRITAM CHAKRABORTY
STREAM - CSE
SECTION - A
ROLL NO.- 12100122045
Table of Contents
3 6 9
10
Linking, Assembly,
4 7
and Error Handling
Lexical Analysis Intermediate Code
Generation 11
Conclusion
5 8
Resources
The Architects of Code 3
• What is a Compiler?
A compiler is a special program that translates a
programming language's source code into machine code,
bytecode or another programming language.
Lexical Analysis:
• Tokenization:
⚬ Tokenization breaks text or data into smaller units, called
tokens.
⚬ It simplifies text analysis in NLP and aids in lexical analysis
in programming.
• Lexical Errors:
⚬ Lexical errors occur when the source code contains invalid
sequences of characters or symbols.
⚬ They are detected during lexical analysis and typically
involve unrecognized tokens or incorrect syntax.
1.Type Checking
a. Ensures Data Consistency: Validates that variables and
expressions are used with compatible data types.
b. Static Type Checking: Performs checks at compile time,
catching errors before execution.
c. Dynamic Type Checking: Validates types at runtime,
providing flexibility but with a potential performance cost
2. Symbol Tables
d. Variable Tracking: Stores information about variable names,
types, and scopes for quick lookup.
e. Function Management: Keeps track of function definitions,
parameters, and return types to ensure correct usage.
f. Scope Resolution: Helps in resolving the scope of variables
and functions, managing visibility and lifetimes.
3. Contextual Errors
g. Type Mismatches: Detects logical errors where operations
are performed on incompatible data types.
h. Undeclared Identifiers: Identifies usage of variables or
functions that have not been declared.
i. Inconsistent Definitions: Finds discrepancies in function
signatures or variable declarations across different parts of
the code.
The Translation Bridge 7
Examples of
Intermediate Intermediate
Role of IR in
Representatio Code Formats
Optimization
ns (IR):
Code Optimization:
Optimization Techniques
1.Improving Performance: Enhances the speed and efficiency of code execution by minimizing resource
usage and reducing runtime.
2.Parallelization: Splits tasks into concurrent threads or processes to leverage multi-core processors and
reduce execution time.
Conclusion:
The different phases of a compiler—lexical analysis, syntax analysis, semantic analysis,
optimization, and code generation—each play a vital role in transforming high-level code into
executable machine code. Understanding these phases is essential for both compiler design
and efficient programming. Mastery of this process ensures accurate and optimized code
execution.
Resources:
GeeksforGeeks Compiler Design
Techtarget.com
Principle of compiler design
-Alfred V. Aho & Jeffery D.Ullman
Thank you