0

Is there a nice way to give context free grammar for $$\{a^nb^ma^kb^l:n+m=k+l\}?$$

From PDA point of view it seems we just push + on stack if we see a, push + on stack if we see b, pop + from stack if we see a, pop + from stack if we see b and accept if you have empty stack.

Raphael
  • 72,336
  • 29
  • 179
  • 389
  • Every decent automata theory textbook gives a description of how to convert a PDA to a CFG. So, simply apply that construction and you'll get a CFG for that language. There's little point in us repeating the description that construction here, and a question that says "please run standard algorithm X on my particular input Y for me" seems of unclear value (to me) -- better for you to run it yourself. – D.W. Nov 07 '15 at 10:30

1 Answers1

3

Here is a simple grammar: $$ \begin{align*} & S \to aSb|U|V \\ & U \to aUa|T \\ & V \to bVb|T \\ & T \to bTa|\epsilon \end{align*} $$

Yuval Filmus
  • 276,994
  • 27
  • 311
  • 503