Question:

Given the following syntax directed translation rules: 
Rule 1: \( R \to AB \) { \( B.i = R.i - 1 \); \( A.i = B.i \); \( R.i = A.i + 1 \); } 
Rule 2: \( P \to CD \) { \( P.i = C.i + D.i \); \( D.i = C.i + 2 \); } 
Rule 3: \( Q \to EF \) { \( Q.i = E.i + F.i \); } 
Which ONE is the CORRECT option among the following?

Show Hint

S-attributed grammars use only synthesized attributes, while L-attributed grammars allow inherited attributes but must be evaluated in a single left-to-right parse.
Updated On: Apr 7, 2025
  • Rule 1 is S-attributed and L-attributed; Rule 2 is S-attributed and not L-attributed; Rule 3 is neither S-attributed nor L-attributed
  • Rule 1 is neither S-attributed nor L-attributed; Rule 2 is S-attributed and L-attributed; Rule 3 is S-attributed and L-attributed
  • Rule 1 is neither S-attributed nor L-attributed; Rule 2 is not S-attributed and is L-attributed; Rule 3 is S-attributed and L-attributed
  • Rule 1 is S-attributed and not L-attributed; Rule 2 is not S-attributed and is L-attributed; Rule 3 is S-attributed and L-attributed
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

In syntax-directed translation, attributes are classified as:
  • S-attributed: If all attributes are synthesized. This means that the attribute values are computed from the children in the parse tree, not from their parents.
  • L-attributed: If attributes can be inherited, but the dependency follows a left-to-right order in the parse tree. This means the inherited attributes depend on the current node and its left siblings.
Now analyzing the rules:
  • Rule 1: \( B.i = R.i - 1 \) and \( A.i = B.i \) introduce dependencies on parent and sibling attributes in a way that prevents it from being L-attributed. Since there are inherited attributes, it is not purely synthesized, so it is neither S-attributed nor L-attributed.
  • Rule 2: Since \( D.i = C.i + 2 \), it uses an inherited attribute but still follows an L-attributed dependency structure. However, due to inherited attributes, it is not S-attributed.
  • Rule 3: Uses only synthesized attributes, making it both S-attributed and L-attributed. This means the attributes can be computed in a left-to-right order and are entirely synthesized.

Thus, the correct answer is (C).

Was this answer helpful?
0
0

Top Questions on Syntax Directed Translation

View More Questions

Questions Asked in GATE CS exam

View More Questions