Finding Context free grammar from a language

71 Views Asked by At

I am trying to construct context-free grammar from the following language accepted by this PDA

$L(A)=\{a^n c^m b^{2n} \mid n, m \in {\Bbb N}, m \geqslant 2 \}$

I am particularly stuck on how to construct the grammar showing "c" with non-terminal cnsidering to be equal or greater than two

My attempt so far

$S \to e \mid aSbb \mid A$

$A \to ccA$

It is one of the concept I struggle the most now and any help is very appreciate. Thank you

1

There are 1 best solutions below

4
On

What you have is quite close to what you need, but it has two shortcomings: there is no terminal derivation from $A$, so the only terminal derivation is the one that gives you the empty word, and $A$ can only generate even numbers of $c$s. Make this small change:

$$\begin{align*} &S\to aSbb\mid cA\\ &A\to cA\mid c \end{align*}$$

Now every derivation that does not produce the empty word looks like this:

$$S\Rightarrow^n a^nSb^{2n}\Rightarrow a^ncAb^{2n}\Rightarrow^ka^nc^{k+1}Ab^{2n}\Rightarrow a^nc^{k+2}b^{2n}\;,$$

where $n,k\ge 0$.