0
$\begingroup$

Input alphabet = {a,b,c}

I tried with the following grammar :-

S -> aSa / bSb / T
T -> cTc / cSc / cBc
B -> c / cXc
X -> a / b / aXa / bXb / epsilon

This grammar is not able to generate 'cacac' .Is there any way to write this grammar with less number of productions or are any productions redundant here ?

Thanks.

$\endgroup$
0
$\begingroup$

You have a symbol S that needs to generate a palindrome with at least 3 c's. Create a symbol X that needs to generate a palindrome with at least 1 c, and a symbol Y that needs to generate a palindrome with no requirement for c's.

S -> aSa | bSb | cXc
X -> aXa | bXb | cYc | c
Y -> aYa | bYb | cYc | a | b | c | eps

I think the essential step was not to start writing down productions, but to write down which different symbols you need to produce which kinds of output. The productions are then trivial.

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.