Context-free grammar for all words not of the form w#w
If a word is not of the form $w\#w$ then one of the following must happen:

It contains no $\#$.
It contains more than one $\#$.
It is of the form $x\#y$, where $x,y \in \{0,1\}^*$ and $x \neq y$, in which case one of the following must happen:

$|x| &gt; |y|$ or $|x| &lt; |y|$.
$x_i = 0$ and $y_i = 1$ for some $i$, or vice versa.



The only case which is non-trivial to handle is the last one, in which case we have a word of the form
$$
x_1 0 x_2 \# y_1 1 y_2,
$$
where $|x_1| = |y_1|$. We can split this into
$$
x_1 \;\; 0x_2\# \;\; y_1 \;\; 1y_2,
$$
where $|x_1| = |y_1|$. This should make it clear how to construct a CFG for such words.

Altogether, we obtain the following grammar:
\begin{align}
&amp;S \to A \mid B \mid C \mid D \mid E \mid F \\
&amp;A \to 0A \mid 1A \mid \epsilon \\
&amp;B \to A\#B \mid A\#A\#A \\
&amp;C \to A0G \mid A1G \\
&amp;D \to G0A \mid G1A \\
&amp;G \to 0G0 \mid 0G1 \mid 1G0 \mid 1G1 \mid \# \\
&amp;E \to E_11A \\
&amp;E_1 \to 0E_10 \mid 0E_11 \mid 1E_10 \mid 1E_11 \mid 0A\# \\
&amp;F \to F_10A \\ 
&amp;F_1 \to 0F_10 \mid 0F_11 \mid 1F_10 \mid 1F_11 \mid 1A\# \\
\end{align}
In this grammar:

$A$ generates words without $\#$
$B$ generates words with more than one $\#$
$C$ generates words of the form $x\#y$ with $|x| &gt; |y|$
$D$ generates words of the form $x\#y$ with $|x| &lt; |y|$
$E$ generates words of the form $x_10x_2\#y_11y_2$ with $|x_1|=|y_1|$
$F$ generates words of the form $x_11x_2\#y_10y_2$ with $|x_1|=|y_1|$
$G$ generates words of the form $x\#y$ with $|x| = |y|$