0

I am not really good at generating grammars, because I find it very hard to come up with rules. However, after a lot of trial and error, this is what I could generate:

A={a,b} Vt={a,b} Vn={S,A,B} R= S->BS S->AS S->e A->a B->b

was this the correct way? if no, what could be improved? thank you!

Hans Hüttel
  • 4,271
koby
  • 47
  • Consider starting with $S$, then use $S -> AS$ then use $S->BS$ and then $S->e$. You would get $S \to AS \to ABS \to ABe$. Then that would give $ab$ which is not a palindrome. – AHusain Feb 20 '20 at 19:07
  • Oh I see. Do you have any suggestions or hints as to how to solve this issue? – koby Feb 20 '20 at 19:13
  • Hint: If $w$ is a palindrome, that starts with $a$, then what does it end with and what can you say about everything between the first and last? – AHusain Feb 20 '20 at 19:18
  • Oh I figured it out! I used S->e, S->a,S->b,S->aSa, S->bSb. Thank you! – koby Feb 20 '20 at 19:21

0 Answers0