# CFG for the language L ={a^n w | w \in {b,c}^*, n= count of b.c in w. }

$$L =\{a^nw \mid w \in \{b,c\}^*$$, $$n=$$ #$$_b$$ + #$$_c\}$$

$$\bullet$$ #$$_b$$ denotes the number of $$b$$'s in $$w$$

$$\bullet$$ #$$_c$$ denotes the number of $$c$$'s in $$w$$

I have some trouble designing a CFG for the language above. How can I do this?

• I do not believe the language $L$ to be context-free. If it was context-free then, by the pumping lemma for context-free languages there exists a number $p$ such that any string $s \in L$ of length at least $p$ can be split into $s = u v w x y$ satisfying conditions $1$ to $3$ of the pumping lemma. Consider the string $s = a^p b^p c^p \in L$ - no split of $s$ can satisfy all conditions of the pumping lemma, therefore $L$ is not context-free. – AcId Apr 28 at 11:30
• @AcId's comment is true if you mean (#a = #b and #a = #c). But there is a CFG if you mean (#a = #b + #c). Can you clarify what "number of a's is equal to number of b's and number of c's" means? – frabala Apr 28 at 11:38
• @frabala You are right; in the latter case the language would be context-free. – AcId Apr 28 at 11:52
• @Acld For instance aabc, aacc or ab – Fatih Canbekli Apr 28 at 13:37
• The rules of your CFG should ensure that every time an $a$ is produced in the lead part of the string, then either a $b$ or a $c$ should be produced in the trailing part of the string. – AcId Apr 28 at 16:01

$$S \to aSB \mid \varepsilon\\ B \to b \mid c$$