GATE / CS ARCHIVE

GATE CSE 2025 SET 2 / QUESTION 22

GATE CSE 2025 Set 2 Q22

Compiler Design · Semantic Analysis & Type Checking · Full GATE CSE 2025 Set 2 paper

GATE 2025 Set 2, Q22 1 mark · MCQ
Report issue

Semantic Analysis & Type Checking

Question 22, GATE 2025: Classify these syntax-directed attribute rules:
1. R→AB with B.i=R.i−1, A.i=B.i, R.i=A.i+1.
2. P→CD with P.i=C.i+D.i, D.i=C.i+2.
3. Q→EF with Q.i=E.i+F.i.
Options list the classification of rules 1,2,3 respectively:
A. [S and L], [S not L], [neither].
B. [neither], [S and L], [S and L].
C. [neither], [L not S], [S and L].
D. [S not L], [L not S], [S and L].
Here S means S-attributed and L means L-attributed.
Tap to enlarge
Your answer
Answer & solution

Official answer: C

An S-attributed definition has only synthesized attributes: the parent obtains its values from children. An L-attributed definition additionally permits a child's inherited attributes to depend on the parent's inherited attributes and on attributes of siblings to that child's left, so a left-to-right evaluation is possible.

Rule 1 assigns attributes on both children, so it is not S-attributed. In particular A.i depends on B.i, an attribute of A's right sibling. That violates the L-attributed direction restriction. The listed dependencies also form the cycle R.i→B.i→A.i→R.i; they do not provide a straightforward acyclic evaluation. Thus rule 1 is neither.

In rule 2, P.i is synthesized, but D.i is inherited from its left sibling C. This is permitted in an L-attributed definition and disallowed in an S-attributed one. Rule 3 only synthesizes the parent's Q.i from E.i and F.i, so it is S-attributed, and every S-attributed definition is also L-attributed. The sequence is [neither], [L not S], [S and L], which is C. The letters used to name an attribute, such as i, do not determine its classification; its dependency does.

Original paper, page 19 · Answer key