SlideShare a Scribd company logo
1 of 10
L- ATTRIBUTE
Name: Khushboo Jethwa
Enrollment no. : 140950107028
Subject: Compiler Design
Subject Guide: Avneet Saluja
Attribute Grammar
• Attribute grammar is a special form of context-free
grammar where some additional information
(attributes) are appended to one or more of its non-
terminals in order to provide context-sensitive
information. Each attribute has well-defined domain of
values, such as integer, float, character, string, and
expressions.
• Attribute grammar is a medium to provide semantics
to the context-free grammar and it can help specify the
syntax and semantics of a programming language.
Attribute grammar (when viewed as a parse-tree) can
pass values or information among the nodes of a tree.
EXAMPLE
E → E + T { E.value = E.value + T.value }
• The right part of the CFG contains the semantic rules
that specify how the grammar should be interpreted.
Here, the values of non-terminals E and T are added
together and the result is copied to the non-terminal E.
• Semantic attributes may be assigned to their values
from their domain at the time of parsing and evaluated
at the time of assignment or conditions. Based on the
way the attributes get their values, they can be broadly
divided into two categories : synthesized attributes and
inherited attributes.
Synthesized attributes
• These attributes get values from the attribute
values of their child nodes. To illustrate, assume
the following production:
S → ABC
• If S is taking values from its child nodes (A,B,C),
then it is said to be a synthesized attribute, as the
values of ABC are synthesized to S.
• As in our previous example (E → E + T), the
parent node E gets its value from its child node.
Synthesized attributes never take values from
their parent nodes or any sibling nodes.
Inherited attributes
• In contrast to synthesized attributes, inherited
attributes can take values from parent and/or
siblings. As in the following production,
S → ABC
• A can get values from S, B and C. B can take
values from S, A, and C. Likewise, C can take
values from S, A, and B.
L-attributed SDT
• This form of SDT uses both synthesized and inherited
attributes with restriction of not taking values from right
siblings.
• In L-attributed SDTs, a non-terminal can get values from its
parent, child, and sibling nodes. As in the following
production
S → ABC
• S can take values from A, B, and C (synthesized). A can take
values from S only. B can take values from S and A. C can
get values from S, A, and B. No non-terminal can get values
from the sibling to its right.
• Attributes in L-attributed SDTs are evaluated by depth-first
and left-to-right parsing manner.
All S-attributes are L-attribute but all S-
arrtibute may or may not be L-attribute.
EXAMPLE
State whether the following are l attribute or
not.
1) A-> QR { R.i = f(A.i), Q.i =f(R.i) }
checking one by one semantic actions.
• for R.i = f(A.i), it’s a l-attribute as it’s a
inherited attibute from the parent.
• for Q.i =f(R.i), it’s not a l-attribute as it’s
inherited from the right sibling.
2) A-> BC { B.S = A.S }
checking one by one semantic actions.
• for B.S = A.S, it’s a l-attribute as it’s a
inherited attibute from the parent.
THANK YOU

More Related Content

What's hot

compiler ppt on symbol table
 compiler ppt on symbol table compiler ppt on symbol table
compiler ppt on symbol table
nadarmispapaulraj
 
Data structures question paper anna university
Data structures question paper anna universityData structures question paper anna university
Data structures question paper anna university
sangeethajames07
 

What's hot (20)

1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translation
 
Run time storage
Run time storageRun time storage
Run time storage
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
 
Symbol table in compiler Design
Symbol table in compiler DesignSymbol table in compiler Design
Symbol table in compiler Design
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Parsing
ParsingParsing
Parsing
 
Ambiguous & Unambiguous Grammar
Ambiguous & Unambiguous GrammarAmbiguous & Unambiguous Grammar
Ambiguous & Unambiguous Grammar
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
 
Principal source of optimization in compiler design
Principal source of optimization in compiler designPrincipal source of optimization in compiler design
Principal source of optimization in compiler design
 
compiler ppt on symbol table
 compiler ppt on symbol table compiler ppt on symbol table
compiler ppt on symbol table
 
RECURSIVE DESCENT PARSING
RECURSIVE DESCENT PARSINGRECURSIVE DESCENT PARSING
RECURSIVE DESCENT PARSING
 
COMPILER DESIGN Run-Time Environments
COMPILER DESIGN Run-Time EnvironmentsCOMPILER DESIGN Run-Time Environments
COMPILER DESIGN Run-Time Environments
 
Symbol Table
Symbol TableSymbol Table
Symbol Table
 
Decision properties of reular languages
Decision properties of reular languagesDecision properties of reular languages
Decision properties of reular languages
 
Compiler Chapter 1
Compiler Chapter 1Compiler Chapter 1
Compiler Chapter 1
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
1.1. the central concepts of automata theory
1.1. the central concepts of automata theory1.1. the central concepts of automata theory
1.1. the central concepts of automata theory
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design
 
Data structures question paper anna university
Data structures question paper anna universityData structures question paper anna university
Data structures question paper anna university
 

Similar to L attribute in compiler design

Similar to L attribute in compiler design (20)

Attribute grammer
Attribute grammerAttribute grammer
Attribute grammer
 
L14 Semantic analysis This process is crucial in various applications such a...
L14 Semantic analysis  This process is crucial in various applications such a...L14 Semantic analysis  This process is crucial in various applications such a...
L14 Semantic analysis This process is crucial in various applications such a...
 
Semantic Analysis.pptx
Semantic Analysis.pptxSemantic Analysis.pptx
Semantic Analysis.pptx
 
Semantics analysis
Semantics analysisSemantics analysis
Semantics analysis
 
Syntax Directed Definition and its applications
Syntax Directed Definition and its applicationsSyntax Directed Definition and its applications
Syntax Directed Definition and its applications
 
19IS305_U1_LP3_LM3-22-23-2.pdf
19IS305_U1_LP3_LM3-22-23-2.pdf19IS305_U1_LP3_LM3-22-23-2.pdf
19IS305_U1_LP3_LM3-22-23-2.pdf
 
18306_lec-2 (1).ppt
18306_lec-2 (1).ppt18306_lec-2 (1).ppt
18306_lec-2 (1).ppt
 
Chapter -4.pptx
Chapter -4.pptxChapter -4.pptx
Chapter -4.pptx
 
Unit iv-syntax-directed-translation
Unit iv-syntax-directed-translationUnit iv-syntax-directed-translation
Unit iv-syntax-directed-translation
 
Lecture 11 semantic analysis 2
Lecture 11 semantic analysis 2Lecture 11 semantic analysis 2
Lecture 11 semantic analysis 2
 
Data Models.pptx
Data Models.pptxData Models.pptx
Data Models.pptx
 
ER-Diagram.pptx
ER-Diagram.pptxER-Diagram.pptx
ER-Diagram.pptx
 
Lecture 10 semantic analysis 01
Lecture 10 semantic analysis 01Lecture 10 semantic analysis 01
Lecture 10 semantic analysis 01
 
Presentation of saad on e-r diagram.
Presentation of saad on e-r diagram.Presentation of saad on e-r diagram.
Presentation of saad on e-r diagram.
 
Database Design and Entity relationship Model.pptx
Database Design and Entity relationship Model.pptxDatabase Design and Entity relationship Model.pptx
Database Design and Entity relationship Model.pptx
 
DBMS Class 3
DBMS Class 3DBMS Class 3
DBMS Class 3
 
10287 lecture5(2)
10287 lecture5(2)10287 lecture5(2)
10287 lecture5(2)
 
Day 1 SQL.pptx
Day 1 SQL.pptxDay 1 SQL.pptx
Day 1 SQL.pptx
 
SQL.pptx
SQL.pptxSQL.pptx
SQL.pptx
 
Databases - Unit 2.pdf
Databases - Unit 2.pdfDatabases - Unit 2.pdf
Databases - Unit 2.pdf
 

More from khush_boo31 (6)

Classification of data mart
Classification of data martClassification of data mart
Classification of data mart
 
statement interface
statement interface statement interface
statement interface
 
context free language
context free languagecontext free language
context free language
 
parameter passing in c#
parameter passing in c#parameter passing in c#
parameter passing in c#
 
Knapsack problem using dynamic programming
Knapsack problem using dynamic programmingKnapsack problem using dynamic programming
Knapsack problem using dynamic programming
 
Parsing
ParsingParsing
Parsing
 

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
fonyou31
 

Recently uploaded (20)

Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 

L attribute in compiler design

  • 1. L- ATTRIBUTE Name: Khushboo Jethwa Enrollment no. : 140950107028 Subject: Compiler Design Subject Guide: Avneet Saluja
  • 2. Attribute Grammar • Attribute grammar is a special form of context-free grammar where some additional information (attributes) are appended to one or more of its non- terminals in order to provide context-sensitive information. Each attribute has well-defined domain of values, such as integer, float, character, string, and expressions. • Attribute grammar is a medium to provide semantics to the context-free grammar and it can help specify the syntax and semantics of a programming language. Attribute grammar (when viewed as a parse-tree) can pass values or information among the nodes of a tree.
  • 3. EXAMPLE E → E + T { E.value = E.value + T.value } • The right part of the CFG contains the semantic rules that specify how the grammar should be interpreted. Here, the values of non-terminals E and T are added together and the result is copied to the non-terminal E. • Semantic attributes may be assigned to their values from their domain at the time of parsing and evaluated at the time of assignment or conditions. Based on the way the attributes get their values, they can be broadly divided into two categories : synthesized attributes and inherited attributes.
  • 4. Synthesized attributes • These attributes get values from the attribute values of their child nodes. To illustrate, assume the following production: S → ABC • If S is taking values from its child nodes (A,B,C), then it is said to be a synthesized attribute, as the values of ABC are synthesized to S. • As in our previous example (E → E + T), the parent node E gets its value from its child node. Synthesized attributes never take values from their parent nodes or any sibling nodes.
  • 5. Inherited attributes • In contrast to synthesized attributes, inherited attributes can take values from parent and/or siblings. As in the following production, S → ABC • A can get values from S, B and C. B can take values from S, A, and C. Likewise, C can take values from S, A, and B.
  • 6. L-attributed SDT • This form of SDT uses both synthesized and inherited attributes with restriction of not taking values from right siblings. • In L-attributed SDTs, a non-terminal can get values from its parent, child, and sibling nodes. As in the following production S → ABC • S can take values from A, B, and C (synthesized). A can take values from S only. B can take values from S and A. C can get values from S, A, and B. No non-terminal can get values from the sibling to its right. • Attributes in L-attributed SDTs are evaluated by depth-first and left-to-right parsing manner.
  • 7. All S-attributes are L-attribute but all S- arrtibute may or may not be L-attribute.
  • 8. EXAMPLE State whether the following are l attribute or not. 1) A-> QR { R.i = f(A.i), Q.i =f(R.i) } checking one by one semantic actions. • for R.i = f(A.i), it’s a l-attribute as it’s a inherited attibute from the parent. • for Q.i =f(R.i), it’s not a l-attribute as it’s inherited from the right sibling.
  • 9. 2) A-> BC { B.S = A.S } checking one by one semantic actions. • for B.S = A.S, it’s a l-attribute as it’s a inherited attibute from the parent.