SDT v1
SDT v1
• Implemented as a
single module.
Syntax-Directed Translation
• Attributes may be
• numbers, types, table references, or strings,
• Strings may even be code in the intermediate language.
Attributes
Synthesized attribute:
• Synthesized attribute for a nonterminal A at a parse-tree node N
is defined by
• Semantic rule associated with the production at N.
• The production must have A as its head.
1 3
6
4
2 5
Evaluation Orders of SDD
• "Dependency graphs" are a useful tool for determining an
evaluation order for the attribute instances in a given parse tree.
• Depicts the flow of information among the attribute
instances in a particular parse tree
• Directed edges
• If there is an edge of the dependency graph from Ni to Nj, such that i < j
• the only allowable orders of evaluation are those sequences of
nodes N1, N2,... ,Nk
• One topological sort is the order in which the nodes have already
been numbered: 1,2,... ,9.
Type Expressions
Type Expressions
• The program fragments are called semantic actions and can appear at any
position within a production body.
Syntax-Directed Translation Schemes
• The simplest SDD implementation occurs when we can parse the grammar
bottom-up and the SDD is S-attributed.
• In that case, we can construct an SDT in which each action is placed at the end
of the production
• Executed along with the reduction of the body to the head of that
production.
• SDT's with all actions at the right ends of the production bodies are called
postfix SDT’s.
Syntax-Directed Translation Schemes
Parser Implementation of Postfix SDT's
• The parser stack contains records with a field for a grammar symbol
(or parser state) and, below it, a field for an attribute
A->X Y Z
• If the attributes are all synthesized, and the actions occur at the ends
of the productions
• then we can compute the attributes for the head when we
reduce the body to the head.
• After the action, A and its attributes are pushed at the top of the stack,
in the position of the record for X
Actions of the desk-
calculator SDT so that
they manipulate the
parser stack explicitly
SDT's With Actions Inside Productions
SDT for infix-to-prefix translation during parsing