Question Details

Given the following syntax directed translation rules:


Rule 1: R→ABR→AB [B.i=R.i−1;A.i=B.iR.i=A.i+1;B.i=R.i−1;A.i=B.iR.i=A.i+1;]
Rule 2: P→CDP→CD [P.i=C.i+D.i;D.i=C.i+2P.i=C.i+D.i;D.i=C.i+2]
Rule 3: Q→EFQ→EF [Q.i=E.i+F.i;Q.i=E.i+F.i;]


Which ONE is the CORRECT option among the following?

Options

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 L-attributed; 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

Show Answer

Correct Answer :

Option 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

Solution :

The correct option is: 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.

To determine the correct classification of each Syntax-Directed Translation (SDT) rule, let us first review the definitions of S-attributed and L-attributed definitions:

1. S-attributed definition:
An SDD is S-attributed if it uses only synthesized attributes. In a syntax-directed definition, a synthesized attribute at a node is computed from the attributes of its children. In grammar terms, for a production XY1Y2...Yn, only the attribute of the left-hand side symbol X is computed, and it depends solely on the attributes of the right-hand side symbols Y1,Y2...Yn.

2. L-attributed definition:
An SDD is L-attributed if every attribute is either synthesized, or inherited with the restriction that the inherited attributes of a sibling symbol Yj on the right-hand side of a production XY1Y2...Yn can depend only on:
- The inherited attributes of the left-hand side parent head X.
- The attributes (either synthesized or inherited) of sibling symbols Y1,Y2...Yj-1 that lie to the left of Yj.
Note that every S-attributed definition is also an L-attributed definition, because S-attributed definitions do not have any inherited attributes and thus trivially satisfy the constraints of L-attributed definitions.

Let us analyze each rule step-by-step:

Analysis of Rule 1:
Production: RAB
Semantic Rules:
B.i=R.i-1
A.i=B.i
R.i=A.i+1

Looking at the action A.i=B.i, the attribute of the symbol A (which is to the left of B) depends on the attribute of the symbol B (which is to the right of A). This right-to-left dependency violates the constraint of L-attributed definitions. Furthermore, since it contains inherited attributes (such as B.i and A.i), it is not S-attributed. Thus, Rule 1 is neither S-attributed nor L-attributed.

Analysis of Rule 2:
Production: PCD
Semantic Rules:
P.i=C.i+D.i
D.i=C.i+2

Here, the inherited attribute of D (which is D.i) depends on C.i (an attribute of its left sibling symbol C). This is a valid dependency for an L-attributed definition. The attribute P.i of the head is synthesized from the right-hand side attributes. Because it contains the inherited attribute D.i on the right-hand side, it is not S-attributed. Therefore, Rule 2 is not S-attributed but is L-attributed.

Analysis of Rule 3:
Production: QEF
Semantic Rules:
Q.i=E.i+F.i

In this rule, the attribute of the left-hand side head Q is computed using only the attributes of the right-hand side symbols E and F. There are no inherited attributes computed for any of the right-hand side symbols. This makes the rule S-attributed. Since all S-attributed definitions are a subset of L-attributed definitions, Rule 3 is both S-attributed and L-attributed.

Unlock Our Free Library

Access expert-curated educational resources and study materials—completely free.

Ask AI Tutor
5 left
Q1 View Question & Options
AI Tutor is solving this question...
Reading question context & options...