Skip to content
GATEiit

GATE CSE 2025 Session 2 Q22: Classify three SDT rules as S-attributed or L-attributed

Question

Given the following syntax directed translation rules:

Rule 1: R→AB {B.i=R.i−1; A.i=B.i; R.i=A.i+1;}R \to AB\ \{B.i = R.i - 1;\ A.i = B.i;\ R.i = A.i + 1;\}

Rule 2: P→CD {P.i=C.i+D.i; D.i=C.i+2;}P \to CD\ \{P.i = C.i + D.i;\ D.i = C.i + 2;\}

Rule 3: Q→EF {Q.i=E.i+F.i;}Q \to EF\ \{Q.i = E.i + F.i;\}

Which ONE is the CORRECT option among the following?

Try it: multiple choice: exactly one correct option

Select one option
Wrong answer costs 1/3 mark in GATE.
Show answer and explanation

Answer: C (official GATE 2025 final answer key)

Concept used: S-attributed: only synthesized attributes. L-attributed: inherited attributes may depend only on the parent and siblings to the left.

First step: In Rule 1, A.i=B.iA.i = B.i makes AA depend on its right sibling; in Rule 2, D.iD.i is inherited from the left sibling CC.

Full step-by-step solution

Detailed working, common mistakes and linked mock tests will be available with a free GATEiit account. Log-in is coming soon.

Share this question

WhatsAppDownload image

Source: official GATE 2025 Session 2 CS question paper and final answer key, organised by IIT Roorkee. Question paper · Answer key