CD |Gate-2019| Compiler Design
1. Consider the grammar given below:
S → Aa
A → BD
B → b | ε
D → d | ε
Let a, b, d, and $ be indexed as follows:
a | b | d | $ |
3 | 2 | 1 | 0 |
Compute the FOLLOW set of the non-terminal B and write the index values for the symbols in the FOLLOW set in the descending order. (For example, if the FOLLOW set is {a, b, d, $}, then the answer should be 3210). [GATE – 2019]
a. 30
b. 31
c. 12
d. 33
Answer : b)
CD |Gate-2019|
2. Which one of the following kinds of derivation is used by LR parsers? [GATE – 2019]
a. Leftmost in reverse
b. Leftmost
c. Rightmost in reverse
d. Rightmost
Answer : c)
3. Consider the augmented grammar given below:
S’ → S
S → 〈L〉 | id
L → L,S | S
Let I0 = CLOSURE ({[S’ → ·S]}). The number of items in the set GOTO (I0 , 〈 ) is: _____. [GATE – 2019]
a. 4
b. 5
c. 6
d. 7
Answer: b)
CD |Gate-2019|
4. Consider the following grammar and the semantic actions to support the inheriteatd 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? [GATE – 2019]
a. X1 = L, X2 = L, X3 = L1, X4 = T
b. X1 = L, X2 = T, X3 = L1, X4 = L
c. X1 = T, X2 = L, X3 = L1, X4 = T
d. X1 = T, X2 = L, X3 = T, X4 = L1
Answer : b)