SYNTAX Directed
Translation
Compiler Construction
National College of Business
Administration & Economics
Group Members
Wamiq Ali
Programmer
Sarmad Shuja
Programmer
Zain Abid
Programmer
Background
Parser uses a CFG(Context-free-Grammar) to validate the input
string and produce output for next phase of the compiler.
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.
Terminology
A common method of syntax-directed translation is translating a string in
to a sequence of actions by attaching one such action to each rule of a
grammar.
Formula
Grammar + semantic rule = SDT (syntax directed translation)
Syntax Directed Translation Scheme
1 The Syntax directed translation scheme is a context -free grammar.
2 The syntax directed translation scheme is used to evaluate the
order of semantic rules.
3 In translation scheme, the semantic rules are embedded within the
right side of the productions.
4
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.
Top Down
Bottom Up
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.
Thank You

SYNTAX Directed Translation PPT || Compiler Construction

  • 1.
  • 3.
    National College ofBusiness Administration & Economics
  • 4.
    Group Members Wamiq Ali Programmer SarmadShuja Programmer Zain Abid Programmer
  • 5.
    Background Parser uses aCFG(Context-free-Grammar) to validate the input string and produce output for next phase of the compiler.
  • 6.
    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.
  • 7.
    Terminology A common methodof syntax-directed translation is translating a string in to a sequence of actions by attaching one such action to each rule of a grammar. Formula Grammar + semantic rule = SDT (syntax directed translation)
  • 8.
    Syntax Directed TranslationScheme 1 The Syntax directed translation scheme is a context -free grammar. 2 The syntax directed translation scheme is used to evaluate the order of semantic rules. 3 In translation scheme, the semantic rules are embedded within the right side of the productions. 4 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.
  • 9.
    Implementation of Syntaxdirected 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.
  • 10.
  • 11.
  • 12.
    Limitation Without using globaldata 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.
  • 13.
    Common Approach A programwith too many global variables is difficult to understand and maintain. Restrict the usage of global variables to essential items and use them as objects.
  • 14.