Develop the context free grammar to match this language (puzzle) This is a puzzle type question which asks to create a context-free grammar to match this language:

{ x#w | x,w are in {a,b}*, and w contains the reversal of x as a substring }


So some example strings to try:
    #, a#a, b#b, ab#ba, ab#aaabbba

Does anyone have any advice on how to get better at these types of problems?  I am generally a good problem solver, but have trouble developing grammars for languages for some reason.  I am completely stuck on this question.  Here is my attempt:

S --&gt; TR
T --&gt; aTa | bTb | #R
R --&gt; RR | 0 | 1 | empty


My guess is that we want to define the left side of the string in terms of the right side of the string.  

Edit:  As far as I can tell, the above answer seems to be correct now.  Only took me an hour to figure out!
X --&gt; Xa | Xb | Y

Y --&gt; aYa | bYb | #Z

Z --&gt; Za | Zb | empty


Y is the part that handles the string reversal. X and Z handle junk to the right and left of the reversal of x.