refers
to a method of compiler implementation where the source language translation is
completely driven by the parser, i.e., based on the syntax of the language The
parsing process and parse trees are used to direct semantic analysis and the
translation of the source program. Almost all modern compilers are
syntax-directed.
SDT
can be a separate phase of a compiler or we can augment our conventional
grammar with information to control the semantic analysis and translation. Such
grammars are called attribute grammars.
We
augment a grammar by associating attributes with
each grammar symbol that describes its properties. With each production in a
grammar, we give semantic rules/ actions,
which describe how to compute the attribute values associated with each grammar
symbol in a production.
The
general approach to Syntax-Directed Translation is to construct a parse tree or
syntax tree and compute the values of attributes at the nodes of the tree by
visiting them in some order. In many cases, translation can be done during
parsing without building an explicit tree.
A
class of syntax-directed translations called "L-attributed
translations" (L for left-toright) includes almost all translations that
can be performed during parsing. Similarly, "S-attributed
translations" (S for synthesized) can be performed easily in connection
with a bottom-up parse. There are two ways to represent the semantic rules
associated with grammar symbols.
Syntax-Directed
Definitions (SDD)
Syntax-Directed Translation Schemes (SDT)
0 comments