Context-free grammar for language with unequal numbers of a and b
Here are some hints:


Break the language into two parts: $L_a = \{ w : \#_a(w) &gt; \#_b(w) \}$ and $L_b = \{ w : \#_a(w) &lt; \#_b(w) \}$. Below we concentrate on $L_a$.
Figure out a grammar for the language $L_= = \{ w : \#_a(w) = \#_b(w) \}$. Here the idea is that $L_= = (aL_=b + bL_=a)^*$.
Use the identity $L_a = L_=(aL_=)^+$ to construct a grammar for $L_a$.