$G = \{V, T, S, P\}$, $T = \{0, 1, 2\}$, find production rules P to generate $\{0^n 1^n 2^n | n ∈ ℤ, n ≥ 0\}$

32 Views Asked by At

Given $V = \{S, 0, 1, 2,$ any additional nonterminals needed$\}$, $T = \{0, 1, 2\}$, $S$ as the start symbol, list production rules $P$ that can be used to generate strings of the form $\{0^n 1^n 2^n | n \in \mathbb{Z}, n ≥ 0\}$.

At first I thought the answer was something like:

$S \rightarrow 0A1B2C$

$A \rightarrow 0A | \lambda$

$B \rightarrow 1B | \lambda$

$C \rightarrow 2C | \lambda$

But the problem with those rules is that you can "follow" the rules for A, B, and C varying numbers of times, when they should be the same answer. (That would be a solution for $\{0^x 1^y 2^z\}$, but not where all 3 are repeated the same number of times.)

I'm having trouble with ensuring that each step creates an equal number of 0's, 1's, and 2's, and in the correct order. I'm pretty sure this means each "augmentation" of the string will need to take place in 1 step, but I'm having trouble since there are more than 2 terminals.