- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is Types of Syntax Directed Translation Schemes?
There are two types of Syntax directed translation schemes which are as follows −
Synthesized Translation
In this translation, values of variables on L.H.S of a production rule depend on the value of the variable on R.H.S of production rule.
For Example,
E → E(1) + E(2) {E. VAL = E(1). VAL + E(2). VAL}
Here, E on L.H.S of production rule can be computed by the sum of values of E(1) and E(2) which are on R.H.S of a production rule, i.e., L.H.S variable is dependent on R.H.S variables.
In synthesized translation, the value of the synthesized attribute at the node is evaluated from the values of attributes at the children of that node in the Parse Tree.
For Example, In Productions.
E → E(1) + E(2)
E → digit
where digit = 0 | 1 | 2 |… . . | 9
The Parse Tree for string 2 + 3 will be
The complete parse tree, i.e., Parse Tree with translation will consist of a tree with each node labeled with attribute VAL.
Here, E. VAL represents the value of non-terminal E, computed from the values at the children of that node in Parse Tree.
Inherited Translation
In this translation, the translation of the Non-terminal on the right side of production depends on the translation of the Non-terminal on the left side of production rules.
For example, consider a production with semantic action.
A → BC {B. VAL = 5 ∗ A. VAL}
In this production, it can view the value of B is dependent on the value of A. So, nonterminal translation at R.H.S of production (B.VAL) depends on non-terminal translation (A.VAL) at L.H.S of production.
The value of inherited attributes is evaluated from the value of attributes at sibling and parent of that node.
For example, a complete parse tree will be
A → BC {B. VAL = 5 ∗ A. VAL}
If A.VAL = 2, so, B.VAL = 5 * 2 = 10
So, the value of B is computed from the parent of that node.
Example of Inherited Translation− Consider the production
A → BC {C. VAL = 2 ∗ B. VAL}
Its complete parse tree will be
Here, value at node C on its sibling B. So, in inherited translation, the value of inherited attributes at a node depends upon its parent node or Sibling node.
Translation on Parse Tree
Consider the Grammar
E → E + T
E → T
T → T ∗ F
T → F
F → digit
Following is the syntax-directed definition for the above Grammar.
Production | Semantic Action |
---|---|
E → E + T | E. VAL = E1. VAL + T1. VAL |
E → T | E. VAL = T. VAL |
T → T ∗ F | T. VAL = T. VAL ∗ F. VAL |
T → F | T. VAL = F. VAL |
F → digit | F. VAL = digit |
Following diagram shows for Parse Tree & Complete Parse Tree for string 5 + 6 + 7.
Complete Parse Tree (Annotated Parse Tree) − A Parse Tree displaying the value of attributes at every node.
LEXVAL represents the values of the digits at the leaf node.
- Related Articles
- What is syntax-directed translation schemes in compiler design?
- What is the Syntax Directed Translation?\n
- What is Implementation of Syntax Directed Translators?
- What is translation of control statements in compiler design?
- What is a "translation unit" in C++
- What are Directory Schemes?
- What is Syntax Tree?
- What are the schemes of Branch Detection?
- What are the schemes of Branch prediction?
- What is syntax of tuple declaration in Python?
- What is correct syntax of Python if statement?
- What is basic syntax of Python for Loops?
- What are the functions of network address translation?
- What is basic syntax of Python if...else statement?
- What is python .. ("dot dot") notation syntax?
