# What is the grammar for language $L=\{a^nb^m : n \neq m-1\}$?

What is the grammar for language $$L = \{ a^nb^m : n\neq m-1\}$$?

I only know I have to write grammar for both $$n and $$n>m-1$$, so this is what I wrote:

• For $$n: \begin{align} &S\to Abb \\ &A\to aAb \mid \lambda \end{align}

• For $$n>m-1$$: \begin{align} &S\to aaA \\ &A\to aAb \mid \lambda \end{align}

Yet I can not mix them and get a correct grammar for $$L$$.

• What makes you think that there's a context-free grammar for it?
– Raphael
Jan 19, 2018 at 13:43
• @Raphael As the question seems to distinguish $<$ and $>$ it seems we have to read $!$ as negation, rather than as factorial. Jan 19, 2018 at 14:18
• PS. I took the liberty of editing both $!=$ and landa. Jan 19, 2018 at 14:21
• @HendrikJan Ahhh, good point. Thanks!
– Raphael
Jan 20, 2018 at 0:38