I'm trying to write a CFG over the alphabet Σ = {a,b} for all words starting and ending with the same number of a's, with at least one b in the middle.
Now I understand the basic concept of CFG, variables, production rules, etc. Unfortunately I've run out of ideas for writing the aforementioned CFG. All I've got so far is
S → aYXYa
X → XbX | b | λ
Y → ???
I think that the production rules S and X will give me a string with two as on both sides with as many bs in the middle as I'd like. However, I'm not sure how I can also put as many as on both sides of the bs while making sure there are exactly the same number of as on each side.
Any suggestions, solutions would be much appreciated. Thanks.