# How to make the length even for the words whose number of 0s is double its number of 1s? [duplicate]

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.

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