Syntax Direct Translation (SDT) method is used in compiler design, associating the translation rules with grammar production. Syntax Directed Translation can identify informal notations, called semantic rules along with the grammar.
In this article, we will learn more about Syntax Directed Translation (SDT) in compiler design, to help you understand what goes around in the world of Compiler Design.


Syntax Directed Translation in compiler design requires some information to convert the parse tree into a code. This information cannot be represented by the CFG(Context Free Grammar), hence attributes are attached to the variables of CFG.
We can represent it as:
Grammar + semantic rule = SDT
Every non-terminal syntax direct translation can get one or more than one attribute depending on its type. The values of these attributes are set by semantic rules associated with the production rule.
The 'val' attribute in the semantic rules may contain strings, numbers, memory location or a complex record.
The table below shows production and semantic rules.
S.No |
Production |
Semantic Rules |
---|---|---|
1. |
E → E + T |
E.val := E.val + T.val |
2. |
E → T |
E.val := T.val |
3. |
T → T * F |
T.val := T.val * F.val |
4. |
T → F |
T.val := F.val |
5. |
F → (F) |
F.val := F.val |
6. |
F → num |
F.val := num.lexval |
For an easy understanding, we assume the following to be a production rule.

The translation or semantic rule is correspondence to the Production rule and is considered to be an attribute for both the non-terminals E & T

The right side of the translation rule is always in correspondence to the attribute values of the right side of the production rule. From this, we come to the conclusion that SDT in compiler design associates:
- A set of attributes to every node in grammar.
- A set of translation rules to every production rule with the help of attributes.
What is a Parse Tree?
A parse tree in compiler design is a graphical representation of a symbol which can be terminal or non-terminal. Here, the string is taken using the start symbol, and the parse tree's root is that start symbol.
Rules to follow while drawing a Parse Tree:
-
All leaf nodes need to be terminals.
-
All interior nodes need to be non-terminals.
-
In-order traversal gives the original input string.
In A -> xyz, the parse tree will have A as the interior node whose children are x, y and z from left to right.