尊敬的 微信汇率:1円 ≈ 0.046166 元 支付宝汇率:1円 ≈ 0.046257元 [退出登录]
SlideShare a Scribd company logo
SRI RAMAKRISHNA INSTITUTE OF TECHNOLOGY,
COIMBATORE-10
(An Autonomous Institution)
Department of Information Technology
Academic Year 2021-22 III Year 5th Semester
UITC013 - PRINCIPLES OF COMPILER
DESIGN
M. MARIMUTHU, AP/IT
What are Compilers?
• Compiler is a program which translates a
program written in one language (the source
language) to an equivalent program in other
language (the target language)
Compilers
• Translates from one representation of the
program to another
• Typically from high level source code to low
level machine code or object code.
• Source code is normally optimized for human
readability.
– Expressive: matches our notion of languages
– Redundant to help avoid programming errors
Compilers…(2)
• Machine code is optimized for hardware.
– Redundancy is reduced
– Information about the intent is lost.
Compilers vs Interpreters
Phases of a Compiler
Phases of a Compiler..
• A compiler operates in phases, each of which
transforms the source program from one
representation into another representation.
• They communicate with error handlers.
• They communicate with the symbol table.
Symbol Table Management
• An essential function of a compiler is to record
the identifiers used in the source program and
collect information about various attributes of
each identifier.
• These attributes may provide information about
the storage allocated for an identifier, its type, its
scope and in the case of procedure names, such
things as the number and types of its arguments,
the method of passing each argument and the
type returned.
Symbol Table Management…
• A symbol table is a data structure containing a
record for each identifier, with fields for the
attributes of the identifier.
• The data structure allows us to find the record
for each identifier quickly and to store or
retrieve data from that record quickly.
• When an identifier in the source program is
detected by the lexical analyzer, the identifier
is entered into the symbol table.
Symbol Table Management…
• However, the attributes of an identifier cannot
normally be determined during lexical analysis.
For example, in a Pascal declaration like.
Var a,b,c: real;
The type “real” is not known when a,b and c are
seen by the lexical analyzer.
• The remaining phases enter information about
identifiers into the symbol table and use this
information in various ways.
Error Detection and Reporting
• Each phase can encounter errors. However,
after detecting an error, a phase must deal
with that error, so that compilation can
proceed allowing further errors in the source
program to be detected.
• The lexical phase can detect errors where the
characters remaining in the input do not form
any token of the language.
Error Detection and Reporting
• Error where the token stream violates the
structure rules of the language are
determined by the syntax analysis phase.
• During semantic analysis the compiler tries to
detect constructs that have the right syntactic
structure but no meaning to the operation
involved.
Error Detection and Reporting
• All phases may encounter errors such as,
• Lexical Phase – Unable to proceed because
the next token in the source program may be
misspelled.
• Syntax Phase – Structure of the statement
violates the rules of programming language.
• Semantic – No meaning in the operation
involved.
Error Detection and Reporting
• Intermediate – Operands have incompatible
data types.
• Code Optimizer – Certain statements may
never be reached.
• Code Generation – Constant is too long.
• Symbol table – Multiple declared variables.
Lexical Analysis
• The lexical analysis phase reads the characters
in the source program and groups them into a
stream of tokens.
• Each token represents a logically cohesive
sequence of characters, such as an identifier, a
keyword, a punctuation character or a
operator, etc.
• The character sequence forming a token is
called the lexeme for the token.
Lexical Analysis
• Certain tokens will be augmented by a “lexical
value”. The lexical analyzer not only generates
a token, but also it enters the lexeme into the
symbol table.
• Eg., Consider the expression
a:= b+c*20
The representation of the above expression
after lexical analysis is,
id1 = id2 + id3 * 20
Syntax Analysis
• This phase receives the tokens generated by previous
phase (Lexical Analysis) as input and produces a
hierarchical structure called syntax or Parse tree as
output.
• It checks whether the statements are up to the syntax
of the programming language constructs or not.
• A Parse tree represents the syntactic structure of the
input. A Syntax tree is a compressed representation of
the parse tree in which the operators appear as the
interior nodes and the operands as child nodes.
Semantic Analysis
• This phase checks the source program for the
meaning of syntax tree, semantic errors and
gathers “type compatible information” for the
subsequent phases.
• Type Checking - “for each operator, the
operands are checked to find whether they
are acceptable for that operator.
• For example, character data type cannot be
used in an arithmetic expression
Intermediate Code Generation
• This phase converts the output of semantic
analyzer into an intermediate representation.
• Intermediate representation should have two
important properties:-
– It should be easy to produce,
– Easy to translate into the target program
• Some of the intermediate forms are
– Syntax Trees
– Postfix Notation
– Three address code – having at most three operands
Code Optimization
• Object code programs need to be small and
faster than the source program. Hence this
phase optimizes the intermediate
representation of the source program into an
efficient code by reducing the unnecessary
statements and operands.
Code Optimization - Examples
• Detection and removal of dead (unreachable)
code.
• Local optimization :- Elimination of common
sub expressions
• Loop optimization :- Finding out loop
invariants and avoiding them.
Code Generation
• This phase converts the optimized
intermediate code into target code which can
be either Assembly code or Machine code.
• This phase also allocates memory locations for
the variables used in the program (allocation
of registers and memory)
Principles of Compiler Design
Principles of Compiler Design
Principles of Compiler Design

More Related Content

What's hot

Voting protocol
Voting protocolVoting protocol
Voting protocol
Dipti Shrivastava
 
Cs556 section2
Cs556 section2Cs556 section2
Cs556 section2
farshad33
 
9 fault-tolerance
9 fault-tolerance9 fault-tolerance
9 fault-tolerance
4020132038
 
Fault Tolerant and Distributed System
Fault Tolerant and Distributed SystemFault Tolerant and Distributed System
Fault Tolerant and Distributed System
sreenivas1591
 
Fault tolerance
Fault toleranceFault tolerance
Fault tolerance
Aman Balutia
 
1.intro. to distributed system
1.intro. to distributed system1.intro. to distributed system
1.intro. to distributed system
Gd Goenka University
 
Communications is distributed systems
Communications is distributed systemsCommunications is distributed systems
Communications is distributed systems
SHATHAN
 
Fault tolerance in Information Centric Networks
Fault tolerance in Information Centric NetworksFault tolerance in Information Centric Networks
Fault tolerance in Information Centric Networks
Nitinder Mohan
 
CS6601 DISTRIBUTED SYSTEMS
CS6601 DISTRIBUTED SYSTEMSCS6601 DISTRIBUTED SYSTEMS
CS6601 DISTRIBUTED SYSTEMS
Kathirvel Ayyaswamy
 
Distributed Systems Introduction and Importance
Distributed Systems Introduction and Importance Distributed Systems Introduction and Importance
Distributed Systems Introduction and Importance
SHIKHA GAUTAM
 
Fault Tolerance 101
Fault Tolerance 101 Fault Tolerance 101
Fault Tolerance 101
C4Media
 
Analysis of mutual exclusion algorithms with the significance and need of ele...
Analysis of mutual exclusion algorithms with the significance and need of ele...Analysis of mutual exclusion algorithms with the significance and need of ele...
Analysis of mutual exclusion algorithms with the significance and need of ele...
Govt. P.G. College Dharamshala
 
Chapter 11c coordination agreement
Chapter 11c coordination agreementChapter 11c coordination agreement
Chapter 11c coordination agreement
AbDul ThaYyal
 
Message Passing, Remote Procedure Calls and Distributed Shared Memory as Com...
Message Passing, Remote Procedure Calls and  Distributed Shared Memory as Com...Message Passing, Remote Procedure Calls and  Distributed Shared Memory as Com...
Message Passing, Remote Procedure Calls and Distributed Shared Memory as Com...
Sehrish Asif
 
Middleware and Middleware in distributed application
Middleware and Middleware in distributed applicationMiddleware and Middleware in distributed application
Middleware and Middleware in distributed application
Rishikese MR
 
3. challenges
3. challenges3. challenges
3. challenges
AbDul ThaYyal
 
dos mutual exclusion algos
dos mutual exclusion algosdos mutual exclusion algos
dos mutual exclusion algos
Akhil Sharma
 
Replication in Distributed Systems
Replication in Distributed SystemsReplication in Distributed Systems
Replication in Distributed Systems
Kavya Barnadhya Hazarika
 
Technical Architectures
Technical ArchitecturesTechnical Architectures
Technical Architectures
Damian T. Gordon
 
Basic features of distributed system
Basic features of distributed systemBasic features of distributed system
Basic features of distributed system
satish raj
 

What's hot (20)

Voting protocol
Voting protocolVoting protocol
Voting protocol
 
Cs556 section2
Cs556 section2Cs556 section2
Cs556 section2
 
9 fault-tolerance
9 fault-tolerance9 fault-tolerance
9 fault-tolerance
 
Fault Tolerant and Distributed System
Fault Tolerant and Distributed SystemFault Tolerant and Distributed System
Fault Tolerant and Distributed System
 
Fault tolerance
Fault toleranceFault tolerance
Fault tolerance
 
1.intro. to distributed system
1.intro. to distributed system1.intro. to distributed system
1.intro. to distributed system
 
Communications is distributed systems
Communications is distributed systemsCommunications is distributed systems
Communications is distributed systems
 
Fault tolerance in Information Centric Networks
Fault tolerance in Information Centric NetworksFault tolerance in Information Centric Networks
Fault tolerance in Information Centric Networks
 
CS6601 DISTRIBUTED SYSTEMS
CS6601 DISTRIBUTED SYSTEMSCS6601 DISTRIBUTED SYSTEMS
CS6601 DISTRIBUTED SYSTEMS
 
Distributed Systems Introduction and Importance
Distributed Systems Introduction and Importance Distributed Systems Introduction and Importance
Distributed Systems Introduction and Importance
 
Fault Tolerance 101
Fault Tolerance 101 Fault Tolerance 101
Fault Tolerance 101
 
Analysis of mutual exclusion algorithms with the significance and need of ele...
Analysis of mutual exclusion algorithms with the significance and need of ele...Analysis of mutual exclusion algorithms with the significance and need of ele...
Analysis of mutual exclusion algorithms with the significance and need of ele...
 
Chapter 11c coordination agreement
Chapter 11c coordination agreementChapter 11c coordination agreement
Chapter 11c coordination agreement
 
Message Passing, Remote Procedure Calls and Distributed Shared Memory as Com...
Message Passing, Remote Procedure Calls and  Distributed Shared Memory as Com...Message Passing, Remote Procedure Calls and  Distributed Shared Memory as Com...
Message Passing, Remote Procedure Calls and Distributed Shared Memory as Com...
 
Middleware and Middleware in distributed application
Middleware and Middleware in distributed applicationMiddleware and Middleware in distributed application
Middleware and Middleware in distributed application
 
3. challenges
3. challenges3. challenges
3. challenges
 
dos mutual exclusion algos
dos mutual exclusion algosdos mutual exclusion algos
dos mutual exclusion algos
 
Replication in Distributed Systems
Replication in Distributed SystemsReplication in Distributed Systems
Replication in Distributed Systems
 
Technical Architectures
Technical ArchitecturesTechnical Architectures
Technical Architectures
 
Basic features of distributed system
Basic features of distributed systemBasic features of distributed system
Basic features of distributed system
 

Similar to Principles of Compiler Design

System software module 4 presentation file
System software module 4 presentation fileSystem software module 4 presentation file
System software module 4 presentation file
jithujithin657
 
Chapter 1.pptx
Chapter 1.pptxChapter 1.pptx
Chapter 1.pptx
NesredinTeshome1
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
sivaganesh293
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
sivaganesh293
 
1._Introduction_.pptx
1._Introduction_.pptx1._Introduction_.pptx
1._Introduction_.pptx
Anbarasan Radhakrishnan R
 
COMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptxCOMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptx
Rossy719186
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
Sarmad Ali
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
ElakkiaU
 
what is compiler and five phases of compiler
what is compiler and five phases of compilerwhat is compiler and five phases of compiler
what is compiler and five phases of compiler
adilmehmood93
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
Abha Damani
 
Phases of Compiler.pdf
Phases of Compiler.pdfPhases of Compiler.pdf
Phases of Compiler.pdf
SuchandaBanerjee6
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptx
SuchandaBanerjee6
 
Principles of Compiler Design - Introduction
Principles of Compiler Design - IntroductionPrinciples of Compiler Design - Introduction
Principles of Compiler Design - Introduction
sheelarajasekar205
 
1 compiler outline
1 compiler outline1 compiler outline
1 compiler outline
ASHOK KUMAR REDDY
 
Compiler Design Material
Compiler Design MaterialCompiler Design Material
Compiler Design Material
Dr. C.V. Suresh Babu
 
Assignment1
Assignment1Assignment1
Assignment1
Sunita Milind Dol
 
The Phases of a Compiler
The Phases of a CompilerThe Phases of a Compiler
The Phases of a Compiler
Radhika Talaviya
 
Introduction to Compiler Construction
Introduction to Compiler Construction Introduction to Compiler Construction
Introduction to Compiler Construction
Sarmad Ali
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
Tanzeela_Hussain
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
Ahmed Raza
 

Similar to Principles of Compiler Design (20)

System software module 4 presentation file
System software module 4 presentation fileSystem software module 4 presentation file
System software module 4 presentation file
 
Chapter 1.pptx
Chapter 1.pptxChapter 1.pptx
Chapter 1.pptx
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
 
Compier Design_Unit I.ppt
Compier Design_Unit I.pptCompier Design_Unit I.ppt
Compier Design_Unit I.ppt
 
1._Introduction_.pptx
1._Introduction_.pptx1._Introduction_.pptx
1._Introduction_.pptx
 
COMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptxCOMPILER CONSTRUCTION KU 1.pptx
COMPILER CONSTRUCTION KU 1.pptx
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 
An Introduction to the Compiler Designss
An Introduction to the Compiler DesignssAn Introduction to the Compiler Designss
An Introduction to the Compiler Designss
 
what is compiler and five phases of compiler
what is compiler and five phases of compilerwhat is compiler and five phases of compiler
what is compiler and five phases of compiler
 
Introduction to compiler
Introduction to compilerIntroduction to compiler
Introduction to compiler
 
Phases of Compiler.pdf
Phases of Compiler.pdfPhases of Compiler.pdf
Phases of Compiler.pdf
 
Phases of Compiler.pptx
Phases of Compiler.pptxPhases of Compiler.pptx
Phases of Compiler.pptx
 
Principles of Compiler Design - Introduction
Principles of Compiler Design - IntroductionPrinciples of Compiler Design - Introduction
Principles of Compiler Design - Introduction
 
1 compiler outline
1 compiler outline1 compiler outline
1 compiler outline
 
Compiler Design Material
Compiler Design MaterialCompiler Design Material
Compiler Design Material
 
Assignment1
Assignment1Assignment1
Assignment1
 
The Phases of a Compiler
The Phases of a CompilerThe Phases of a Compiler
The Phases of a Compiler
 
Introduction to Compiler Construction
Introduction to Compiler Construction Introduction to Compiler Construction
Introduction to Compiler Construction
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Compiler Construction
Compiler ConstructionCompiler Construction
Compiler Construction
 

Recently uploaded

Data Communication and Computer Networks Management System Project Report.pdf
Data Communication and Computer Networks Management System Project Report.pdfData Communication and Computer Networks Management System Project Report.pdf
Data Communication and Computer Networks Management System Project Report.pdf
Kamal Acharya
 
Better Builder Magazine, Issue 49 / Spring 2024
Better Builder Magazine, Issue 49 / Spring 2024Better Builder Magazine, Issue 49 / Spring 2024
Better Builder Magazine, Issue 49 / Spring 2024
Better Builder Magazine
 
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 MinutesCall Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
kamka4105
 
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdfFUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
EMERSON EDUARDO RODRIGUES
 
一比一原版(psu学位证书)美国匹兹堡州立大学毕业证如何办理
一比一原版(psu学位证书)美国匹兹堡州立大学毕业证如何办理一比一原版(psu学位证书)美国匹兹堡州立大学毕业证如何办理
一比一原版(psu学位证书)美国匹兹堡州立大学毕业证如何办理
nonods
 
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdfAsymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
felixwold
 
❣Independent Call Girls Chennai 💯Call Us 🔝 7737669865 🔝💃Independent Chennai E...
❣Independent Call Girls Chennai 💯Call Us 🔝 7737669865 🔝💃Independent Chennai E...❣Independent Call Girls Chennai 💯Call Us 🔝 7737669865 🔝💃Independent Chennai E...
❣Independent Call Girls Chennai 💯Call Us 🔝 7737669865 🔝💃Independent Chennai E...
nainakaoornoida
 
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdfSELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
Pallavi Sharma
 
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdfSri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
Balvir Singh
 
Intuit CRAFT demonstration presentation for sde
Intuit CRAFT demonstration presentation for sdeIntuit CRAFT demonstration presentation for sde
Intuit CRAFT demonstration presentation for sde
ShivangMishra54
 
College Call Girls Kolkata 🔥 7014168258 🔥 Real Fun With Sexual Girl Available...
College Call Girls Kolkata 🔥 7014168258 🔥 Real Fun With Sexual Girl Available...College Call Girls Kolkata 🔥 7014168258 🔥 Real Fun With Sexual Girl Available...
College Call Girls Kolkata 🔥 7014168258 🔥 Real Fun With Sexual Girl Available...
Ak47
 
paper relate Chozhavendhan et al. 2020.pdf
paper relate Chozhavendhan et al. 2020.pdfpaper relate Chozhavendhan et al. 2020.pdf
paper relate Chozhavendhan et al. 2020.pdf
ShurooqTaib
 
Call Girls Chandigarh 🔥 7014168258 🔥 Real Fun With Sexual Girl Available 24/7...
Call Girls Chandigarh 🔥 7014168258 🔥 Real Fun With Sexual Girl Available 24/7...Call Girls Chandigarh 🔥 7014168258 🔥 Real Fun With Sexual Girl Available 24/7...
Call Girls Chandigarh 🔥 7014168258 🔥 Real Fun With Sexual Girl Available 24/7...
shourabjaat424
 
CSP_Study - Notes (Paul McNeill) 2017.pdf
CSP_Study - Notes (Paul McNeill) 2017.pdfCSP_Study - Notes (Paul McNeill) 2017.pdf
CSP_Study - Notes (Paul McNeill) 2017.pdf
Ismail Sultan
 
AN INTRODUCTION OF AI & SEARCHING TECHIQUES
AN INTRODUCTION OF AI & SEARCHING TECHIQUESAN INTRODUCTION OF AI & SEARCHING TECHIQUES
AN INTRODUCTION OF AI & SEARCHING TECHIQUES
drshikhapandey2022
 
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Dr.Costas Sachpazis
 
Basic principle and types Static Relays ppt
Basic principle and  types  Static Relays pptBasic principle and  types  Static Relays ppt
Basic principle and types Static Relays ppt
Sri Ramakrishna Institute of Technology
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
gapboxn
 
Call Girls Madurai 8824825030 Escort In Madurai service 24X7
Call Girls Madurai 8824825030 Escort In Madurai service 24X7Call Girls Madurai 8824825030 Escort In Madurai service 24X7
Call Girls Madurai 8824825030 Escort In Madurai service 24X7
Poonam Singh
 
Butterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdfButterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdf
Lubi Valves
 

Recently uploaded (20)

Data Communication and Computer Networks Management System Project Report.pdf
Data Communication and Computer Networks Management System Project Report.pdfData Communication and Computer Networks Management System Project Report.pdf
Data Communication and Computer Networks Management System Project Report.pdf
 
Better Builder Magazine, Issue 49 / Spring 2024
Better Builder Magazine, Issue 49 / Spring 2024Better Builder Magazine, Issue 49 / Spring 2024
Better Builder Magazine, Issue 49 / Spring 2024
 
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 MinutesCall Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
 
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdfFUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
 
一比一原版(psu学位证书)美国匹兹堡州立大学毕业证如何办理
一比一原版(psu学位证书)美国匹兹堡州立大学毕业证如何办理一比一原版(psu学位证书)美国匹兹堡州立大学毕业证如何办理
一比一原版(psu学位证书)美国匹兹堡州立大学毕业证如何办理
 
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdfAsymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
Asymmetrical Repulsion Magnet Motor Ratio 6-7.pdf
 
❣Independent Call Girls Chennai 💯Call Us 🔝 7737669865 🔝💃Independent Chennai E...
❣Independent Call Girls Chennai 💯Call Us 🔝 7737669865 🔝💃Independent Chennai E...❣Independent Call Girls Chennai 💯Call Us 🔝 7737669865 🔝💃Independent Chennai E...
❣Independent Call Girls Chennai 💯Call Us 🔝 7737669865 🔝💃Independent Chennai E...
 
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdfSELENIUM CONF -PALLAVI SHARMA - 2024.pdf
SELENIUM CONF -PALLAVI SHARMA - 2024.pdf
 
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdfSri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
 
Intuit CRAFT demonstration presentation for sde
Intuit CRAFT demonstration presentation for sdeIntuit CRAFT demonstration presentation for sde
Intuit CRAFT demonstration presentation for sde
 
College Call Girls Kolkata 🔥 7014168258 🔥 Real Fun With Sexual Girl Available...
College Call Girls Kolkata 🔥 7014168258 🔥 Real Fun With Sexual Girl Available...College Call Girls Kolkata 🔥 7014168258 🔥 Real Fun With Sexual Girl Available...
College Call Girls Kolkata 🔥 7014168258 🔥 Real Fun With Sexual Girl Available...
 
paper relate Chozhavendhan et al. 2020.pdf
paper relate Chozhavendhan et al. 2020.pdfpaper relate Chozhavendhan et al. 2020.pdf
paper relate Chozhavendhan et al. 2020.pdf
 
Call Girls Chandigarh 🔥 7014168258 🔥 Real Fun With Sexual Girl Available 24/7...
Call Girls Chandigarh 🔥 7014168258 🔥 Real Fun With Sexual Girl Available 24/7...Call Girls Chandigarh 🔥 7014168258 🔥 Real Fun With Sexual Girl Available 24/7...
Call Girls Chandigarh 🔥 7014168258 🔥 Real Fun With Sexual Girl Available 24/7...
 
CSP_Study - Notes (Paul McNeill) 2017.pdf
CSP_Study - Notes (Paul McNeill) 2017.pdfCSP_Study - Notes (Paul McNeill) 2017.pdf
CSP_Study - Notes (Paul McNeill) 2017.pdf
 
AN INTRODUCTION OF AI & SEARCHING TECHIQUES
AN INTRODUCTION OF AI & SEARCHING TECHIQUESAN INTRODUCTION OF AI & SEARCHING TECHIQUES
AN INTRODUCTION OF AI & SEARCHING TECHIQUES
 
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
 
Basic principle and types Static Relays ppt
Basic principle and  types  Static Relays pptBasic principle and  types  Static Relays ppt
Basic principle and types Static Relays ppt
 
一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理一比一原版(UO毕业证)渥太华大学毕业证如何办理
一比一原版(UO毕业证)渥太华大学毕业证如何办理
 
Call Girls Madurai 8824825030 Escort In Madurai service 24X7
Call Girls Madurai 8824825030 Escort In Madurai service 24X7Call Girls Madurai 8824825030 Escort In Madurai service 24X7
Call Girls Madurai 8824825030 Escort In Madurai service 24X7
 
Butterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdfButterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdf
 

Principles of Compiler Design

  • 1. SRI RAMAKRISHNA INSTITUTE OF TECHNOLOGY, COIMBATORE-10 (An Autonomous Institution) Department of Information Technology Academic Year 2021-22 III Year 5th Semester UITC013 - PRINCIPLES OF COMPILER DESIGN M. MARIMUTHU, AP/IT
  • 2. What are Compilers? • Compiler is a program which translates a program written in one language (the source language) to an equivalent program in other language (the target language)
  • 3. Compilers • Translates from one representation of the program to another • Typically from high level source code to low level machine code or object code. • Source code is normally optimized for human readability. – Expressive: matches our notion of languages – Redundant to help avoid programming errors
  • 4. Compilers…(2) • Machine code is optimized for hardware. – Redundancy is reduced – Information about the intent is lost.
  • 6. Phases of a Compiler
  • 7. Phases of a Compiler.. • A compiler operates in phases, each of which transforms the source program from one representation into another representation. • They communicate with error handlers. • They communicate with the symbol table.
  • 8. Symbol Table Management • An essential function of a compiler is to record the identifiers used in the source program and collect information about various attributes of each identifier. • These attributes may provide information about the storage allocated for an identifier, its type, its scope and in the case of procedure names, such things as the number and types of its arguments, the method of passing each argument and the type returned.
  • 9. Symbol Table Management… • A symbol table is a data structure containing a record for each identifier, with fields for the attributes of the identifier. • The data structure allows us to find the record for each identifier quickly and to store or retrieve data from that record quickly. • When an identifier in the source program is detected by the lexical analyzer, the identifier is entered into the symbol table.
  • 10. Symbol Table Management… • However, the attributes of an identifier cannot normally be determined during lexical analysis. For example, in a Pascal declaration like. Var a,b,c: real; The type “real” is not known when a,b and c are seen by the lexical analyzer. • The remaining phases enter information about identifiers into the symbol table and use this information in various ways.
  • 11. Error Detection and Reporting • Each phase can encounter errors. However, after detecting an error, a phase must deal with that error, so that compilation can proceed allowing further errors in the source program to be detected. • The lexical phase can detect errors where the characters remaining in the input do not form any token of the language.
  • 12. Error Detection and Reporting • Error where the token stream violates the structure rules of the language are determined by the syntax analysis phase. • During semantic analysis the compiler tries to detect constructs that have the right syntactic structure but no meaning to the operation involved.
  • 13. Error Detection and Reporting • All phases may encounter errors such as, • Lexical Phase – Unable to proceed because the next token in the source program may be misspelled. • Syntax Phase – Structure of the statement violates the rules of programming language. • Semantic – No meaning in the operation involved.
  • 14. Error Detection and Reporting • Intermediate – Operands have incompatible data types. • Code Optimizer – Certain statements may never be reached. • Code Generation – Constant is too long. • Symbol table – Multiple declared variables.
  • 15. Lexical Analysis • The lexical analysis phase reads the characters in the source program and groups them into a stream of tokens. • Each token represents a logically cohesive sequence of characters, such as an identifier, a keyword, a punctuation character or a operator, etc. • The character sequence forming a token is called the lexeme for the token.
  • 16. Lexical Analysis • Certain tokens will be augmented by a “lexical value”. The lexical analyzer not only generates a token, but also it enters the lexeme into the symbol table. • Eg., Consider the expression a:= b+c*20 The representation of the above expression after lexical analysis is, id1 = id2 + id3 * 20
  • 17. Syntax Analysis • This phase receives the tokens generated by previous phase (Lexical Analysis) as input and produces a hierarchical structure called syntax or Parse tree as output. • It checks whether the statements are up to the syntax of the programming language constructs or not. • A Parse tree represents the syntactic structure of the input. A Syntax tree is a compressed representation of the parse tree in which the operators appear as the interior nodes and the operands as child nodes.
  • 18. Semantic Analysis • This phase checks the source program for the meaning of syntax tree, semantic errors and gathers “type compatible information” for the subsequent phases. • Type Checking - “for each operator, the operands are checked to find whether they are acceptable for that operator. • For example, character data type cannot be used in an arithmetic expression
  • 19. Intermediate Code Generation • This phase converts the output of semantic analyzer into an intermediate representation. • Intermediate representation should have two important properties:- – It should be easy to produce, – Easy to translate into the target program • Some of the intermediate forms are – Syntax Trees – Postfix Notation – Three address code – having at most three operands
  • 20. Code Optimization • Object code programs need to be small and faster than the source program. Hence this phase optimizes the intermediate representation of the source program into an efficient code by reducing the unnecessary statements and operands.
  • 21. Code Optimization - Examples • Detection and removal of dead (unreachable) code. • Local optimization :- Elimination of common sub expressions • Loop optimization :- Finding out loop invariants and avoiding them.
  • 22. Code Generation • This phase converts the optimized intermediate code into target code which can be either Assembly code or Machine code. • This phase also allocates memory locations for the variables used in the program (allocation of registers and memory)
  翻译: