0
$\begingroup$

Find a CFG for the following language:

$$L = \{a^i b^j a^n b^m \mid i + j = n + m\}$$

I'm not sure how I can do that context free. I know that I have to borrow one char from the left group for each char from the right group. but not sure how.

$\endgroup$
  • 1
    $\begingroup$ Welcome to Computer Science! What have you tried? Where did you get stuck? We do not want to just hand you the solution; we want you to gain understanding. However, as it is we do not know what your underlying problem is, so we can not begin to help. See here for tips on asking questions about exercise problems. If you are uncertain how to improve your question, why not ask around in Computer Science Chat? $\endgroup$ – Raphael Jan 15 '17 at 12:06
  • $\begingroup$ With an automaton, it's easy. You use the stack to count (in unary) and accept when it's empty. And you remind yourself which part you're reading with states. $\endgroup$ – xavierm02 Jan 15 '17 at 13:03
  • $\begingroup$ cs.stackexchange.com/q/18524/755 $\endgroup$ – D.W. Jan 16 '17 at 3:45
2
$\begingroup$

The idea is to use non-terminals $X_{\alpha\beta}$, where $\alpha,\beta \in \{a,b\}$, that support the production $X_{\alpha\beta} \to \alpha X_{\alpha\beta} \beta$. You have to combine them somehow so that you obtain the language $L$, but I'll leave the details to you.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.