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?
View worked solution
Answer: B
To find the maximum number of reduce moves to parse a string of length using a bottom-up parser:
- Without Terminal Reductions: If we assume that terminal-to-nonterminal transitions (like ) are handled during the shift phase (or by the lexical analyzer), the parser starts with non-terminal symbols on the stack.
- Stack Reduction: Since the grammar has no epsilon-productions () and no unit-productions (), every reduction must be of the form where .
- Each such reduction replaces at least symbols with symbol, thereby decreasing the number of symbols on the stack by at least .
- To reduce the stack size from symbols to (the start symbol ), we need at most:
Note: If reductions of the form are counted as separate reduce moves, it would require additional reductions, leading to moves (Option C). Under the assumption of pre-classified tokens, the answer is .
Free practice · Your answers on this page are not saved.
