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?
- 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
- 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
- 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
- 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.