I have just started learning formal languages and here is a question I am facing a little hurdle:
Construct a context-free grammar for $\{ a^{2n}b^{2n} \mid n \ge 0 \}$.
This was what I got at first. $$S \to ab\mid aS\mid Sb\mid ab$$ Now I am getting this, $$S\to \epsilon$$
$$S\to aaSbb$$
$$G=(V,\Sigma,R,S)=(\{S,a,b\},\{a,b\},R,S)$$
$$R= \{S \to aaSbb\mid \epsilon\}$$ Is the approach to this question, right or is it done in a different way?
a
s and an even number ofb
s, while your proposed grammar immediately derives a string (ab
) which does not have an even number of anything (through two different productions, which is redundant). $\endgroup$