GATE / CS ARCHIVE

GATE CSE 2026 SET 1 / QUESTION 53

Two syntax-directed type declarations

Compiler Design · Semantic Analysis & Type Checking · Full GATE CSE 2026 Set 1 paper

GATE 2026 Set 1, Q53 2 marks · MSQ
Report issue

Semantic Analysis & Type Checking

Question 53, GATE 2026: G1 has D→TV, T→int|float, V→V₁ id|id; G2 has D→D₁ id|T id, T→int|float. In SDD1, T.type is set by its keyword, D.type=T.type, V.type=T.type, V₁.type=V.type, and each id is entered with V.type. In SDD2, D.type comes from D₁.type or T.type and each id is entered with that child’s type. Decide A same language, B SDD2 S-attributed, C SDD1 L-attributed with only inherited attributes, D same symbol-table entries.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: A, B, D

Givens and goal

G1 has D→TV, T→int|float, V→V₁ id|id; G2 has D→D₁ id|T id, T→int|float. In SDD1, T.type is set by its keyword, D.type=T.type, V.type=T.type, V₁.type=V.type, and each id is entered with V.type. In SDD2, D.type comes from D₁.type or T.type and each id is entered with that child’s type. Decide A same language, B SDD2 S-attributed, C SDD1 L-attributed with only inherited attributes, D same symbol-table entries.

Approach

Compare generated token sequences separately from how attribute values flow through each parse tree.

Step-by-step solution

1. Both grammars generate a type keyword, either int or float, followed by one or more identifier tokens. G1 builds an identifier list through V; G2 builds the same sequence by extending D. Therefore their languages are identical, establishing A.
2. In SDD2, T.type comes from a type keyword and D.type comes from a child T or D. Every attribute value flows upward from children to the left-hand-side symbol, or is a constant. All attributes are synthesized, so SDD2 is S-attributed and B is true.
3. SDD1 passes the type inherited by V down through the identifier list. But it also contains synthesized attributes, including T.type and D.type. Its inherited dependencies are L-attributed, yet the stronger wording that it contains only inherited attributes is false. Thus C is false.
4. In either definition, every identifier receives the same type supplied by the leading keyword. Thus the same identifier/type entries are recorded, establishing D. The ways in which the values flow through the parse tree differ; the resulting entries do not.

Common error: L-attributed does not mean exclusively inherited. An L-attributed definition can contain synthesized attributes as well.

Example: for the token sequence int id₁ id₂, SDD1 obtains int from T and passes it down through V to both identifiers. SDD2 first constructs the declaration for int id₁, synthesizes its type upward, and uses that type when extending the declaration with id₂. Both call put with (id₁,int) and (id₂,int). In SDD1, the existence of the inherited V.type does not erase the synthesized T.type and D.type; that is the exact overstatement in C.

Original paper, page 41 · Answer key