Producing CFG for a language

238 Views Asked by At

The language of palindromes over {a,b} whose length is a multiple of 3, I am clueless as to how you would attempt this.

1

There are 1 best solutions below

2
On

A context free grammar has a few components:
$N$, the set of non-terminal symbols
$T$, the set of terminal symbols
$S$, the starting string.

So since length is a multiple of three, start with all the palindromes of length three:

$S \to aaa$

$S \to bbb$

$S \to aba$

$S \to bab$

This enures that if we go directly to a terminal symbol, that the string satisfies the condition. Now, here's the big hint- with what do you surround any of these terminals such that you have a palindrome?