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?
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
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$