The GATE Grind

GATE 2013 CS (CS1) – Question 19

Compiler Design · Parsing and Syntax Analysis · 1 mark · Multiple choice

A grammar has no ε-productions or unit productions (the source gives types A→ε and A→a). What is the maximum number of bottom-up reduce moves when parsing n tokens?

  1. n/2
  2. n−1
  3. 2n−1
  4. 2ⁿ

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (B) n−1

Explanation

Under the source’s intended restriction every reduction replaces at least two stack symbols with one, reducing stack length by at least one. Reducing n input symbols to the start symbol therefore needs at most n−1 reductions, achievable with binary productions. Thus B. The printed “unit production” example uses a terminal-looking a; the intended length-one exclusion is what makes this bound hold.

More Parsing and Syntax Analysis questions

All Parsing and Syntax Analysis questions →