Tips for creating “Context Free Grammar” [duplicate]

I am new to CFG's, Can someone give me tips in creating CFG that generates some language

For example

$L =\{ w v w^R \mid v,w\in \{a,b\}^*\wedge|v| \text{ is even } \}$, where $w^R$ is the reverse of string $w$.

I'm having trouble understanding the language .. I want to build DFA to convert it

• Welcome to SE Computer Science. What is your idea of the language, even if you have trouble understanding it? What can a DFA have to do with your problem? – babou May 27 '15 at 18:08
• I would build a DFA to convert it to CFG .. but the language not clear fo me – Abdallha dagga May 27 '15 at 18:13
• use the search engine to find similar questions in this site, and get some intuition. See, for example, this question – Ran G. May 27 '15 at 18:41
• also check our reference questions, and in particular this one – Ran G. May 27 '15 at 18:45
• I think you are confusing DFA (Deterministic Finite Automaton) with PDA (Push-Down Automaton) – babou May 27 '15 at 18:48

Mmmm.

Let me note that in fact $L =\{ w v w^R \mid v,w\in \{a,b\}^*\wedge|v| \text{ is even } \}$ equals $\{ v \mid v \in \{a,b\}^*\wedge|v| \text{ is even } \}$.

Al strings in $L$ are of even length, and conversely all strings of even length can be otained by taking $w=\varepsilon$.

That should help.

• I wonder whether this was expected ! – babou May 27 '15 at 23:43
• @babou That is a good question. Perhaps the DFA confusion is related to this? – Hendrik Jan May 28 '15 at 0:20
• Cute! It might help the OP even more if you included a sentence of explanation. (Too bad I can't upvote twice.) – Rick Decker May 28 '15 at 1:12
• It is really a great psychological example of the way we work, and what may block us. Science is largely a question of looking at thing the right way. Hence the importance of conceptualization and notation. But in such a simple example ... Great for teaching. – babou May 28 '15 at 8:40
• I think this question should not be closed. The answer is indeed too cute. What do you think? cc @RickDecker – babou May 28 '15 at 13:59

Hints:

1. Construct a non-terminal $V$ and appropriate productions so that $V$ generates all strings of even length.

2. Create productions so that your starting symbol $S$ generates $wVw^R$ for all $w$. To accomplish that, modify a grammar for $ww^R$.