0
$\begingroup$

I have generated the CFG of $a^n b^m c^p$ where $m = n+p+2$:

$S \rightarrow ASC \mid \varepsilon$

$A \rightarrow aAb \mid \varepsilon$

$C \rightarrow bCc \mid \varepsilon$

I have been trying $a^n b^m c^p$ where $n=m+p+2$ but cannot figure out how to represent $n=m+p+2$. Any hint would really be appreciated.

$\endgroup$
5
  • 3
    $\begingroup$ Does this answer your question? How to prove that a language is context-free? You should look at examples. $\endgroup$ – Nathaniel May 22 at 23:27
  • $\begingroup$ I tried it myself and this was my solution Is this correct? S->abSA | a , C -> Ac | NULL $\endgroup$ – M. Hasnat Raza May 22 at 23:39
  • $\begingroup$ No, because 1) $A$ is not rewritten 2) it can create $abaA$. $\endgroup$ – Nathaniel May 22 at 23:51
  • $\begingroup$ Thanks a lot. I think I found the answer. Here it is: $S->$C$S | aa , $C->$A$C | NULL , $A->$B$A | a , B->a B b | NULL. Please, do tell me if its correct. Thanks a lot $\endgroup$ – M. Hasnat Raza May 23 at 0:16
  • 3
    $\begingroup$ The grammar in your question recognises $a^nb^mc^p$ where $m = n + p$, not $m = n + p + 2$. Although it's easy to fix. $\endgroup$ – rici May 23 at 4:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.