Question
What is the maximum number of reduce moves that can be taken by a bottom-up parser for a grammar with no epsilon- and unit-production (i.e., of type and ) to parse a string with tokens?
Official answer and solution
- Official answer
- B
- From
- Official GATE 2013 answer key
Solution
Analyze how reductions reduce the symbol count on the parser stack when no epsilon or unit productions exist.
In a bottom-up parser:
- The input string consists of tokens.
- In each reduction step, a right-hand side of a production is replaced by its left-hand side non-terminal.
- Since the grammar has no -productions () and no unit productions ( or single symbol reductions where length does not decrease), every reduction rule must have .
- Each reduction replaces at least 2 symbols with 1 non-terminal, thereby reducing the net number of symbols on the stack by at least .
- The parse begins with tokens and finishes with 1 start symbol.
- To reduce the total number of symbols from to , the parser can perform at most:
Thus, the maximum number of reduce moves is .
Option (B)
Thinking that moves are possible, which is the total number of steps (shifts + reduces) rather than reduce moves alone.
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2013 Computer Science and Information Technology (CS)
- Question
- 9 of 65, printed as CS Q.9
- 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.