3-Chapter 5 - Syntax Directed Translation
3-Chapter 5 - Syntax Directed Translation
CHAPTER 5
SYNTAX DIRECTED TRANSLATION
Dependency Graph
Dependency Graph depicts the flow of information among the attribute instances in a
particular parse tree.
If an attribute b depends on attribute c, then attribute b has to be evaluated AFTER c
An edge form one attribute instance to another means that the value of the first is needed
to compute the second.
If Dependency Graph has cycles, there is no way to evaluate the SDD on the parse tree.
Attribute Dependencies
Given a SDD, we can describe the dependencies between the attributes with a
DEPENDENCY GRAPH.
Order of Evaluation of Attributes
DBD’
D’BD’
D’ε
B0
B1
Semantic Rules with Controlled Side
Effects
Translations involve side effects:
A desk calculator may print result.
Code Generator might enter the type of an identifier into symbol table.
Attribute Grammar: Grammar with no side effects and allow any
evaluation order.
Can Control side effects in SDD’s in the following ways
Permit incidental side effects that do not constrain attribute evaluation.
Constrain the allowable evaluation orders.
SDD for Basic Type Declarations
addType()
is just a
Production Semantic Rules procedure
DT L L.inh=T.type that sets
Tint T.type=int the type
field in the
Tfloat T.type=float symbol
LL1, id L1.inh=L.inh table.
addType(id.entry, L.inh)
Lid addType(id.entry, L.inh)