How do I make a context-free grammar (CFG) for the following language? $$L = \{w \in \{0, 1\}^* : \#_0(w) = 2\#_1(w)\text{ and } |w|\text{ is even}\}.$$ I have $$S \to S1S0S0S \mid S0S1S0S \mid S0S0S1S \mid \epsilon $$ but I'm not sure how to make the words even in length as well.

  • $\begingroup$ In each step you produce one 1 and two 2s. You could just use all rules that produce two 1s and four 2s. $\endgroup$ – gnasher729 Mar 29 '19 at 21:30