SlideShare a Scribd company logo
Unit 3
Translation of Expressions
1. Operations within Expressions
2. Incremental Translation
3. Addressing Array elements
4. Translation of Array References
1. Operations within expressions
● SDD attributes:
○ code - denote three address code
○ addr - address that will hold value of non-terminal
● Top - points to current symbol table
● top.get() - retrieves entry of parameter passed
● gen() - generate 3 address instruction , pass operator in quotes
● new Temp() - Create distinct temp name
Translation of expression in compiler design
2. Incremental Translation
● Code attributes can be long strings, so they are usually generated incrementally
● In the incremental approach, gen not only constructs a three-address instruction, it appends the
instruction to the sequence of instructions generated so far.
● The sequence may either be retained in memory for further processing, or it may be output
incrementally.
3. Addressing Array Elements
12 18 24
0 1 2
Address Element Formula for calculation:
Translation of expression in compiler design
Translation of expression in compiler design
4. Translation of array references
Translation of expression in compiler design
Translation of expression in compiler design
Type Checking
1. Rules of type checking
2. Type conversions
3. Overloading of functions and operators
4. Type Inference and Polymorphic Functions
5. An algorithm for unification
What is type checking?
● assign a type expression to each component of the source program
● The compiler must then determine that these type expressions conform to a collection of logical
rules that is called the type system for the source language.
● It can be used to detect errors in the program.
● A sound type system eliminates the need for dynamic checking for type errors, because it allows us
to determine statically that these errors cannot occur when the target program runs.
● type checking have been used to improve the security of systems that allow software modules to
be imported and executed
Example:
1. Rules for Type Checking (Synthesis/Inference)
Type Synthesis
● builds up the type of an expression from the
types of its subexpressions.
● It requires names to be declared before
they are used.
● Eg. Type of E1+E2 is determined from types
of E1 and E2.
Type Inference
● Determines the type of a language
construct from the way it is used.
● Let null(x) be a function to check if list is
empty.
● Since null function applied on list, we can
say x is a list
2. Type Conversions/ Type Casting
● Type casting is converting one datatype to some other data type. It is executed using the
cast operator.
● Explicit type conversion in C is when the datatype conversion is user-defined according to
the program's needs. Explicit type conversion can easily change a particular data type to a
different one.
● Implicit type conversion is automatically done by the program.
● Need:
a = 5
b = 10.12
print(a+b)
Translation of expression in compiler design
Translation of expression in compiler design
Translation of expression in compiler design
3. Overloading of functions and operators
a+b
4. Type Inference and Polymorphic Functions
● Type inference is useful for a language like ML which is strongly typed, but does not require names
to be declared before they are used. Type inference ensures that names are used consistently.
● The term polymorphic refers to any code fragment that can be executed with arguments of
different types.
● polymorphism is characterized by parameters or type variables
Translation of expression in compiler design
Translation of expression in compiler design
Translation of expression in compiler design
5. Unification Algorithm
1. Unification is the problem of determining whether two expressions s and t can be
made identical by substituting expressions for the variables in s and t.
2. Testing equality of expressions is a special case of unification; if s and t have constants
but no variables, then s and t unify if and only if they are identical.
3. The unification algorithm in this section extends to graphs with cycles, so it can be
used to test structural equivalence of circular types
4. Type variables are represented by leaves and type constructors are represented by
interior nodes.
5. Nodes are grouped into equivalence classes; if two nodes are in the same equivalence
class, then the type expressions they represent must unify.
6. Thus, all interior nodes in the same class must be for the same type constructor, and
their corresponding children must be equivalent.
Finds representative node of equivalence class
Union merges classes with nodes s and t
Translation of expression in compiler design
Translation of expression in compiler design

More Related Content

What's hot (20)

PPTX
Code generation
Aparna Nayak
 
PPTX
Concurrency Control in Distributed Database.
Meghaj Mallick
 
PDF
Symbol table in compiler Design
Kuppusamy P
 
PPTX
Type checking in compiler design
Sudip Singh
 
PPT
Type Checking(Compiler Design) #ShareThisIfYouLike
United International University
 
PDF
Classes and Objects
yndaravind
 
PPTX
Specification-of-tokens
Dattatray Gandhmal
 
PPTX
Deadlock Prevention
prachi mewara
 
PPTX
Network layer - design Issues
قصي نسور
 
PPTX
RECURSIVE DESCENT PARSING
Jothi Lakshmi
 
PPTX
Back patching
santhiya thavanthi
 
PDF
Syntax directed translation
Akshaya Arunan
 
PPTX
RPC: Remote procedure call
Sunita Sahu
 
PPT
program flow mechanisms, advanced computer architecture
Pankaj Kumar Jain
 
PPTX
A simple approach of lexical analyzers
Archana Gopinath
 
PPT
Memory Management in OS
vampugani
 
PPTX
Congestion control
Aman Jaiswal
 
PPT
1.Role lexical Analyzer
Radhakrishnan Chinnusamy
 
PDF
Intermediate code generation in Compiler Design
Kuppusamy P
 
PPT
02. chapter 3 lexical analysis
raosir123
 
Code generation
Aparna Nayak
 
Concurrency Control in Distributed Database.
Meghaj Mallick
 
Symbol table in compiler Design
Kuppusamy P
 
Type checking in compiler design
Sudip Singh
 
Type Checking(Compiler Design) #ShareThisIfYouLike
United International University
 
Classes and Objects
yndaravind
 
Specification-of-tokens
Dattatray Gandhmal
 
Deadlock Prevention
prachi mewara
 
Network layer - design Issues
قصي نسور
 
RECURSIVE DESCENT PARSING
Jothi Lakshmi
 
Back patching
santhiya thavanthi
 
Syntax directed translation
Akshaya Arunan
 
RPC: Remote procedure call
Sunita Sahu
 
program flow mechanisms, advanced computer architecture
Pankaj Kumar Jain
 
A simple approach of lexical analyzers
Archana Gopinath
 
Memory Management in OS
vampugani
 
Congestion control
Aman Jaiswal
 
1.Role lexical Analyzer
Radhakrishnan Chinnusamy
 
Intermediate code generation in Compiler Design
Kuppusamy P
 
02. chapter 3 lexical analysis
raosir123
 

Similar to Translation of expression in compiler design (20)

PPTX
Unit 3 Compiler Design Regulation 2021.pptx
jeevitha404389
 
PPTX
Compiler Design Notes for rgpv 6tth sem students
MedhanshAgrawal
 
PPTX
Type checking compiler construction Chapter #6
Daniyal Mughal
 
PDF
Type Checking
A. S. M. Shafi
 
PDF
12TypeSystem.pdf
MdAshik35
 
PPTX
Chapter -5.pptx chapter five compiler design
gadisaAdamu
 
PDF
Compiler Construction | Lecture 7 | Type Checking
Eelco Visser
 
PPTX
Chapter 5 - Type Cheaking.pptxkgjkh,lhj,lghjhklj
Shemse Shukre
 
PDF
Software analysis and testing
NishaVatwani
 
PPT
Lecture 21 22
Najmul Hassan
 
PPT
Chapter 6 intermediate code generation
Vipul Naik
 
PDF
Project presentation PPT.pdf this is help for student who doing this complier...
AmitSingh395981
 
PPTX
Operators & Casts
Raghuveer Guthikonda
 
PPT
458237.-Compiler-Design-Intermediate-code-generation.ppt
PalaniSamyB3
 
PDF
+2 Computer Science - Volume II Notes
Andrew Raj
 
PDF
Ti1220 Lecture 7: Polymorphism
Eelco Visser
 
PPTX
Plagiarism introduction
Merin Paul
 
PPT
Chapter 6 Intermediate Code Generation
Radhakrishnan Chinnusamy
 
PPT
Life & Work of Robin Milner | Turing100@Persistent
Persistent Systems Ltd.
 
PPTX
Type Systems
Jordan Parmer
 
Unit 3 Compiler Design Regulation 2021.pptx
jeevitha404389
 
Compiler Design Notes for rgpv 6tth sem students
MedhanshAgrawal
 
Type checking compiler construction Chapter #6
Daniyal Mughal
 
Type Checking
A. S. M. Shafi
 
12TypeSystem.pdf
MdAshik35
 
Chapter -5.pptx chapter five compiler design
gadisaAdamu
 
Compiler Construction | Lecture 7 | Type Checking
Eelco Visser
 
Chapter 5 - Type Cheaking.pptxkgjkh,lhj,lghjhklj
Shemse Shukre
 
Software analysis and testing
NishaVatwani
 
Lecture 21 22
Najmul Hassan
 
Chapter 6 intermediate code generation
Vipul Naik
 
Project presentation PPT.pdf this is help for student who doing this complier...
AmitSingh395981
 
Operators & Casts
Raghuveer Guthikonda
 
458237.-Compiler-Design-Intermediate-code-generation.ppt
PalaniSamyB3
 
+2 Computer Science - Volume II Notes
Andrew Raj
 
Ti1220 Lecture 7: Polymorphism
Eelco Visser
 
Plagiarism introduction
Merin Paul
 
Chapter 6 Intermediate Code Generation
Radhakrishnan Chinnusamy
 
Life & Work of Robin Milner | Turing100@Persistent
Persistent Systems Ltd.
 
Type Systems
Jordan Parmer
 
Ad

Recently uploaded (20)

PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
PDF
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
PDF
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
PDF
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
PDF
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
PPTX
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Building Resilience with Digital Twins : Lessons from Korea
SANGHEE SHIN
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
TrustArc Webinar - Data Privacy Trends 2025: Mid-Year Insights & Program Stra...
TrustArc
 
Smart Air Quality Monitoring with Serrax AQM190 LITE
SERRAX TECHNOLOGIES LLP
 
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
Building a Production-Ready Barts Health Secure Data Environment Tooling, Acc...
Barts Health
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
SFWelly Summer 25 Release Highlights July 2025
Anna Loughnan Colquhoun
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Ad

Translation of expression in compiler design

  • 2. Translation of Expressions 1. Operations within Expressions 2. Incremental Translation 3. Addressing Array elements 4. Translation of Array References
  • 3. 1. Operations within expressions ● SDD attributes: ○ code - denote three address code ○ addr - address that will hold value of non-terminal ● Top - points to current symbol table ● top.get() - retrieves entry of parameter passed ● gen() - generate 3 address instruction , pass operator in quotes ● new Temp() - Create distinct temp name
  • 5. 2. Incremental Translation ● Code attributes can be long strings, so they are usually generated incrementally ● In the incremental approach, gen not only constructs a three-address instruction, it appends the instruction to the sequence of instructions generated so far. ● The sequence may either be retained in memory for further processing, or it may be output incrementally.
  • 6. 3. Addressing Array Elements 12 18 24 0 1 2 Address Element Formula for calculation:
  • 9. 4. Translation of array references
  • 12. Type Checking 1. Rules of type checking 2. Type conversions 3. Overloading of functions and operators 4. Type Inference and Polymorphic Functions 5. An algorithm for unification
  • 13. What is type checking? ● assign a type expression to each component of the source program ● The compiler must then determine that these type expressions conform to a collection of logical rules that is called the type system for the source language. ● It can be used to detect errors in the program. ● A sound type system eliminates the need for dynamic checking for type errors, because it allows us to determine statically that these errors cannot occur when the target program runs. ● type checking have been used to improve the security of systems that allow software modules to be imported and executed Example:
  • 14. 1. Rules for Type Checking (Synthesis/Inference) Type Synthesis ● builds up the type of an expression from the types of its subexpressions. ● It requires names to be declared before they are used. ● Eg. Type of E1+E2 is determined from types of E1 and E2. Type Inference ● Determines the type of a language construct from the way it is used. ● Let null(x) be a function to check if list is empty. ● Since null function applied on list, we can say x is a list
  • 15. 2. Type Conversions/ Type Casting ● Type casting is converting one datatype to some other data type. It is executed using the cast operator. ● Explicit type conversion in C is when the datatype conversion is user-defined according to the program's needs. Explicit type conversion can easily change a particular data type to a different one. ● Implicit type conversion is automatically done by the program. ● Need: a = 5 b = 10.12 print(a+b)
  • 19. 3. Overloading of functions and operators a+b
  • 20. 4. Type Inference and Polymorphic Functions ● Type inference is useful for a language like ML which is strongly typed, but does not require names to be declared before they are used. Type inference ensures that names are used consistently. ● The term polymorphic refers to any code fragment that can be executed with arguments of different types. ● polymorphism is characterized by parameters or type variables
  • 24. 5. Unification Algorithm 1. Unification is the problem of determining whether two expressions s and t can be made identical by substituting expressions for the variables in s and t. 2. Testing equality of expressions is a special case of unification; if s and t have constants but no variables, then s and t unify if and only if they are identical. 3. The unification algorithm in this section extends to graphs with cycles, so it can be used to test structural equivalence of circular types 4. Type variables are represented by leaves and type constructors are represented by interior nodes. 5. Nodes are grouped into equivalence classes; if two nodes are in the same equivalence class, then the type expressions they represent must unify. 6. Thus, all interior nodes in the same class must be for the same type constructor, and their corresponding children must be equivalent.
  • 25. Finds representative node of equivalence class Union merges classes with nodes s and t