To generate any other string, it needs to start with the production
S
aSb and then the non-terminal
S in the RHS can be replaced either by
ab (in which we get the string aabb) or the same production S
aSb can be used one or more times. Every time it adds an 'a' to the left and a 'b' to the right of S, thus giving the sentential form
. When the non-terminal is replaced by ab (which is then only possibility for generating a terminal string) we get a terminal string of the form
.
There is no general rule for finding a grammar for a given language. For many languages we can devise grammars and there are many languages for which we cannot find any grammar.