Syntax Directed Translation
Syntax Directed Translation
Translation
Part I
Syntax Directed Translation
• Example:
sequence of characters 495
– grammar symbol TOK_INT
– meaning ≡ integer 495
– is an attribute of TOK_INT.
• Syntax-Directed Definitions:
– give high-level specifications for translations
– hide many implementation details such as order of evaluation of
semantic actions.
– We associate a production rule with a set of semantic actions, and
we do not say when they will be evaluated.
– More readable.
• Translation Schemes:
– indicate the order of evaluation of semantic actions associated with
a production rule.
– In other words, translation schemes give a little bit information
about implementation details.
– More efficient.
Syntax-Directed Definitions
start
final
Synthesized Attributes – Grid Positions
instr S
y=1 dy=0
seq
Input: BEGIN N W S S x=0 dx=0
W
y=0 dy=1
seq instr
BEGIN N
Inherited Attributes
List Æ id addtype(id.entry,List.in)
Inherited Attributes – Example
Input: 5+3*4 L
E.val=17 n
E.val=5 + T.val=12
digit.lexval=5 digit.lexval=3
Dependency Graph
Input: 5+3*4 L
E.val=17
E.val=5 T.val=12
digit.lexval=5 digit.lexval=3
Syntax-Directed Definition (SDD)