0
$\begingroup$

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.

$\endgroup$

marked as duplicate by D.W. Mar 29 at 6:31

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\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 at 21:30