Let f(n) be the number of ways to generate an. We have,
f(n) = $2*f(n-1)$ <-- due to the rule S -> aS|Sa
+ $\sum_{i=1}^{n-1} f(i)*f(n-i)$ < --- due to the rule S -> SS
So, $f(n) = 2f(n-1)+\sum_{k=1}^{n-1} f(k)*f(n-k)$ with f(1) = 1
$\therefore f(2)=2f(1)+f(1)^2 = 3 \\ f(3) = 2f(2)+f(1)*f(2)+f(2)*f(1) = 12 \\ f(4) = 2f(3)+f(1)*f(3)+f(2)^2+f(3)*f(1) = 57$