Search code examples
context-free-grammarcomputation-theorycontext-free-language

understanding basics of CFG


Have just started the chapter about CFL in Sipser's book and already fail to understand the basics.

Let this be the grammar of some language:

S -> A0A 
A -> 00A | 11A | 10A | 01A | e

I am really confused about this A0A part. Does it mean that the left hand side from 0 should be always the same as the right hands side. Does this mean 00011 or 000 are not in this language then?


Solution

  • Any S is any option you have for any A, followed by a single literal 0 and then another option for A. Each A is independent.

    The string 00011 is in the language because you can pick your two As (for example) such that the first one is 00A and the second one is 11A. If you pick recursively the empty string (e) for both of the "remaining" As, when you concatenate everything you'll end up with the string 00011.

    You can do a similar thing to obtain the string 000.