CFG Grammar for $L=\left\{ a^ib^jc^k\mid i+k=3j \right\}$

392 Views Asked by At

Write a CFG Grammar for $L=\left\{ a^ib^jc^k\mid i+k=3j \right\}$

I'm having trouble because the j is in the middle so I keep getting c's before b's. I feel I'm missing something simple.

1

There are 1 best solutions below

1
On BEST ANSWER

I think this will do it:

$S \rightarrow \varepsilon |aAbBcc|aaAbBc|aaaAbbBccc$

$A\rightarrow aaaAb|\varepsilon $

$B \rightarrow bBccc | \varepsilon $

The trick for me was having the first rule determine the differenace between $i$ and $k$ and then the other rules just preserve that.