Compiler Design
Lecture-1
Unit-III:Â Syntax directed definition
Â
By
Dr.G.Janardhan
Associate Professor
CSE
Syntax directed definition
Syntax directed definition :
E -> E + T E.val = E.val + T.val
Â
Â
Syntax directed definition
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
Â
Â
Syntax directed definition
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
Â
Syntax directed definition
Types of SDD:
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
Syntax directed definition
L-Attributed SDD:
 Ex:A->XYZ
A be a parent node. B,C,D are children nodes.
Y.S=A.S
Y.S=X.S