# CFG where u has same number of 1s as v [closed]

$$L=\{uv\in\{0,1,2\}^*\mid u\in\{0,1\}^*,v\in\{1,2\}^*, \text{ and }u\text{ has the same number of 1s as }v\}.$$

Here is my attempt solution, but it is not completely correct, any hint is appreciated (not sure how I can ensure that $u$ and $v$ to have the same number of 1).

\begin{align} S &\rightarrow S_l \mid S \mid S_r\\ S_l &\rightarrow 0S_l \mid 1S_l \mid S_l0 \mid S_l1 \mid \varepsilon \\ S_r &\rightarrow 1S_r \mid 2S_r \mid S_r1 \mid S_r2 \mid \varepsilon \end{align}

• Why do you think your grammar is correct? Have you tried proving it correct or tested by verifying that words up to length, say, 5 are covered correctly? Also, what do you expect here? There is no question. – Raphael Jun 11 '18 at 9:27

where $S_0$ represents $0^*$ and $S_2$ represents $2^*$.
This answer refers to the question as originally stated, in which $L$ is defined as follows: $$L = \{uv \in \{0,1,2\}^* \mid u,v \in \{0,1\}^*, \text{and u has the same number of 1s as v}\}.$$
Your language is regular, since it consists of all words over $\{0,1\}$ with an even number of $1$s.