SlideShare a Scribd company logo
2
Most read
5
Most read
7
Most read
ATTRIBUTE
GRAMMAR
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
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.
CONCEPTS AND EXAMPLES
An attribute grammar may be informally defined as
a context-free grammar that has been extended to
provide context sensitivity using a set of
attributes, assignment of attribute values,
evaluation rules, and conditions. A finite, possibly
empty set of attributes is associated with each
distinct symbol in the grammar.
E → E + T { E.value = E.value + T.value }
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.
TWO TYPES
Synthesized attributes
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.
S-ATTRIBUTED SDT
If an SDT uses only synthesized attributes, it is
called as S-attributed SDT. These attributes are
evaluated using S-attributed SDTs that have their
semantic actions written after the production
(right hand side).
S-ATTRIBUTED SDT
As depicted above, attributes in S-attributed
SDTs are evaluated in bottom-up parsing, as
the values of the parent nodes depend upon the
values of the child nodes.
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
L-ATTRIBUTED SDT
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.
L-ATTRIBUTED SDT
We may conclude that if a definition is S-attributed,
then it is also L-attributed as L-attributed definition
encloses S-attributed definitions.
Aur Kuch...???

More Related Content

PPTX
Semantics analysis
PDF
Lexical analysis - Compiler Design
PDF
Parse Tree
PDF
08 subprograms
PPTX
Compiler design syntax analysis
PDF
Syntax Directed Definition and its applications
PPT
Chapter 5 Syntax Directed Translation
PPTX
Structure of the compiler
Semantics analysis
Lexical analysis - Compiler Design
Parse Tree
08 subprograms
Compiler design syntax analysis
Syntax Directed Definition and its applications
Chapter 5 Syntax Directed Translation
Structure of the compiler

What's hot (20)

PPTX
Recognition-of-tokens
PPTX
Peephole Optimization
PPTX
Peephole optimization techniques in compiler design
DOCX
Unit v
PPTX
Underlying principles of parallel and distributed computing
PPTX
Performance analysis(Time & Space Complexity)
PDF
Code optimization in compiler design
PPTX
Problem reduction AND OR GRAPH & AO* algorithm.ppt
PPTX
Three Address code
PPTX
Structure of agents
PPTX
Code generation
PPTX
Syntax-Directed Translation into Three Address Code
PPTX
Relational algebra ppt
PPTX
Truth management system
PDF
Syntax directed translation
PPTX
Ooad unit – 1 introduction
PPTX
Register allocation and assignment
PPTX
Inductive analytical approaches to learning
PPTX
Three address code In Compiler Design
PPTX
Code Optimization
Recognition-of-tokens
Peephole Optimization
Peephole optimization techniques in compiler design
Unit v
Underlying principles of parallel and distributed computing
Performance analysis(Time & Space Complexity)
Code optimization in compiler design
Problem reduction AND OR GRAPH & AO* algorithm.ppt
Three Address code
Structure of agents
Code generation
Syntax-Directed Translation into Three Address Code
Relational algebra ppt
Truth management system
Syntax directed translation
Ooad unit – 1 introduction
Register allocation and assignment
Inductive analytical approaches to learning
Three address code In Compiler Design
Code Optimization
Ad

Similar to Attribute grammer (20)

PPTX
L attribute in compiler design
PPTX
Compiler design selective dissemination of information syntax direct translat...
PDF
L14 Semantic analysis This process is crucial in various applications such a...
PPTX
Syntax Directed Definition and Translation
PDF
Compiler Design UNIT III PPT (SDD, SDT).pdf
PPTX
SyntaxDirectedTranslation in Compiler Design
PPTX
Chapter -4.pptx
PPTX
Lecture 11 semantic analysis 2
DOCX
Unit iv-syntax-directed-translation
PPTX
Compiler Design_Syntax Directed Translation.pptx
PDF
Syntax Directed Definitions Synthesized Attributes and Inherited Attributes
PDF
Syntax Directed Translation PPTs for Third Year CSE
PPTX
Module 3 - Semantic Analysis(Compiler Design).pptx
PPTX
Semantic Analysis.pptx
PPT
Chapte - Syntax Directed Translation.ppt
PPT
Chapter 5 -Syntax Directed Translation - Copy.ppt
PDF
PDF
Syntaxdirected (1)
PDF
L attribute in compiler design
Compiler design selective dissemination of information syntax direct translat...
L14 Semantic analysis This process is crucial in various applications such a...
Syntax Directed Definition and Translation
Compiler Design UNIT III PPT (SDD, SDT).pdf
SyntaxDirectedTranslation in Compiler Design
Chapter -4.pptx
Lecture 11 semantic analysis 2
Unit iv-syntax-directed-translation
Compiler Design_Syntax Directed Translation.pptx
Syntax Directed Definitions Synthesized Attributes and Inherited Attributes
Syntax Directed Translation PPTs for Third Year CSE
Module 3 - Semantic Analysis(Compiler Design).pptx
Semantic Analysis.pptx
Chapte - Syntax Directed Translation.ppt
Chapter 5 -Syntax Directed Translation - Copy.ppt
Syntaxdirected (1)
Ad

Recently uploaded (20)

PPTX
master seminar digital applications in india
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Introduction-to-Social-Work-by-Leonora-Serafeca-De-Guzman-Group-2.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
PPTX
Pharma ospi slides which help in ospi learning
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Pre independence Education in Inndia.pdf
master seminar digital applications in india
GDM (1) (1).pptx small presentation for students
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
TR - Agricultural Crops Production NC III.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Anesthesia in Laparoscopic Surgery in India
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Introduction-to-Social-Work-by-Leonora-Serafeca-De-Guzman-Group-2.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
O5-L3 Freight Transport Ops (International) V1.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Cardiovascular Pharmacology for pharmacy students.pptx
Open Quiz Monsoon Mind Game Prelims.pptx
Pharma ospi slides which help in ospi learning
2.FourierTransform-ShortQuestionswithAnswers.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Pre independence Education in Inndia.pdf

Attribute grammer

  • 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.
  • 3. ATTRIBUTE GRAMMAR 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.
  • 4. CONCEPTS AND EXAMPLES An attribute grammar may be informally defined as a context-free grammar that has been extended to provide context sensitivity using a set of attributes, assignment of attribute values, evaluation rules, and conditions. A finite, possibly empty set of attributes is associated with each distinct symbol in the grammar. E → E + T { E.value = E.value + T.value }
  • 5. 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.
  • 7. 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.
  • 8. 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.
  • 9. S-ATTRIBUTED SDT If an SDT uses only synthesized attributes, it is called as S-attributed SDT. These attributes are evaluated using S-attributed SDTs that have their semantic actions written after the production (right hand side).
  • 10. S-ATTRIBUTED SDT As depicted above, attributes in S-attributed SDTs are evaluated in bottom-up parsing, as the values of the parent nodes depend upon the values of the child nodes.
  • 11. 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
  • 12. L-ATTRIBUTED SDT 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.
  • 13. L-ATTRIBUTED SDT We may conclude that if a definition is S-attributed, then it is also L-attributed as L-attributed definition encloses S-attributed definitions.