Given the following syntax directed translation rules: Rule 1: 𝑅 β†’ 𝐴𝐡 {𝐡.…

2025

Given the following syntax directed translation rules:

Rule 1: 𝑅 β†’ 𝐴𝐡 {𝐡. 𝑖 = 𝑅. 𝑖 βˆ’ 1; 𝐴. 𝑖 = 𝐡. 𝑖; 𝑅. 𝑖 = 𝐴. 𝑖 + 1;}

Rule 2: 𝑃 β†’ 𝐢𝐷 {𝑃. 𝑖 = 𝐢. 𝑖 + 𝐷. 𝑖;𝐷. 𝑖 = 𝐢. 𝑖 + 2;}

Rule 3: 𝑄 β†’ 𝐸𝐹 {𝑄. 𝑖 = 𝐸. 𝑖 + 𝐹. 𝑖;}

Which ONE is the CORRECT option among the following?

  1. A.

    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

  2. B.

    Rule 1 is neither S-attributed nor L-attributed; Rule 2 is S-attributed and Lattributed; Rule 3 is S-attributed and L-attributed

  3. C.

    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

  4. D.

    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

Attempted by 74 students.

Show answer & explanation

Correct answer: C

Final classification (correct answer): 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.

Key reasons:

  • Rule 1: This rule is neither S-attributed nor L-attributed. It is not S-attributed because the semantic action uses R.i to set B.i before R.i itself is computed for the left-hand side, so the production requires an inherited value for R.i (S-attributed grammars allow only synthesized attributes). It is not L-attributed because A.i is assigned from B.i (a right sibling). L-attributed inherited attributes of a symbol may depend only on the parent and on attributes of symbols to its left, so depending on a right sibling violates the L-attributed restriction.

  • Rule 2: This rule is L-attributed but not S-attributed. The attribute D.i for the right child is assigned from C.i (the left sibling), so D.i is an inherited attribute that depends only on a left sibling, which fits the L-attributed form. Because an inherited attribute is present (D.i), the production is not S-attributed (S-attributed grammars permit only synthesized attributes).

  • Rule 3: This rule is S-attributed because the parent attribute Q.i is computed solely from the synthesized attributes E.i and F.i of its children. Since it is S-attributed (only synthesized attributes used), it also satisfies the requirements for being L-attributed.

Therefore, the option that states: "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" is the correct choice.

A video solution is available for this question β€” log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir