0
$\begingroup$

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?

$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$
    – D.W.
    Apr 9 at 20:57
  • 1
    $\begingroup$ The way to verify that your grammar is correct is to prove it correct. See cs.stackexchange.com/q/11315/755 for the techniques. $\endgroup$
    – D.W.
    Apr 9 at 21:16
  • $\begingroup$ 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. $\endgroup$
    – gnasher729
    Nov 24 at 10:31

1 Answer 1

0
$\begingroup$

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$

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.