-2

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?

John L.
  • 39,205
  • 4
  • 34
  • 93
Barry
  • 39
  • 7

3 Answers3

1

Here is a derivation in your grammar:

$$ S \to aS \to aab. $$

The word $aab$ does not belong to your language, hence your grammar is incorrect.

Yuval Filmus
  • 280,205
  • 27
  • 317
  • 514
-1

I think this is the solution: $$S\to \epsilon \mid aaSbb $$

zoldxk
  • 111
  • 1
  • 6
-1

the second grammer you wrote, is right. it can involve all strings belongs to the language with no extra string.