简体   繁体   中英

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?

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 A s (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" A s, when you concatenate everything you'll end up with the string 00011 .

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

A transforms to either empty, or two binary digits then A. It means that A transforms to any sequence of even number of binary digits.

S transforms to A, then 0, then A. This means that S is transforms to even number of binary digits, then 0, then even number of binary digits. That is, S is any sequence of odd number of binary digits with 0 in the middle.

Does it mean that the left hand side from 0 should be always the same as the right hands side.

No, why? Two different A's can transform to different sequences.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM