# CFG for the given language $L = \{~ a^\ell a^n b^m c^m d^n e^\ell ~|~ \ell,n,m \geq 0 \}$

I am writing this CFG to solve the problem:

$$S \to ASBSC$$

$$A \to aAe ~|~ ε$$

$$B \to aBd ~|~ ε$$

$$C \to bcC ~|~ ε$$

Is this correct or not?

• We discourage "please check whether my answer is correct" questions, as only "yes/no" answers are possible, which won't help you or future visitors. See here and here. Can you edit your post to ask about a specific conceptual issue you're uncertain about? As a rule of thumb, a good conceptual question should be useful even to someone who isn't looking at the problem you happen to be working on. If you just need someone to check your work, you might seek out a friend, classmate, or teacher.
– D.W.
Apr 9 at 20:57
• The way to verify that your grammar is correct is to prove it correct. See cs.stackexchange.com/q/11315/755 for the techniques.
– D.W.
Apr 9 at 21:16
• Sorry, but your grammar is totally wrong. I mean really completely totally wrong. For example, the last rule creates strings like bcbcbcbc which are not in the language. Looks like you asked some "Artificial Idiocy" like ChatGPT for an answer and try to check it. Nov 24 at 10:31

Strings in your grammar could potentially terminate with a sequence of $$bc$$s because of the following, which is not desired.

$$S \rightarrow ASBSC$$

$$C \rightarrow bcC \ | \ \epsilon$$

The correct grammar in this case would be:

$$S \rightarrow aSe \ | \ A \ | \ \epsilon$$

$$A \rightarrow aAd \ | \ B \ | \ \epsilon$$

$$B \rightarrow bBc \ | \ \epsilon$$

• The word $aaee$ cannot be generated by your grammar, despite being in the language. Nov 23 at 22:05
• @Nathaniel I am sorry. I probably wrote that in a hurry. Nov 25 at 2:31