StreakPeaked· Practice

ExamsGATETechnical

Consider the following grammar and the semantic actions to support the inherited type declaration attributes. Let X1, X2, X3, X4, X5, and X6 be the placeholders for the non-terminals D, T, L or L1 in the following table: Production rule | Semantic action D → T L | X1.type = X2.type T → int | T.type = int T → float | T.type = float L → L1, id | X3.type = X4.type addType(id.entry, X5.type) L → id | addType(id.entry, X6.type) Which one of the following are the appropriate choices for X1, X2, X3 and X4?

  1. X1 = L, X2 = T, X3 = L1, X4 = L
  2. X1 = T, X2 = L, X3 = L1, X4 = T
  3. X1 = L, X2 = L, X3 = L1, X4 = T
  4. X1 = T, X2 = L, X3 = T, X4 = L1

Correct answer: X1 = L, X2 = T, X3 = L1, X4 = L

Solution

The correct option is right because it accurately reflects the relationships defined in the grammar: the type of the declaration (D) is derived from the type of the type (T) and the list (L), ensuring that the type of the entire declaration matches the type of its components.

Related GATE Technical questions

⚔️ Practice GATE Technical free + battle 1v1 →