compiler
compiler
2 print(“by – varun”)
Introduction to Compilers
• A compiler is a software that converts high-
level language (source code) into
machine/binary language (object code).
• This conversion is necessary as computers
understand only binary language.
• Some compilers use an intermediate step
(assembly language), while others directly
generate machine code.
• The entire process is known as compilation.
Analysis of a Source Program
• Linear Analysis:
• Reads characters from left to right.
• Groups them into meaningful units called tokens.
• Hierarchical Analysis:
• Groups tokens hierarchically into a nested
structure.
• Semantic Analysis:
• Ensures the correct meaning of the code.
Phases of a Compiler
• Lexical Analysis – Converts source code into tokens by removing
spaces and comments.
• Syntax Analysis – Checks for syntax errors and builds a parse
tree.
• Semantic Analysis – Ensures correct variable usage, type
checking, and logic validation.
• Intermediate Code Generation – Produces a platform-independent
intermediate representation.
• Code Optimization – Refines the code for better performance and
efficiency.
• Target Code Generation – Converts optimized code into machine-
executable form.
These phases are categorized into =>
• Front End: Handles lexical, syntax, semantic analysis, and
intermediate code generation.
• Back End: Deals with optimization and target code generation.
Types of Compilers
• Cross Compiler
• Produces machine code for a different platform than the
one it runs on.
• Bootstrap Compiler
• Written in the same language it compiles.
• Decompiler
• Reverse of a compiler: Converts machine code into a high-
level language.
Features of a Compiler
• Fast compilation speed.
• Produces correct machine code.
• Ensures the meaning of the code remains
unchanged.
• Generates efficient machine code.
• Detects and reports errors effectively.
• Ensures code follows proper grammar rules.
Uses & Applications of
Compilers
• Makes the code platform-independent.
• Ensures syntax and semantic correctness.
• Generates executable files.
• Converts code from one programming language to
another.
Conclusion
• A compiler is essential for converting high-
level code into machine language.
• The compilation process follows multiple
structured phases.
• Different types of compilers serve specific
needs.
• Compilers play a critical role in software
development and optimization.