I need to find a CFG where the word length $|w|$ is odd. Plus there must be a $0$ in the middle.
In a previous exercise I had to specify a CFG only for odd word length. I chose the following:
$G = (\{A,B\},\{0,1\},P,A)$
$P =\{A \to 1B \mid 0B, B \to 11B \mid 00B \mid 01B \mid 10B \mid \epsilon \}$
But with $0$ in the middle I have to make sure that I add the same amount of symbols on each side. How could I manage that? I was maybe thinking of a pushdown automata which keeps track of the symbols on each side..
any hints I could use?
EDIT: I may have found a solution. Could this work? $A \to 0A0 \mid 1A1 \mid 1A0 \mid 0A1 \mid 0$