recategorized by
499 views
0 votes
0 votes

Consider the context-free grammar below ($\epsilon$ denotes the empty string, alphabet is $\{a,b\}$):

$$S\rightarrow \epsilon \mid aSb \mid bSa \mid SS.$$

What language does it generate?

  1. $(ab)^{\ast} + (ba)^{\ast}$
  2. $(abba) {\ast} + (baab)^{\ast}$
  3. $(aabb)^{\ast} + (bbaa)^{\ast}$
  4. Strings of the form $a^{n}b^{n}$ or $b^{n}a^{n},n$ any positive integer
  5. Strings with equal numbers of $a$ and $b$
recategorized by

1 Answer

0 votes
0 votes

$S\rightarrow \epsilon \mid aSb \mid bSa \mid SS$

  • $S\rightarrow a\underline{S}b$
  • $S\rightarrow a\underline{S}Sb$
  • $S\rightarrow a a\underline{S}b Sb$
  • $S\rightarrow a ab\underline{S}a b Sb$
  • $S\rightarrow a aba b \underline{S}b$
  • $S\rightarrow a aba b b$


Stings with an equal number of $a's$ and $b's.$

References:

So, the correct answer is $(E).$

edited by
Answer:

Related questions

3 votes
3 votes
1 answer
4