How to construct a context free grammar that generate following language. $\{a^nb^nc^k \in \{a,b,c\}^* | n,k >= 0\} $

4.4k Views Asked by At

$$\{a^nb^nc^k \in \{a,b,c\}^* | n,k >= 0\} $$

$E \to aEbS $

$S \to c$

I do not know where to go next, or even if this is right at all?

1

There are 1 best solutions below

3
On

Try this:

$$S \to PQ \\ P \to aPb \mid \epsilon \\ Q \to cQ \mid \epsilon$$

The second rule ensures that the number of a's and b's are equal, whereas the third rule ensures that there can be any number of c's. The fact that they are in the right order should be clear.