GATE CS 2019 · Question 46 · Compiler Design · Multiple choice (MCQ) · 2 marks · −2/3 for a wrong answer

Consider the following grammar and the semantic actions to support the inherited type declaration attributes. Let X₁, X₂, X₃, X₄, X₅, and X₆ be the placeholders for the non-terminals D, T, L or L₁ in the following table:
Which one of the following are the appropriate choices for X₁, X₂, X₃ and X₄?

Production ruleSemantic action
D → T LX₁.type = X₂.type
T → intT.type = int
T → floatT.type = float
L → L₁ , idX₃.type = X₄.type; addType(id.entry, X₅.type)
L → idaddType(id.entry, X₆.type)
  1. (A) X₁ = L, X₂ = T, X₃ = L₁, X₄ = L
  2. (B) X₁ = T, X₂ = L, X₃ = L₁, X₄ = T
  3. (C) X₁ = L, X₂ = L, X₃ = L₁, X₄ = T
  4. (D) X₁ = T, X₂ = L, X₃ = T, X₄ = L₁
Answer

Answer (A)

Answer from the official GATE CS 2019 answer key.

The step-by-step solution, where available, is part of GATE CS Pro. See what Pro includes