Course Title: Compiler Design Course Code: CS 451 Topic: Introduction Branch: CSE Semester: VII TH
Course Title: Compiler Design Course Code: CS 451 Topic: Introduction Branch: CSE Semester: VII TH
Topic : Introduction
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
This presentation is released under Creative Commons-A6ribute,on 4.0 License. You are free to use, distribute and modify it ,
including for commercial purposes, provided you acknowledge the source.
Text and Reference books
• 1. Compilers Principles, Techniques and Tools. Aho
A. V., Lam M. S., Sethi R. & Ullman J. D. 2nd Ed.
Pearson. 2009.
Source Program
Interpreter Result
Input
• Advantages of Interpreter
• Comparison of Compiler, Interpreter and assembler
Language Processing system
Source Program
Preprocessor
Modified Source program
Compiler
Target assembly program
Assembler
Relocatable machine code
Linker / Loader Library files
Relocatable object files
Target Machine code
Process of Compiling
Characters Stream
Lexical Analyzer
Token Stream
Syntax Analyzer
Parse/syntax tree
Semantic Analyzer
Syntax tree Error detection &
Symbol Table handling
Intermediate Code Generator
Intermediate code
Machine Independent Code optimizer
Intermediate code
Code generator
Target Machine code
Machine Dependent Code optimizer
Introduction to compiler
Target Machine code
Chapter 1 7
The Phases of Compiler
• Lexical Analysis
• Syntax Analysis
• Semantic Analysis
• Intermediate Code Generation
• Code Optimization
• Code Generation
• Symbol table management
• Error Detection and handling.
Introduction to compiler
Chapter 1 8
Compiler: Analysis-Synthesis Model
Introduction to compiler
Chapter 1 15
The Phases of Compiler
• Code Generation : In code generation phase
the target code gets generated. The
intermediate code instructions are translated
into sequence of machine instructions.
Introduction to compiler
Chapter 1 16
The Phases of Compiler
• Symbol table Management : The task of
symbol table is to store identifiers used in
program.
• The symbol table also stores information
about attributes of each identifier. The
attributes of identifiers are usually its type,
its scope, information about the storage
allocated for it.
• It also store information about the
subroutines used in the program.
Introduction to compiler
Chapter 1 17
The Phases of Compiler
• Symbol table allows us to find the record for
each identifier quickly, and to store or
retrieve data from the record efficiently.
• During compilation the lexical analyzer
detects the identifier and makes its entry in
the symbol table.
Introduction to compiler
Chapter 1 18
•
The Phases of Compiler
Error detection and handling : In compilation,
each phase detects errors. These errors must
be reported to error handler whose task is to
handle the errors so that the compilation can
proceed. Normally, the errors are reported in
the form of message. Ex. In Lexical analysis,
error occurs in separation of tokens. In syntax
analysis error occurs during construction of
parse tree.
Introduction to compiler
Chapter 1 19
•
The Phases of Compiler
Error detection and handling : In compilation,
each phase detects errors. These errors must
be reported to error handler whose task is to
handle the errors so that the compilation can
proceed. Normally, the errors are reported in
the form of message. Ex. In Lexical analysis,
error occurs in separation of tokens. In syntax
analysis error occurs during construction of
parse tree.
Introduction to compiler
Chapter 1 20
Examples(Phases of compiler)
Examples(Phases of compiler)
References
• 1. John E. Hopcroft, Rajeev Motwani & Jeffery D. Ullman.
Introduction to Automata Theory, Languages and
Computation. Pearson Education.
• 2. K.L.P Mishra and N.Chandrasekaran, Theory of
Computer science (Automata, Language and
Computation) PHI
• .