Evaluation Orders for SDD’s Dependency graphs

GunjalSanjay 100 views 17 slides Mar 06, 2025
Slide 1
Slide 1 of 17
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17

About This Presentation

Evaluation Orders for SDD’s


Slide Content

Sanjivani Rural Education Society’s
Sanjivani College of Engineering, Kopargaon-423 603
(An Autonomous Institute, Affiliated to Savitribai Phule Pune University, Pune)
NACC ‘A’ Grade Accredited, ISO 9001:2015 Certified
Department of Computer Engineering
(NBA Accredited)
Dr. S. N. Gunjal
Assistant Professor
E-mail : [email protected]
Contact No: 91301 91301 Ext :145, 9503916876
Course-System Software
(CO312)
Unit-III Syntax Directed Definitions
Dr. S.N Gunjal

“Dependency graphs” are a useful tool for determining an evaluation order for the attribute
instances in a given parse tree.
While an annotated parse tree shows the values of attributes, a dependency graph helps us
determine how those values can be computed.
We define two important classes of SDD’s: the “S-attributed” and the more general “L-attributed”
SDDs

Evaluation Orders for SDD’s

A dependency graph indicate the flow of information among the instances of attributes in a
given parse tree.
An edge from one attribute instance to another means that the value of the first is needed to
compute the second.
Edges express constraints implied by the semantic rules.
Dependency Graphs

For each parse-tree node, say a node labeled by grammar symbol X, the dependency graph has a
node for each attribute associated with X.
Evaluation Orders for SDD’s

Supposethatasemanticruleassociatedwithaproductionpdefinesthevalueofsynthesized
attributeA.bintermsofthevalueofX.c(therulemaydefineA.bintermsofotherattributesin
additiontoX.c).Then,thedependencygraphhasanedgefromX.ctoA.b.
Supposethatasemanticruleassociatedwithaproductionpdefinesthevalueofinherited
attributeB.iintermsofthevalueofX.a.Then,thedependencygraphhasanedgefromX.ato
B.i.

Example5.1SynthesizeE.valfromE1.valandE2.val.
Solution.Considerthefollowingproductionandrule:
ProductionRule:
E→E1+T
SemanticRule:
E.val=E1.val+T.val
Asaconvention,weshallshowtheparsetreeedgesasdottedlines,whiletheedgesofthe
dependencygrapharesolid.

Example5.2ConstructaDependencygraphfortheannotatedparsetreeofFig.5.3,whose
SDDisgiveninTable5.1.

15/06/20 DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
•The dependency graph characterizes the possible orders in which we can evaluate the attributes at the
various nodes of a parse tree.
•If the dependency graph has an edge from node M to node N, then the attribute corresponding to M must
be evaluated before the attribute of N.
•Thus, the only allowable orders of evaluation are those sequences of nodes N
1, N2,. . . , Nksuch that if
there is an edge of the dependency graph from Ni to Nj; then i< j. Such an ordering embeds a directed
graph into a linear order, and is called a topological sort of the graph.
Ordering the Evaluation of Attributes
Ordering the Evaluation of Attributes

15/06/20 DEPARTMENT OF COMPUTER ENGINEERING, Sanjivani COE, Kopargaon
•If there is any cycle in the graph, then there are no topological sorts; that is there is no way to evaluate
the SDD on this parse tree.
•If there are no cycles, however, then there is always at least one topological sort. To see why, since there
are no cycles, we can surely find a node with no edge entering.
•For if there were no such node, we could proceed from predecessor to predecessor until we came back to
some node we had already seen, yielding a cycle. Make this node the first in the topological order,
remove it from the dependency graph, and repeat the process on the remaining nodes.

An SDD is S-attributed if every attribute is synthesized.
Example 5.5: The SDD of Table. 5.2 is an example of an S-attributed definition. Each
attribute, L.val, E.va1, T.val, and F.val is synthesized.
S-Attributed Definitions

The second class of SDD’s is called L-attributed definitions.
For these definitions, edges of dependency graph, corresponding to the attributes associated with
production body, can go from left to right but not from right to left in production symbols. More
precisely, each attribute must be either
1. Synthesized, or
2. Inherited, but with the rules limited as follows. Suppose that there is a production
A → X
1,X
2...X
n, and that there is an inherited attribute X
i.acomputed by a rule
associated with this production. Then the rule may use only:
L-Attributed Definitions

(a) Inherited attributes associated with the head A.
(b) Either inherited or synthesized attributes associated with the occurrences of symbols X
1, X
2, ... ,
X
i−1 occurring to the left of X
i.
(c) Inherited or synthesized attributes associated with this occurrence of X
iitself, but only in such a
way that there are no cycles in a dependency graph formed by the attributes of this X
i.
L-Attributed Definitions

L-Attributed Definitions

References
1. Compilers : Principles, Techniques, & Tools 2nd Edition" by Alfred V Aho and
Ravi Sethi