Write a CFG for the language $\{0^n 1^a 2^b \mid n = a+b\}$
Unfortunately your grammar generates mixed $1$s and $2$s.
You can try something like this:
$S\rightarrow 0SB | S'$
$S' \rightarrow 0S'A | \varepsilon$
$A\rightarrow 1$
$B\rightarrow 2$
Notice that I don't know if in your problem $n$ can be $0$ or not (and similarly for $a$ and $b$), so maybe you have to fix something.
Anyway, here the idea is starting generating first some $0$s an all the $2$s, and then add the remaining $0$s and the $1$s: it is similar to the &quot;standard&quot; grammar used to generate $0^n 1^n$.