Can this language be defined by a Context Free Grammer? I was solving one of my practice questions, defining a language with Context Free Grammar Productions , but I am stuck on one question , Here are my attempt:

Question: $L = \{a^n b^m c^p \mid n = m + p + 2\}$

My Attempt: 

S -&gt; aaBC

B -&gt; aBb | ^

C -&gt; ?  (Now how can i increase length of `a` Terminal by C as i increased from B)


Is this language not context free / impossible ?
You'll need to "wrap" the Bs in the Cs:

S -&gt; aaC
C -&gt; aCc | B
B -&gt; aBb | ɛ


With that, we have

$L(B) = a^m b^m$,

$L(C) = a^p \cdot L(B) \cdot c^p = a^p a^m b^m c^p$ and

$L(S) = a^2 \cdot L(C) = a^2 a^p a^m b^m c^p = a^{m+p+2} b^m c^p$.