I'm having trouble to find context free grammars which generate following languages:
$L_1 = \{a^nb^{2n}∣n\ge1\}$
$L_2 = \{a^pb^{p+q}a^q∣p,q\ge1\}$
I'm having trouble to find context free grammars which generate following languages:
$L_1 = \{a^nb^{2n}∣n\ge1\}$
$L_2 = \{a^pb^{p+q}a^q∣p,q\ge1\}$
HINT: For $L_1$ you need a very small modification of a context-free grammar for $\{a^nb^n:n\ge 1\}$, and I suspect that you’ve seen such a grammar: it has just two productions, $S\to aSb$ and $S\to ab$. That same grammar contains the essential idea needed for a grammar for $L_2$ as well. Start with a production $S\to XY$, let $X$ produce strings of the form $a^pb^p$, and let $Y$ do the rest.