'Determining language from a grammar

I'm trying to solve an exercise on grammars and languages. Here is the exercise:

Let the grammar G be:

G = {V, T, P, S}, 
V = {S, A, B}, 
T = {a, b, c},

P = {S → ABA; A → a | bb; B → bS | ε}

What language is generated by this grammar?

I've tried to derive every possible words accepted by this grammar, but I just can't seem to find a pattern. Anyone can help me with this problem?



Solution 1:[1]

Here is the original grammar:

S ? ABA
A ? a | bb
B ? bS | ?

We can substitute for A and B so S is all that's left:

S ? (a + bb)(bS + ?)(a + bb)

Distributing and rearranging a bit:

S ? (a + bb)bS(a + bb) + (a + bb)(a + bb)

It can be shown that

X ? rXs + t
iff
X ? (r^n)t(s^n)

In our case:

S ? (ab + bbb)^n (a + bb)^2 (a + bb)^n

I am not sure there is a super satisfying English language description of these strings, but maybe it gives a more inuitive representation than the grammar does? To each his own.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Patrick87