CD-Ch04 SDT
CD-Ch04 SDT
Chapter Four
Syntax Directed Translation
Outline
4.1. Syntax directed definitions
4.2. Types of Attributes
4.3. Dependency graph and evaluation order
4.4. S-attributed definitions
4.5. L-attributed definitions
1
10/31/202 WCU-CS Compiled by TM.
Syntax Directed Translations
In syntax analysis phase, we have learnt how a parser constructs parse trees.
But the plain parse-tree constructed in that phase is generally not used for a
compiler as it is,
Because, it does not carry any information about of how to evaluate the tree.
Means that, the productions of CFG makes the rules of the language, but do
not accommodate how to interpret them.
For example: E → E + T
This CFG production has no any semantic rule associated with it, and it
cannot help in making any sense of the production.
Semantic information can be represented by associating CFG used in SA
with semantic rules
Then the result is a syntax-directed translation,
Example: S → ABC
synthesized to S.
ii. inherited, meaning that its value is obtained
from the parent node in the parse tree,
A can get values from S, B and C. B can take values from S, A, and C.
10/31/202 8
Types of Attribute cont’d
Expansion: When a non-terminal is expanded to terminals as per a
grammatical rule
T.val=3 * F.val=5
T.val=9
10/31/202 12
4.4. S-attributed definitions
S-attributed SDD
If an SDT uses only synthesized attributes, it is called as S-attributed
SDT.
These attributes are evaluated using S-attributed SDTs that have their
semantic actions written after the production (right hand side).
10/31/202 14
Next
Chapter Five
Type Checking
Outline
5.1. Type systems
5.2. Specifications of a type checker
5.3. Equivalence of types
5.4. Type conversion
15
10/31/202 WCU-CS Compiled by TM.