Consider a grammar with production rules D→TL (semantic action X1.type=X2.type), T→int (T.type=int), T→float (T.type=float), L→L1,id (semantic action X3.type=X4.type; addType(id.entry, X5.type)), L→id (addType(id.entry, X6.type)) — supporting inherited type-declaration attributes. Let X1,X2,X3,X4,X5,X6 be placeholders for the non-terminals D,T,L, or L1. Which one of the following are the appropriate choices for X1, X2, X3 and X4?
- X1=L, X2=T, X3=L1, X4=L
- BX1=T, X2=L, X3=L1, X4=T
- CX1=L, X2=L, X3=L1, X4=T
- DX1=T, X2=L, X3=T, X4=L1
Explanation
For D→TL, the type must flow FROM T (synthesized, computed directly from the token) INTO L (inherited, so L knows what type to attach to declared identifiers): L.type=T.type, so X1=L, X2=T. For L→L1,id, the inherited type must propagate from L down to L1: L1.type=L.type, so X3=L1, X4=L (matching L's own inherited type, which then gets used via X5=L for addType).
Source: GATE CS 2019 (Set-2) (2019)
This question is part of a 15-day revision cycle — sign in and Project Forge will bring it back the day before you'd forget it.