So, I have this language L={a^i b^2j+1 / i<>j}
and I have to generate a context free grammar based on it, can you please help me in illustrating the steps in doing that.
So far I have this:
S-->aS/aBbb
B-->bB/b/e(empty)
but I am not sure if it is correct, please help me understand it.
For languages with a "not-equal" restriction, the easiest approach is usually to first find a grammar that corresponds to the language with an "equal" restriction instead, and then change it to require more of one of the things.
In this case we have a number of a
tokens followed by an odd number of b
tokens where the constraint is on the number of each. For the equal case, that becomes just
S → aSbb | b
a single b
with the same number of a
s and pairs of b
s wrapped around it.
To make it not-equal, we need to add either extra a
s or extra pairs of B
s, but not both:
S → AS' | S'B
S' → aS'bb | b
A → Aa | a
B → Bbb | bb