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:
Its parser replaces id by LLL when the entire stack consists of that single token. It replaces the stack suffix L , idL\;,\;\text{id}L,id by LLL whenever that suffix is present.
The right-recursive grammar is:
Its parser replaces a final id by RRR only when the next input is the end marker. It replaces the stack suffix id , R\text{id}\;,\;Rid,R by RRR 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.
Find the maximum occupied symbol slots for the left-recursive parser and for the right-recursive parser. Enter both counts as exact integers.
Unlock full course notes by signing up
When an Empty Production Is Legal
A predictive parser uses this grammar, with start symbol SSS and an external end-of-input marker called EOF:
Complete the decision table for a call to RRR. Enter exactly continue for R→+idRR \to +\mathrm{id}RR→+idR, empty for R→εR \to \varepsilonR→ε, or error when neither production is valid for the lookahead token.
Two Structures for One Token Sequence
An expression grammar has start symbol EEE and productions
For the token sequence id(a) + id(b) * id(c), which statements are true? Select every true statement. No precedence or associativity rules supplement the grammar.
Delaying a Predictive Choice
A command parser chooses a production using only the next input token. The token names name and value each denote a single token category. The symbols =, (, and ) are literal tokens.
The original grammar has these labelled productions:
O1: S→name = valueS \to \text{name}\;=\;\text{value}S→name=value
Counting Ambiguous Groupings
An expression parser uses the ambiguous grammar
Inputs contain identifiers separated by plus tokens, with no parentheses. Let NnN_nNn be the number of structurally distinct parse trees for a fixed sequence containing nnn identifiers. Do not count different expansion orders for the same tree separately.