Finding a grammar for $L = \{ 0^x1^y0^z1^w | x+w=y+z\}$
Let's write the condition $x+w=y+z$ in a different way: $x-y=z-w$. We consider two cases: $x \geq y$ and $y \geq x$. If $x \geq y$, let $x = y+a$. Then we are interested in words of the form
$$
0^{y+a} 1^y 0^{w+a} 1^w = 0^a 0^y 1^y 0^a 0^w 1^w.
$$
If $y \geq x$, let $y=x+b$. Then we are interested in words of the form
$$
0^x 1^{x+b} 0^z 1^{z+b} = 0^x 1^x 1^b 0^z 1^z 1^b.
$$
We can generate words of the first form using the grammar
\begin{align}
&amp;T_1 \to AW \\
&amp;A \to 0A0 \mid Y \\
&amp;Y \to 0Y1 \mid \epsilon \\
&amp;W \to 0W1 \mid \epsilon
\end{align}
We can generate words of the second form using the grammar
\begin{align}
&amp;T_2 \to XB \\
&amp;X \to 0X1 \mid \epsilon \\
&amp;B \to 1B1 \mid Z \\
&amp;Z \to 0Z1 \mid \epsilon
\end{align}
Taking these two grammars together and adding a new rule $S \to T_1 \mid T_2$, we get a grammar for your language. Note that you can merge $X,Y,Z,W$. The resulting grammar is
\begin{align}
&amp;S \to AX \mid XB \\
&amp;A \to 0A0 \mid X \\
&amp;B \to 1B1 \mid X \\
&amp;X \to 0X1 \mid \epsilon
\end{align}