Let's consider this CFG-

S->AB [Here, **S** is the starting variable]

Now, the question is- Check if ab is a valid string for the given string or not?

I thought an answer. And that is-

 ->CB [A->C]
 ->Cb [CB->Cb]
 ->ab [C->a]

My question is, Can we generate string ab from this CFG in this way?

  • $\begingroup$ The grammar that you included is not a context-free grammar. The left side of the production rules of a context-free grammar must consist of exactly one non-terminal, but the rule $CB \to CB$ has two non-terminals on the left side. (This is why it's "context free" – the context of a non-terminal does not affect its expansions) $\endgroup$
    – Curtis F
    Sep 26 at 8:00
  • $\begingroup$ @CurtisF what it should be? $\endgroup$
    – shadril238
    Sep 26 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.