Given the grammar $G=(\{S,X,Y\},\{0,1,2\},P,S)$ where $P$ is $$S\to01X\mid0S,\quad X\to2X\mid1Y,\quad Y\to2Y2\mid0$$ find the automata.
The teacher found that the language generated by $G$ i.e. $L(G)$ is $$L(G)=\{w=0^n012^m12^p02^p\mid m,n,p\geq0\},$$ which I agree.
But my problem is to represent (either in a regular expression or in the automaton) the production $Y\to2Y2$.
I found this regular expression: $$0^*012^*1\color{red}{(\text{????})}$$ The part in $\color{red}{\text{red}}$ can't be $2^*02^*$ because the words have to end with $$0,\quad202,\quad22022,\quad2220222,\quad\ldots$$ but with $2^*02^*$ I can generate the words $20,\quad22220,\quad2022$ where they are not in $L(G)$.
How can we represent $Y\to2Y2$?
Your language $L(G)$ is not regular. Indeed, consider the following languages \begin{align} L_1 &= L(G) \cap 011\{0,1,2\}^* = 011\{2^p02^p \mid p \geqslant 0\} \\ L_2 &= (011)^{-1}L_1 = \{2^p02^p \mid p \geqslant 0\} \end{align} Suppose that $L(G)$ is regular. Since regular languages are closed under intersection and under left residual, $L_2$ would also be regular. But it is easy to verify, using the pumping lemma or Nerode's equivalence, that $L_2$ is not regular. Therefore, there are no regular expression to represent $L(G)$ and you need a pushdown automaton to accept this language.