Provide a grammar for the language: $a^ib^jc^{i+j}:i,j \geq 0$

57 Views Asked by At

I am trying to provide a grammar for the above language, but keep running into the same issue. So far I have this:

$S \rightarrow AB | \epsilon$

$A \rightarrow aAc | \epsilon$

$B \rightarrow bBc | \epsilon$

but these productions produce words like $acbbcc$, when it should be $abbccc$.

I feel as though I am very close but need some advice of how to sort this issue out.

1

There are 1 best solutions below

0
On BEST ANSWER

What about this?

$S\to aSc\mid T$

$T\to bTc\mid\epsilon$

First you create a string of the form $a^nSc^n$, then after substituting $S\to T$, and performing the rule with $T$ a few times you get $a^nb^mTc^{n+m}$. After performing $T\to\epsilon$ you get any string in the wanted language.