Term Paper Group - 7 Bottom Up Evolution of Inherited Attributes

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

BOTTOM-UP EVALUTION OF

INHERITED ATTRIBUTES

Bachelor of Technology
Computer Science and Engineering

Submitted By

SOURAV KR ARYA (13000119117)


RAMAN KUMAR (13000119109)
AINDRILA PATRA (13000120148)
ANKITA SAHA (13000120149)

MONTH 2021

Techno Main Salt Lake


EM-4/1, Sector-V, Salt Lake
Kolkata- 700091
West Bengal
India
TABLE OF CONTENTS

1. Abstract Page_3
2. Introduction Page_3-4
3. Body
I. Kind of Attributes for Non-Terminals Page_4
Ii. Inherited Attributes Page_4
Iii. Bottom-up Evalution of Inherited Attributes Page_4-5
Iv. Inherited Attributes on Parsar Stack Page_5

4. Conclusion Page_6
5. References Page-_6

TISL/CSE/Term-Paper/Semester- 2
1. Abstract

Attribute Grammars were invented by Don Knuth as a way to unify all of the stages of compiling into one. They give a
formal way to pass semantic information (types, values, etc.) around a parse tree.

We now allow any grammar symbol X to have attributes. The attribute a of symbol X is denoted X.a
If there is a grammar rule

P: X0 ::= X1X2 ...Xk

then a semantic rule for P computes the value of some attribute of one of the Xi in terms of other attributes
of symbols in the rule.

If you think of the rule as forming the node of a tree, an attribute of a node gets its value from the attribute
of its parent, siblings and children (but not from its grandparent).

2. Introduction

A syntax - directed definition (SDD) is a context-free grammar together with attributes and
rules Attributes are associated with grammar symbols and rules are associated with
productions. If X is a symbol and a is one of its attributes, then we write to denote the value
of a at a particular parse-tree node labeled X If we implement the nodes of the parse tree
by records or objects, then the attributes of X can be implemented by data fields in the
records that represent the nodes for X. Attributes may be of any kind. Numbers, types,
table references, or strings, for instance. The strings may even be long sequences of code,
say code in the intermediate language used by a compiler.

TISL/CSE/Term-Paper/Semester- 3
3. Body

KIND OF ATTRIBUTES FOR NON-TERMINALS:

We shall deal with two kinds of attributes for non-terminals.



 A Synthesized attribute for a non-terminal A at a parse-tree under N is defined by a semantic
rule associated with the production at N. Note that the production must have A as
its head. A synthesized attribute at node N is defined only in terms of attribute
values at the children of N and at N itself.
 An Inherited attribute for a non-terminal B at a parse tree node N is defined by a semantic
rule associated with the production at the parent of N. Note that the production
must have B as a symbol in its body. An inherited attribute at node N is defined only
in terms of attribute values at N's parent, N itself, and N's siblings.

INHERITED ATTRIBUTES

 1. 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 a symbol in its body.

 3.It can be evaluated during a single top-down and sideways traversal of parse tree.

 4. Inherited attributes can’t be contained by both, It is only contained by non-
terminals.

 5.Inherited attribute is used by only L-attributed SDT (Syntax-directed


translation).

TISL/CSE/Term-Paper/Semester- 4
BOTTOM-UP EVALUTION OF INHERITED ATTRIBUTED
 Removing Embedding Semantic Actions, in bottom-up evaluation scheme, the
semantic actions are evaluated during reductions.
 During the bottom-up evaluation of S-attributed definitions, we have a parallel
stack to hold synthesized attributes.
 Problem: where are we going to hold inherited attributes?
A Solution: We will convert our grammar to an equivalent grammar to guarantee to the
followings -
6. All embedding semantic actions in our translation scheme will be moved into the
end of the production rules.
7. All inherited attributes will be copied into the synthesized attributes (most of the
time synthesized attributes of new non-terminals).
8. Thus, we will be evaluating all semantic actions during reductions, and we find a
place to store an inherited attribute.

INHERITED ATTRIBUTES ON PARSAR STACK


 A bottom up parser reduces the RHS of a production A→XY by removing X and Y
from the top of the stack and replacing them by A.
 Suppose X has a synthesized attribute X.s which is already in the stack.
 If the inherited attrtibute Y. i is defined by the copy rule X. s=Y. i, then the value of
X. s can where Y. i is called for.
 Copy rule plays an important role in the evaluation of inherited attributes during
bottom up parsing.

TISL/CSE/Term-Paper/Semester- 5
4. Conclusion

In this PPT we have learnt about attributes grammar which was invented by Don Knuth
then we knew about Syntax directed definition and types of attributes for non-terminal
which is synthesized attribute and inherited attributes and then we learnt about bottom-up
evaluation of inherited attributes.

Using a bottom-up translation scheme, we can implement any L-attributed definition based
on LL (1) grammar.

5. References

 https://cs.stackexchange.com/questions/67956/bottom-up-evaluation-of-inherited-
attributes
 https://www.academia.edu/41864140/BOTTOM_UP_EVALUATION_OF_S_ATTRIBU
TED_DEFINITION
 https://www.geeksforgeeks.org/differences-between-synthesized-and-inherited-attributes/

TISL/CSE/Term-Paper/Semester- 6

You might also like