# context free – Find an unambiguous grammar of a language provided by a CFG

I am working on the second edition of Hopcroft, Motwani & Ullman's Introduction to Automaton Theory, Language and Computing.

In section 5.4, exercise 5.4.3, I am responsible for finding an unambiguous grammar for the language of this context-free grammar (where epsilon is the empty string):

$$S rightarrow aS | aSbS | epsilon$$

I have difficulty formally describing this grammar, but I realize that the number of a is greater than or equal to the number of b's. And the string will always start with an a (except the empty string).

I've tried to divide the grammar into two parts to remove ambiguity. After a few brute force attempts, I decided to make sure that one variable only generates a and the other variable generates an equal number of a and b.

$$S rightarrow A | B | epsilon$$
$$A rightarrow aA | a$$
$$B rightarrow BB | aBa | ab$$

The key part is when rewriting B into a sense form when A occurs, only more than a can be generated in the string.

My question is this: does the new grammar I created generate the same language as the previous grammar? If not, what would be the good grammar? I realize that determining if two CFGs are equivalent is undecidable; but i have no method to determine if i am right.