SlideShare ist ein Scribd-Unternehmen logo
1 von 34
Submitted By
Ujjwal matoliya
Atal Bihari Vajpayee Vishwavidyalaya
Department of Computer Science and Information
Session 2022-23
(SDT)Syntax Directed Translation
INDEX
Semantic Analizer
Application of Syntax Directed Translation
How to Evaluate a SDT
Differences between Synthesized and Inherited
Attributes
S-attributed SDT
L-attributed SDT
Compiler Phases
Semantic Analizer
INPUT
OUTPUT
Syntax directed translation
In syntax directed translation, along with the
grammar we associate some informal
notations and these notations are called as
semantic rules.
So we can say that
Grammar + semantic rule = SDT (syntax directed translati
on)
Application of Syntax Directed Translation
We use SDT(Syntax Directed Translation) for
Executing Arithmetic Expressions
Conversion from infix to postfix expression
Conversion from infix to prefix expression
For Binary to decimal conversion
Counting the number of Reductions
Creating a Syntax tree
Generating intermediate code
Storing information into the symbol table
Type checking
Production Semantic Rules
E → E # T / T E.val := E.val * T.val
T → T & F / F T.val := T.val + F.val
F →id F.val := id.l.val
How to Evaluate a SDT
S->AS {printf (1)}
S->AB {printf (2)}
A->a {printf (3)}
B->bc {printf (4)}
B->db {printf (5)}
C->c {printf (6)}
(SDT)Syntax Directed Translation
S->AS {printf (1)}
S->AB {printf (2)}
A->a {printf (3)}
B->bc {printf (4)}
B->db {printf (5)}
C->c {printf (6)}
(SDT)Syntax Directed Translation
INPUT STRING = aadbc
S->AS {printf (1)}
S->AB {printf (2)}
A->a {printf (3)}
B->bc {printf (4)}
B->db {printf (5)}
C->c {printf (6)}
(SDT)Syntax Directed Translation
INPUT STRING = aadbc
OUTPUT STRING= ?
S S->AS {printf (1)}
S->AB {printf (2)}
A->a {printf (3)}
B->bc {printf (4)}
B->dB {printf (5)}
C->c {printf (6)}
S
A S 1
S->AS {printf (1)}
S->AB {printf (2)}
A->a {printf (3)}
B->bc {printf (4)}
B->dB {printf (5)}
C->c {printf (6)}
S
A S 1
A B 2
S->AS {printf (1)}
S->AB {printf (2)}
A->a {printf (3)}
B->bc {printf (4)}
B->dB {printf (5)}
C->c {printf (6)}
S
A S 1
A B 2
d B 5
S->AS {printf (1)}
S->AB {printf (2)}
A->a {printf (3)}
B->bc {printf (4)}
B->dB {printf (5)}
C->c {printf (6)}
S
A S 1
A B 2
d B 5
b C 4
S->AS {printf (1)}
S->AB {printf (2)}
A->a {printf (3)}
B->bc {printf (4)}
B->dB {printf (5)}
C->c {printf (6)}
S
A S 1
A B 2
d B 5
b C 4
C 6
S->AS {printf (1)}
S->AB {printf (2)}
A->a {printf (3)}
B->bc {printf (4)}
B->dB {printf (5)}
C->c {printf (6)}
S
A S 1
A B 2
d B 5
b C 4
C 6
Top Down
S->AS {printf (1)}
S->AB {printf (2)}
A->a {printf (3)}
B->bc {printf (4)}
B->dB {printf (5)}
C->c {printf (6)}
S->AS {printf (1)}
S->AB {printf (2)}
A->a {printf (3)}
B->bc {printf (4)}
B->dB {printf (5)}
C->c {printf (6)}
S
A S 1
A B 2
d B 5
b C 4
C 6
Top Down
Bottom Up
S
A S 1
A B 2
d B 5
b C 4
C 6
Top Down
S
A S 1
A B 2
d B 5
b C 4
C 6
Top Down
S->AS {printf (1)}
S->AB {printf (2)}
A->a {printf (3)}
B->bc {printf (4)}
B->dB {printf (5)}
C->c {printf (6)}
A 3
A 3
S
A S 1
A B 2
d B 5
b C 4
C 6
Top Down
S->AS {printf (1)}
S->AB {printf (2)}
A->a {printf (3)}
B->bc {printf (4)}
B->dB {printf (5)}
C->c {printf (6)}
A 3
A 3
S
A S 1
A B 2
d B 5
b C 4
C 6
Bottom Up
S->AS {printf (1)}
S->AB {printf (2)}
A->a {printf (3)}
B->bc {printf (4)}
B->dB {printf (5)}
C->c {printf (6)}
A 3
A 3
Synthesized
Inherited
Synthesized
S-attributed SDT :
If an SDT uses only synthesized attributes, it is called as S-attributed
SDT.
S-attributed SDTs are evaluated in bottom-up parsing, as the values
of the parent nodes depend upon the values of the child nodes.
Semantic actions are placed in rightmost place of RHS.
L-attributed SDT:
If an SDT uses both synthesized attributes and inherited attributes
with a restriction that inherited attribute can inherit values from left
siblings only, it is called as L-attributed SDT.
Attributes in L-attributed SDTs are evaluated by depth-first and left-
to-right parsing manner.
Semantic actions are placed anywhere in RHS.
Example : S->ABC, Here attribute B can only obtain its value either
from the parent – S or its left sibling A but It can’t inherit from its
right sibling C. Same goes for A & C – A can only get its value from
its parent & C can get its value from S, A, & B as well because C is
the rightmost attribute in the given production.
Differences between Synthesized
and Inherited Attributes
S.NO Synthesized Attributes Inherited Attributes
1.
An attribute is said to be Synthesized attribute if its
parse tree node value is determined by the attribute
value at child nodes.
An attribute is said to be Inherited
attribute if its parse tree node value is
determined by the attribute value at
parent and/or siblings node.
2. The production must have non-terminal as its head.
The production must have non-
terminal as a symbol in its body.
3.
A synthesized attribute at node n is defined only in
terms of attribute values at the children of n itself.
A Inherited attribute at node n is
defined only in terms of attribute
values of n’s parent, n itself, and n’s
siblings.
4.
It can be evaluated during a single bottom-up
traversal of parse tree.
It can be evaluated during a single
top-down and sideways traversal of
parse tree.
5.
Synthesized attributes can be contained by both the
terminals or non-terminals.
Inherited attributes can’t be
contained by both, It is only
contained by non-terminals.
6.
Synthesized attribute is used by both S-attributed
SDT and L-attributed SDT.
Inherited attribute is used by only L-
attributed SDT.
compiler design ujjwal matoliya 2nd sem MCA.pptx

Weitere ähnliche Inhalte

Ähnlich wie compiler design ujjwal matoliya 2nd sem MCA.pptx

Lecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculusLecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculus
emailharmeet
 
Chapter 5 -Syntax Directed Translation - Copy.ppt
Chapter 5 -Syntax Directed Translation - Copy.pptChapter 5 -Syntax Directed Translation - Copy.ppt
Chapter 5 -Syntax Directed Translation - Copy.ppt
FamiDan
 
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
venkatapranaykumarGa
 
Chapter 5 - Syntax Directed Translation.ppt
Chapter 5 - Syntax Directed Translation.pptChapter 5 - Syntax Directed Translation.ppt
Chapter 5 - Syntax Directed Translation.ppt
MulugetaGebino
 
Chapter_5_Syntax_Directed_Translation.ppt
Chapter_5_Syntax_Directed_Translation.pptChapter_5_Syntax_Directed_Translation.ppt
Chapter_5_Syntax_Directed_Translation.ppt
SatyamVerma61
 

Ähnlich wie compiler design ujjwal matoliya 2nd sem MCA.pptx (20)

Lecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculusLecture 06 relational algebra and calculus
Lecture 06 relational algebra and calculus
 
Chapter 5 -Syntax Directed Translation - Copy.ppt
Chapter 5 -Syntax Directed Translation - Copy.pptChapter 5 -Syntax Directed Translation - Copy.ppt
Chapter 5 -Syntax Directed Translation - Copy.ppt
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translation
 
C Programming
C ProgrammingC Programming
C Programming
 
Syntax Directed Definition and its applications
Syntax Directed Definition and its applicationsSyntax Directed Definition and its applications
Syntax Directed Definition and its applications
 
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
12-Syntax Directed Definition – Evaluation Order-09-06-2023.ppt
 
Haskell Jumpstart
Haskell JumpstartHaskell Jumpstart
Haskell Jumpstart
 
18560 lecture6
18560 lecture618560 lecture6
18560 lecture6
 
Lecture 11 semantic analysis 2
Lecture 11 semantic analysis 2Lecture 11 semantic analysis 2
Lecture 11 semantic analysis 2
 
Chapter_5_Syntax_Directed_Translation.ppt
Chapter_5_Syntax_Directed_Translation.pptChapter_5_Syntax_Directed_Translation.ppt
Chapter_5_Syntax_Directed_Translation.ppt
 
Chapter 5 - Syntax Directed Translation.ppt
Chapter 5 - Syntax Directed Translation.pptChapter 5 - Syntax Directed Translation.ppt
Chapter 5 - Syntax Directed Translation.ppt
 
Introduction to programming c and data-structures
Introduction to programming c and data-structures Introduction to programming c and data-structures
Introduction to programming c and data-structures
 
Introduction to programming c and data structures
Introduction to programming c and data structuresIntroduction to programming c and data structures
Introduction to programming c and data structures
 
Chapter_5_Syntax_Directed_Translation.ppt
Chapter_5_Syntax_Directed_Translation.pptChapter_5_Syntax_Directed_Translation.ppt
Chapter_5_Syntax_Directed_Translation.ppt
 
IBM Cloud University: Java, Node.js and Swift
IBM Cloud University: Java, Node.js and SwiftIBM Cloud University: Java, Node.js and Swift
IBM Cloud University: Java, Node.js and Swift
 
Attribute grammer
Attribute grammerAttribute grammer
Attribute grammer
 
Parsing
ParsingParsing
Parsing
 
InterConnect: Java, Node.js and Swift - Which, Why and When
InterConnect: Java, Node.js and Swift - Which, Why and WhenInterConnect: Java, Node.js and Swift - Which, Why and When
InterConnect: Java, Node.js and Swift - Which, Why and When
 
07.05 division
07.05 division07.05 division
07.05 division
 
Compiler Design Material 2
Compiler Design Material 2Compiler Design Material 2
Compiler Design Material 2
 

Mehr von ujjwalmatoliya

Data Frames and Scatterplots in R language ujjwal matoliya.pptx
Data Frames and Scatterplots in R language ujjwal matoliya.pptxData Frames and Scatterplots in R language ujjwal matoliya.pptx
Data Frames and Scatterplots in R language ujjwal matoliya.pptx
ujjwalmatoliya
 
3 address code ujjwal matoliya.pptx
3 address code ujjwal matoliya.pptx3 address code ujjwal matoliya.pptx
3 address code ujjwal matoliya.pptx
ujjwalmatoliya
 
2-3 tree ujjwal matoliya .pptx
2-3 tree ujjwal matoliya .pptx2-3 tree ujjwal matoliya .pptx
2-3 tree ujjwal matoliya .pptx
ujjwalmatoliya
 

Mehr von ujjwalmatoliya (20)

kisan bill ujjwal matoliya.pptx
kisan bill ujjwal matoliya.pptxkisan bill ujjwal matoliya.pptx
kisan bill ujjwal matoliya.pptx
 
Data Frames and Scatterplots in R language ujjwal matoliya.pptx
Data Frames and Scatterplots in R language ujjwal matoliya.pptxData Frames and Scatterplots in R language ujjwal matoliya.pptx
Data Frames and Scatterplots in R language ujjwal matoliya.pptx
 
Floyd’s and Warshal’s Algorithm ujjwal matoliya.pptx
Floyd’s and Warshal’s Algorithm ujjwal matoliya.pptxFloyd’s and Warshal’s Algorithm ujjwal matoliya.pptx
Floyd’s and Warshal’s Algorithm ujjwal matoliya.pptx
 
congestion ujjwal matoliya.pptx
congestion ujjwal matoliya.pptxcongestion ujjwal matoliya.pptx
congestion ujjwal matoliya.pptx
 
Global Attributes Window Event Attributes Form Events Ujjwal matoliya.pptx
Global Attributes Window Event Attributes Form Events Ujjwal matoliya.pptxGlobal Attributes Window Event Attributes Form Events Ujjwal matoliya.pptx
Global Attributes Window Event Attributes Form Events Ujjwal matoliya.pptx
 
Instruction format UJJWAL MATOLIYA.pptx
Instruction format UJJWAL MATOLIYA.pptxInstruction format UJJWAL MATOLIYA.pptx
Instruction format UJJWAL MATOLIYA.pptx
 
javascript function ujjwal matoliya.pptx
javascript function ujjwal matoliya.pptxjavascript function ujjwal matoliya.pptx
javascript function ujjwal matoliya.pptx
 
string functions in SQL ujjwal matoliya.pptx
string functions in SQL ujjwal matoliya.pptxstring functions in SQL ujjwal matoliya.pptx
string functions in SQL ujjwal matoliya.pptx
 
jdbc Java Database Connectivity ujjwal matoliya jdbc.pptx
 jdbc Java Database Connectivity ujjwal matoliya jdbc.pptx jdbc Java Database Connectivity ujjwal matoliya jdbc.pptx
jdbc Java Database Connectivity ujjwal matoliya jdbc.pptx
 
3 address code ujjwal matoliya.pptx
3 address code ujjwal matoliya.pptx3 address code ujjwal matoliya.pptx
3 address code ujjwal matoliya.pptx
 
2-3 tree ujjwal matoliya .pptx
2-3 tree ujjwal matoliya .pptx2-3 tree ujjwal matoliya .pptx
2-3 tree ujjwal matoliya .pptx
 
Graph in Discrete mathemaetics.pptx
Graph in Discrete mathemaetics.pptxGraph in Discrete mathemaetics.pptx
Graph in Discrete mathemaetics.pptx
 
Quick Sort in data structure.pptx
Quick Sort in data structure.pptxQuick Sort in data structure.pptx
Quick Sort in data structure.pptx
 
Hadoop With R language.pptx
Hadoop With R language.pptxHadoop With R language.pptx
Hadoop With R language.pptx
 
LOGIC FAMILY.pptx
LOGIC FAMILY.pptxLOGIC FAMILY.pptx
LOGIC FAMILY.pptx
 
Transaction.pptx
Transaction.pptxTransaction.pptx
Transaction.pptx
 
cyclomatic complecity.pptx
cyclomatic complecity.pptxcyclomatic complecity.pptx
cyclomatic complecity.pptx
 
Congestion control algorithms.pptx
Congestion control algorithms.pptxCongestion control algorithms.pptx
Congestion control algorithms.pptx
 
computer graphic.pptx
computer graphic.pptxcomputer graphic.pptx
computer graphic.pptx
 
Game playing With AI.pptx
Game playing With AI.pptxGame playing With AI.pptx
Game playing With AI.pptx
 

Kürzlich hochgeladen

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Kürzlich hochgeladen (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 

compiler design ujjwal matoliya 2nd sem MCA.pptx

  • 1. Submitted By Ujjwal matoliya Atal Bihari Vajpayee Vishwavidyalaya Department of Computer Science and Information Session 2022-23 (SDT)Syntax Directed Translation
  • 2. INDEX Semantic Analizer Application of Syntax Directed Translation How to Evaluate a SDT Differences between Synthesized and Inherited Attributes S-attributed SDT L-attributed SDT
  • 4.
  • 7. Syntax directed translation In syntax directed translation, along with the grammar we associate some informal notations and these notations are called as semantic rules. So we can say that Grammar + semantic rule = SDT (syntax directed translati on)
  • 8. Application of Syntax Directed Translation We use SDT(Syntax Directed Translation) for Executing Arithmetic Expressions Conversion from infix to postfix expression Conversion from infix to prefix expression For Binary to decimal conversion Counting the number of Reductions Creating a Syntax tree Generating intermediate code Storing information into the symbol table Type checking
  • 9. Production Semantic Rules E → E # T / T E.val := E.val * T.val T → T & F / F T.val := T.val + F.val F →id F.val := id.l.val
  • 11. S->AS {printf (1)} S->AB {printf (2)} A->a {printf (3)} B->bc {printf (4)} B->db {printf (5)} C->c {printf (6)} (SDT)Syntax Directed Translation
  • 12. S->AS {printf (1)} S->AB {printf (2)} A->a {printf (3)} B->bc {printf (4)} B->db {printf (5)} C->c {printf (6)} (SDT)Syntax Directed Translation INPUT STRING = aadbc
  • 13. S->AS {printf (1)} S->AB {printf (2)} A->a {printf (3)} B->bc {printf (4)} B->db {printf (5)} C->c {printf (6)} (SDT)Syntax Directed Translation INPUT STRING = aadbc OUTPUT STRING= ?
  • 14. S S->AS {printf (1)} S->AB {printf (2)} A->a {printf (3)} B->bc {printf (4)} B->dB {printf (5)} C->c {printf (6)}
  • 15. S A S 1 S->AS {printf (1)} S->AB {printf (2)} A->a {printf (3)} B->bc {printf (4)} B->dB {printf (5)} C->c {printf (6)}
  • 16. S A S 1 A B 2 S->AS {printf (1)} S->AB {printf (2)} A->a {printf (3)} B->bc {printf (4)} B->dB {printf (5)} C->c {printf (6)}
  • 17. S A S 1 A B 2 d B 5 S->AS {printf (1)} S->AB {printf (2)} A->a {printf (3)} B->bc {printf (4)} B->dB {printf (5)} C->c {printf (6)}
  • 18. S A S 1 A B 2 d B 5 b C 4 S->AS {printf (1)} S->AB {printf (2)} A->a {printf (3)} B->bc {printf (4)} B->dB {printf (5)} C->c {printf (6)}
  • 19. S A S 1 A B 2 d B 5 b C 4 C 6 S->AS {printf (1)} S->AB {printf (2)} A->a {printf (3)} B->bc {printf (4)} B->dB {printf (5)} C->c {printf (6)}
  • 20. S A S 1 A B 2 d B 5 b C 4 C 6 Top Down S->AS {printf (1)} S->AB {printf (2)} A->a {printf (3)} B->bc {printf (4)} B->dB {printf (5)} C->c {printf (6)}
  • 21. S->AS {printf (1)} S->AB {printf (2)} A->a {printf (3)} B->bc {printf (4)} B->dB {printf (5)} C->c {printf (6)} S A S 1 A B 2 d B 5 b C 4 C 6 Top Down Bottom Up
  • 22. S A S 1 A B 2 d B 5 b C 4 C 6 Top Down
  • 23. S A S 1 A B 2 d B 5 b C 4 C 6 Top Down S->AS {printf (1)} S->AB {printf (2)} A->a {printf (3)} B->bc {printf (4)} B->dB {printf (5)} C->c {printf (6)} A 3 A 3
  • 24. S A S 1 A B 2 d B 5 b C 4 C 6 Top Down S->AS {printf (1)} S->AB {printf (2)} A->a {printf (3)} B->bc {printf (4)} B->dB {printf (5)} C->c {printf (6)} A 3 A 3
  • 25. S A S 1 A B 2 d B 5 b C 4 C 6 Bottom Up S->AS {printf (1)} S->AB {printf (2)} A->a {printf (3)} B->bc {printf (4)} B->dB {printf (5)} C->c {printf (6)} A 3 A 3
  • 27.
  • 28.
  • 29.
  • 31. S-attributed SDT : If an SDT uses only synthesized attributes, it is called as S-attributed SDT. S-attributed SDTs are evaluated in bottom-up parsing, as the values of the parent nodes depend upon the values of the child nodes. Semantic actions are placed in rightmost place of RHS. L-attributed SDT: If an SDT uses both synthesized attributes and inherited attributes with a restriction that inherited attribute can inherit values from left siblings only, it is called as L-attributed SDT. Attributes in L-attributed SDTs are evaluated by depth-first and left- to-right parsing manner. Semantic actions are placed anywhere in RHS. Example : S->ABC, Here attribute B can only obtain its value either from the parent – S or its left sibling A but It can’t inherit from its right sibling C. Same goes for A & C – A can only get its value from its parent & C can get its value from S, A, & B as well because C is the rightmost attribute in the given production.
  • 32. Differences between Synthesized and Inherited Attributes
  • 33. S.NO Synthesized Attributes Inherited Attributes 1. An attribute is said to be Synthesized attribute if its parse tree node value is determined by the attribute value at child nodes. An attribute is said to be Inherited attribute if its parse tree node value is determined by the attribute value at parent and/or siblings node. 2. The production must have non-terminal as its head. The production must have non- terminal as a symbol in its body. 3. A synthesized attribute at node n is defined only in terms of attribute values at the children of n itself. A Inherited attribute at node n is defined only in terms of attribute values of n’s parent, n itself, and n’s siblings. 4. It can be evaluated during a single bottom-up traversal of parse tree. It can be evaluated during a single top-down and sideways traversal of parse tree. 5. Synthesized attributes can be contained by both the terminals or non-terminals. Inherited attributes can’t be contained by both, It is only contained by non-terminals. 6. Synthesized attribute is used by both S-attributed SDT and L-attributed SDT. Inherited attribute is used by only L- attributed SDT.