Counting Ambiguous Groupings

An expression parser uses the ambiguous grammar


E→E+E∣id.E \to E+E \mid \mathrm{id}.


Inputs contain identifiers separated by plus tokens, with no parentheses. Let NnN_n be the number of structurally distinct parse trees for a fixed sequence containing nn identifiers. Do not count different expansion orders for the same tree separately.


Splitting at the root plus gives


Nn=∑i=1n−1NiNn−i,N1=1.N_n = \sum_{i=1}^{n-1} N_iN_{n-i}, \qquad N_1=1.


You may use N2=1N_2=1 and N3=2N_3=2. Find the parse-tree counts for a four-identifier input and a five-identifier input. Enter each as an exact integer number of trees, with zero decimal places.

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: