Parsing · Compiler Design
58 questions · asked in 25 of 27 years (2000–2026)
MCQ 46 · MSQ 5 · NAT 71-mark 39 · 2-mark 19
2000Questions per year2026
Questions 11–15 of 58
Consider the following statements.
S1: Every SLR(1) grammar is unambiguous but there are certain unambiguous grammars that are not SLR(1).
S2: For any context-free grammar, there is a parser that takes at most time to parse a string of length n.
Which one of the following options is correct?
S1: Every SLR(1) grammar is unambiguous but there are certain unambiguous grammars that are not SLR(1).
S2: For any context-free grammar, there is a parser that takes at most time to parse a string of length n.
Which one of the following options is correct?
Answer: (C)
Let us check each statement.
- S1: An SLR(1) parsing table has no conflicts, so every SLR(1) grammar is unambiguous. Some unambiguous grammars are not SLR(1) (for example, many LALR/LR(1) grammars) TRUE.
- S2: The CYK algorithm can parse any CFG (written in CNF) in time TRUE.
Answer: S1 is true and S2 is true
- S1: An SLR(1) parsing table has no conflicts, so every SLR(1) grammar is unambiguous. Some unambiguous grammars are not SLR(1) (for example, many LALR/LR(1) grammars) TRUE.
- S2: The CYK algorithm can parse any CFG (written in CNF) in time TRUE.
Answer: S1 is true and S2 is true
Consider the following augmented grammar with as the set of terminals.
Let . The number of items in the set is ___________
Let . The number of items in the set is ___________
Answer: 8
In , the item moves over and becomes . Its closure then brings in all 7 S-items with the dot at the start. So we get 1 + 7 = 8 items.
Now take GOTO on once more, using the item in that set. This gives the same set again, so it has 8 items.
Answer: 8
Now take GOTO on once more, using the item in that set. This gives the same set again, so it has 8 items.
Answer: 8
Consider the following grammar.
The number of reduction steps taken by a bottom-up parser while accepting the string is___________.
The number of reduction steps taken by a bottom-up parser while accepting the string is___________.
Answer: 7
Bottom-up parsing of aaadbbb takes these reduction steps:
Step 1: reduce d S
Step 2: reduce b B. Step 3: reduce aSB S
Step 4: reduce b B. Step 5: reduce aSB S
Step 6: reduce b B. Step 7: reduce aSB S
Answer: 7
Step 1: reduce d S
Step 2: reduce b B. Step 3: reduce aSB S
Step 4: reduce b B. Step 5: reduce aSB S
Step 6: reduce b B. Step 7: reduce aSB S
Answer: 7
Which one of the following kinds of derivation is used by LR parsers?
Answer: (D)
An LR parser is a bottom-up parser. It keeps reducing handles again and again. The order of these reductions is a rightmost derivation followed backwards.
Answer: Rightmost in reverse
Answer: Rightmost in reverse
Consider the following given grammar:
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).
Answer:_____
S -> Aa
A -> BD
B -> b| ε
D -> d| ε Let a, b, d and $ be indexed as follows: 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).
Answer:_____
Answer: 31
We have A BD, so D comes right after B. This means FOLLOW(B) gets FIRST(D) {} = {d}.
D can also become , so FOLLOW(B) gets FOLLOW(A) = {a} as well (from S Aa).
FOLLOW(B) = {a, d}. The indices are a = 3 and d = 1 written in descending order, this gives 31.
Answer: 31
D can also become , so FOLLOW(B) gets FOLLOW(A) = {a} as well (from S Aa).
FOLLOW(B) = {a, d}. The indices are a = 3 and d = 1 written in descending order, this gives 31.
Answer: 31
Keep practising