• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
September 09, 2022 |6.0K Views

Syntax Directed Translation (SDT) in Compiler Design

  Share   Like
Description
Discussion

In this video, we will be covering what is SDT in detail.

The full form of SDT is Syntax Directed Translation. Whenever any informal notations (known as semantic rules) are associated with the CFG (Context Free Grammar), they are called STD. 

So it can be said that:
Grammar + Semantic Rules = Syntax Directed Translation

In the SDT, each non-terminal generally get one or more attribute depending on the type of attribute. These attribute values are evaluated by semantic rules corresponding to the rules of production.
In SDT, information can be passed in either a bottom-up or top-down approach to parse tree with respect to the attributes that are attached to nodes. 

SDT rules utilize:
1) Node’s Lexical Values
2) Constants 
3) Attributes with respect to the non-terminals

The regular approach for SDT is constructing a parse tree and computing the attribute’s values at nodes of the parse tree by scanning them in any pre-defined order.

Synthesized attributes: It is an attribute of non-terminal on the LHS of a production. It can take value only from its children. 

Example: If A → BC is a production, A’s attribute is dependent on B’s or C’s attributes.

Inherited attributes: It is an attribute of non-terminal on the RHS of a production. It can take value either from its parent or from its siblings. 

Example: If A → BC is a production, B’s attribute is dependent on A’s or C’s attributes.

S-attributed SDT: It uses only Synthesized Attributes. S-attributed SDTs are evaluated in bottom-up parsing, as the values of the parent node depend upon the values of the child nodes.

Example: S → PQ  { S.val = P.val + Q.val }

L-attributed SDT: It uses both Synthesized and Inherited Attributes, with a restriction that inherited attributes can inherit the values from left siblings only. S-attributed SDTs are evaluated in a top-down and left-to-right manner.

Example: S→ PQ  { S.val = P.val + Q.val } // It is L-attributed
 M → AB  { A.val = B.val} // Not L-attributed

SDT in compiler design: https://www.geeksforgeeks.org/syntax-directed-translation-in-compiler-design/