Question

Let Σ = {a, b, c}. Let L = {w∈Σ∗ |w={w1,w2,...,wn} is a palindrome,and wi !=wi+1...

  1. Let Σ = {a, b, c}. Let L = {w∈Σ∗ |w={w1,w2,...,wn} is a palindrome,and wi !=wi+1 ∀1≤i<n}. In other words, L contains palindromes that don’t ever have the same character occur twice in a row.

    1. Give the rules for a CFG that generates L.

    2. Convert your CFG into an equivalent PDA using the construction from class. You may use shorthand to push multiple symbols onto the stack in a single move.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Lets consider a simpler question at first without any restriction on same character occuring twice in a row. The CFG for this simpler version can be given as follows.

S -> aSa | bSb | cSc | a | b | c | ε

now the problem with this definition for the original question is that two characters might occur together.

To avoid this we have to apply some further restrictions on the way we expand.

consider an example, let us expand S to aSa. Now in the next step the S in aSa should not be expanded to aSa again. For this, let us introduce three new non terminals Sa, Sb, Sc, with a promise that Sa would not expand to aSa in the immediate next step, and similarly Sb and Sc too won't.

The corrected grammar for the original case can now be written as.

S -> aSaa | bSbb | cScc | a | b | c | ε

Sa -> bSbb | cScc | b | c

Sb -> aSaa | cScc | a | c

Sc -> aSaa | bSbb | a | b

An important fact to note here is that none of the expansions of Sa, Sb orSc  contain ε. because otherwise the two terminals surrounding the non terminal would come together. Ex. aSaa would yield aa, which is not acceptable in the given question.

For steps to convert a CFG to PDA see : www.cs.nuim.ie/~jpower/Courses/Previous/parsing/node35.html

PDA:

Let our PDA be defined by

M = (Q, ∑, S, δ, q0, Z0, F)

where

Q = {q0, q1, q2}

∑ = {a, b, c, ε}

S = {a, b, c, S, Sa, Sb, Sc, Z0}

F = {q2}

Comment if you want details about the above symbols.

The transitions are defined as follows:

?(q0, ε, Z0) = {(q1, SZ0)}

?(q1, ε, S) = {(q1, aSaa), (q1, bSbb), (q1, cScc), (q1, a), (q1, b), (q1, c), (q1, ε)}

?(q1, ε, Sa) = {(q1, bSbb), (q1, cScc), (q1, b), (q1, c)}

?(q1, ε, Sb) = {(q1, aSaa), (q1, cScc), (q1, a), (q1, c)}

?(q1, ε, Sc) = {(q1, aSaa), (q1, bSbb), (q1, a), (q1, b)}

?(q1, a, a) = {(q1, ε)}

?(q1, b, b) = {(q1, ε)}

?(q1, c, c) = {(q1, ε)}

?(q1, ε, Z0) = {(q2, Z0)}

Comment if you find anything that you are not able to understand.

Add a comment
Know the answer?
Add Answer to:
Let Σ = {a, b, c}. Let L = {w∈Σ∗ |w={w1,w2,...,wn} is a palindrome,and wi !=wi+1...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT