What if a formal grammar cannot be terminated?
When you are given a grammar $G$, then the language it produces, $L(G)$, is all the (finite) words it can generate. All the other "derivations" that don't yield any legal word, can be ignored.

For instance, for the grammar $G_1$:


  S -> SS | Sa | aS


the language that the grammar produces is $L(G_1)=\emptyset$, as no derivation ever terminates.