0% found this document useful (0 votes)
18 views27 pages

Unit 3

A Syntax Directed Definition (SDD) combines a Context Free Grammar with Semantic rules, where attributes are associated with grammar symbols and semantic rules with productions. There are two types of attributes: synthesized, which derive values from child nodes, and inherited, which derive values from parent or sibling nodes. SDDs can be classified into S-Attributed SDDs, using only synthesized attributes, and L-Attributed SDDs, using both synthesized and inherited attributes with specific restrictions.

Uploaded by

heyjala777
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views27 pages

Unit 3

A Syntax Directed Definition (SDD) combines a Context Free Grammar with Semantic rules, where attributes are associated with grammar symbols and semantic rules with productions. There are two types of attributes: synthesized, which derive values from child nodes, and inherited, which derive values from parent or sibling nodes. SDDs can be classified into S-Attributed SDDs, using only synthesized attributes, and L-Attributed SDDs, using both synthesized and inherited attributes with specific restrictions.

Uploaded by

heyjala777
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

UNIT-III

Syntax directed definition :


• A SDD is a Context free grammar together with Semantic rules.
• Attributes are Associated with grammar Symbols and Semantic rules are
Associated with productions
• If ‘x’ is a Symbol and ‘a’ is one of its attribute then X.a denotes value at
node ‘X’
• Attributes may be numbers,strings,datatypes etc.
Production Semantic Rules
E -> E + T [Link] = [Link] + [Link]
Types of attributes –
There are two types of attributes:
Synthesized Attributes – These are those attributes which derive 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.
Ex:A->BCD
A be a parent node. B,C,D are children nodes.
A.S=B.S
A.S=C.S
A.S=D.S
Here A is parent node taking values from its children nodes B,C,D
Inherited Attributes – These are the attributes which derive their values from
their parent or sibling nodes i.e. value of inherited attributes are computed by
value of parent or sibling nodes.
Ex:A->BCD
C.i=A.i taking value from parent node
C.i=B.i taking value from Sibling node
C.i=D.i taking value from Sibling node
Types of SDD:

Page 1 of 27
1. S-Attributed SDD (or) S-Attributed Grammar
2. L-Attributed SDD (or) L-Attributed Grammar
S-Attributed SDD:
• A SDD That uses only Synthesized attributes is called as S-Attributed
SDD
Ex:A->BCD
A be a parent node. B,C,D are children nodes.
A.S=B.S
A.S=C.S
A.S=D.S
• Semantic Actions are always placed at right hand end of the [Link]
is also called as Postfix SDD
• Attributes are Evaluated with bottom-up parsing.
L-Attributed SDD:
• A SDD That uses both Synthesized attributes and Inherited attributes is
called as L-Attributed SDD but each inherited attribute is restricted to
inherits from parent or left sibling
Ex:A->XYZ
A be a parent node. B,C,D are children nodes.
Y.S=A.S
Y.S=X.S
• Semantic Actions are always placed anywhere in RHS.
• Attributes are Evaluated with traversing parse tree depth first, left to right
order.
`

Page 2 of 27
Page 3 of 27
Page 4 of 27
Page 5 of 27
Page 6 of 27
Page 7 of 27
Page 8 of 27
Page 9 of 27
Page 10 of 27
Page 11 of 27
Page 12 of 27
Page 13 of 27
Page 14 of 27
Page 15 of 27
Page 16 of 27
Page 17 of 27
Page 18 of 27
Page 19 of 27
Page 20 of 27
Page 21 of 27
Page 22 of 27
Page 23 of 27
Page 24 of 27
Page 25 of 27
Page 26 of 27
Page 27 of 27

You might also like