The GATE Grind

GATE 2020 CS – Question 43

Compiler Design · Syntax-Directed Translation · 2 marks · Multiple choice

Consider the productions A → PQ and A → XY. Each of the five non-terminals A, P, Q, X, and Y has two attributes: $s$ is a synthesized attribute, and $i$ is an inherited attribute. Consider the following rules.

Rule 1: P.i = A.i + 2, Q.i = P.i + A.i, and A.s = P.s + Q.s

Rule 2: X.i = A.i + Y.s and Y.i = X.s + A.i

Which one of the following is TRUE?

  1. Both Rule 1 and Rule 2 are L-attributed.
  2. Only Rule 1 is L-attributed.
  3. Only Rule 2 is L-attributed.
  4. Neither Rule 1 nor Rule 2 is L-attributed.

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (B) Only Rule 1 is L-attributed.

Explanation

In Rule 1 each inherited attribute depends only on the parent's inherited attribute and left siblings, so it is L-attributed. In Rule 2, X.i depends on Y.s, a right sibling's attribute, which violates the L-attributed condition.