Nonlinear equations with superposition formulas and the exceptional group G2. I. Complex and real forms of g2 and their maximal subalgebras