VIP High Class Call Girls Jamshedpur Anushka 8250192130 Independent Escort Se...
SYNTAX Directed Translation Report || Compiler Construction
1. Syntax Directed Translation
Background: -
Parser uses a CFG(Context-free-Grammar) to validate the input string and produce output for next
phase of the compiler. Output could be either a parse tree or abstract syntax tree. Now to interleave
semantic analysis with syntax analysis phase of the compiler, we use Syntax Directed Translation.
Introduction: -
Syntax-directed translation (SDT) refers to a method of compiler implementation where the
source language translation is completely driven by the parser. The parsing process and parse
trees are used to direct semantic analysis and the translation of the source program. We can
augment grammar with information to control the semantic analysis and translation. Such
grammars are called attribute grammars.
Associate attributes with each grammar symbol that describes its properties. An attribute has a
name and an associated value with each production in a grammar, give semantic rules or
actions. 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.
Terminology: -
A common method of syntax-directed translation is translating a string into a sequence of actions
by attaching one such action to each rule of a grammar.
Formula: -
Grammar + semantic rule = SDT (syntax directed translation)
2. Syntax DirectedTranslationScheme
The Syntax directed translation scheme is a context -free grammar.
The syntax directed translation scheme is used to evaluate the order of semantic rules.
In translation scheme, the semantic rules are embedded within the right side of the
productions.
The position at which an action is to be executed is shown by enclosed between braces. It
is written within the right side of the production.
Implementation of Syntax directed translation
Syntax direct translation is implemented by constructing a parse tree and performing the
actions in a left to right depth first order.
SDT is implementing by parse the input and produce a parse tree as a result.
4. Why Syntax directed translation is used?
The syntax directed translation scheme is used to evaluate the order of semantic rules.
In translation scheme, the semantic rules are embedded within the right side of the productions.
The position at which an action is to be executed is shown by enclosed between braces.
Limitation: -
Without using global data to create side effects, some of the semantic actions cannot be
performed.
Example:
Checking whether a variable is defined before its usage.
Checking the type and storage address of a variable.
Checking whether a variable is used or not.
Common Approach:
A program with too many global variables is difficult to understand and maintain.
Restrict the usage of global variables to essential items and use them as objects.
a. Symbol table.
b. Labels for GOTO’s.
c. Forwarded declarations.