$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?
Computer Science Stack Exchange is a question and answer site for students, researchers and practitioners of computer science. It only takes a minute to sign up.
Sign up to join this community$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 believe the following CFG meets the requirements
$$ S \to aSB \mid \varepsilon\\ B \to b \mid c $$
I believe, the answer of @Acid is correct.
Also, It is sometimes hard to come up with the productions rules directly by looking at the language.
An easier (a bit longer) approach can be, making a Push Down Automata (PDA) accepting the given language and converting the transitions of PDA into production rules.
For this language, it can be observed that, we can just push some stack symbol let's say '#' into the stack on seeing 'a' as the input symbol and pop from the stack on seeing 'b' or 'c'. Also make sure that, 'a' never comes after we see at least one 'b' or 'c'.
Once the PDA is done, this is a very informative video on converting to PDA to CFG.
Let me know in the comments, if you need any clarification in the conversion.