Question
Consider the following grammar.
The number of reduction steps taken by a bottom-up parser while accepting the string is _______.
Official answer and solution
- Official answer
- 7
- From
- Official GATE 2020 answer key
Solution
Trace the bottom-up shift-reduce parse steps (reverse rightmost derivation) for the string aaadbbb.
Given grammar:
A bottom-up parser reconstructs the rightmost derivation in reverse:
- (Reduction 1: using )
- (Reduction 2: using )
- (Reduction 3: using )
- (Reduction 4: using )
- (Reduction 5: using )
- (Reduction 6: using )
- (Reduction 7: using )
Counting the reduction steps:
- 1 reduction for
- 3 reductions for
- 3 reductions for
- Total reduction steps = .
Final answer
7
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2020 Computer Science and Information Technology (CS)
- Question
- 34 of 65, printed as CS Q.24
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.