Skip to content
Official PYQ · 2013

GATE CS 2013 Q9 — Parsing (LL, LR)

Explain with AI

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 A→ϵA \rightarrow \epsilon and A→aA \rightarrow a) to parse a string with nn tokens?

Choose one option
View worked solution

Answer: B

To find the maximum number of reduce moves to parse a string of length nn using a bottom-up parser:

  1. Without Terminal Reductions: If we assume that terminal-to-nonterminal transitions (like A→aA \rightarrow a) are handled during the shift phase (or by the lexical analyzer), the parser starts with nn non-terminal symbols on the stack.
  2. Stack Reduction: Since the grammar has no epsilon-productions (A→ϵA \rightarrow \epsilon) and no unit-productions (A→BA \rightarrow B), every reduction must be of the form A→αA \rightarrow \alpha where ∣α∣≥2|\alpha| \ge 2.
  3. Each such reduction replaces at least 22 symbols with 11 symbol, thereby decreasing the number of symbols on the stack by at least 11.
  4. To reduce the stack size from nn symbols to 11 (the start symbol SS), we need at most: n−1 reduce movesn - 1 \text{ reduce moves}

Note: If reductions of the form A→aA \rightarrow a are counted as separate reduce moves, it would require nn additional reductions, leading to 2n−12n - 1 moves (Option C). Under the assumption of pre-classified tokens, the answer is n−1n - 1.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Parsing (LL, LR) questions