Recursion Direction and Parser Stack Space

A configuration tool parses the list alpha, beta, gamma, delta, eta, theta, kappa, omega. Each identifier becomes one id token, and each comma becomes one comma token. Compare two bottom-up parsers that start with empty stacks.


The left-recursive grammar is:


L→L  ,  id∣idL \to L\;,\;\text{id} \mid \text{id}


Its parser replaces id by LL when the entire stack consists of that single token. It replaces the stack suffix L  ,  idL\;,\;\text{id} by LL whenever that suffix is present.


The right-recursive grammar is:


R→id  ,  R∣idR \to \text{id}\;,\;R \mid \text{id}


Its parser replaces a final id by RR only when the next input is the end marker. It replaces the stack suffix id  ,  R\text{id}\;,\;R by RR whenever that suffix is present.


Both parsers apply a permitted reduction before shifting another token. If no reduction is permitted and input remains, they shift one token. The end marker is inspected but never shifted. A reduction replaces its entire suffix in one action.


One symbol slot holds one terminal or nonterminal. Ignore parser states, storage outside the stack, and any bottom marker. Count occupancy immediately after every shift and every reduction.


A parser loop records stack size after each shift or reduction and checks for a permitted reduction before shifting.


Find the maximum occupied symbol slots for the left-recursive parser and for the right-recursive parser. Enter both counts as exact integers.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Parsing Questions: