Professional Documents
Culture Documents
INTRODUCTION
A Syntax Directed Definition (SDD) specifies the values of attributes by associating semantic
rules with the grammar productions.
1. Inherited Attributes
2. Synthesized Attributes
Inherited Attributes:
These are attributes that inherit their values from their parent or sibling nodes.
EXAMPLE :
B can take values from A , C and D . C can take values from A , B and D.
Likewise D can take values from A , B and C
Computation of Inherited Attributes :
The annotated parse tree is generated and attributes values are computed in
top down manner
Consider the following grammar and its corresponding semantic rules:
Synthesized Attributes:
Attributes which get their values from their children nodes i.e. value of synthesized
attribute at node is computed from the values of attributes at children nodes in
parse tree.
EXAMPLE :
If S is taking values from its child node (A, B, C), then it is said to be a synthesized
attribute,as the value of ABC are synthesized to S.
Computation of Synthesized Attributes:
Write the SSD using appropriate semantic rules for each production in given
grammar
The annotated parse tree is generated and attributes values are computed in
bottom up manner.
Dependency Graphs are the most general technique used to evalute syntax.
directed definitions with both synthesized and inherited attributes.
Annoted parse tree shows the values of attributes, dependency graph helps to
determine how those values are computed.
Dependency Graphs:
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.
1. S-attributed SDD
2. L-attributed SDD
S-attributed SDD:
This is the second class of SDD which can contain synthesized as well as inherited
attributes. Also we have to note that, between the attributes associated with a
production body, dependency graph edges can go from left-to-right, but not from
right-to-left (and hence the name “L-attributed”). A L-attributed SDD will be
evaluated from top-to-down and left-to-right.
Syntax Directed Translation (SDT):
It is a CFG with program fragments embedded with the production body. The
program fragments are known as the semantic actions.
THANK YOU