Similar questions 1 more →
Semantic Analysis & Type Checking

Answer & solution
Official answer: A
1. T reads the type keyword and synthesizes its type value: int for T→int or float for T→float. The identifier list must receive this value from its declaration context.
2. In D→T L, the value flows from sibling T to L. Therefore L.type=T.type, giving X1=L and X2=T. Reversing this assignment would try to obtain the declared type from an untyped identifier list.
3. In L→L1,id, the parent L already has an inherited type. The shorter list L1 must inherit that same type, so L1.type=L.type. Consequently X3=L1 and X4=L.
4. The last identifier also gets L.type through addType; in the base case L→id, the single identifier receives L.type. For example, int a,b passes int from T to the outer list, then to its inner list and to both identifier entries.
5. The requested tuple is (L,T,L1,L), option A. T need not appear directly in recursive list productions: its value has already been propagated into the inherited L attribute.