Ask your own question, for FREE!
Computer Science 21 Online
OpenStudy (anonymous):

The following BNF grammar consists of: a | ε b | c | bc a. List 10 distinct strings generated by this grammar:

OpenStudy (anonymous):

ε a aa aaa bc bbc cbc bcbc bbbc ccbc

OpenStudy (anonymous):

how are "ε", "cbc", "bcbc" and "ccbc" generated by this grammar? looks to me like it is any number of "a"s (including none) followed by any number of "b"s (at least one) followed by any number of "c"s (at least one)

OpenStudy (anonymous):

yes you are kinda right from S you can get only AB, I treated it as A|B, sorry

OpenStudy (anonymous):

However you can get cbc S->AB->εcB->εcbc->cbc You can get any number of a's (including zero) followed by any number of b's or c's and ending with bc

OpenStudy (anonymous):

so bc abc aaaabc aabbbbbcccbcbcbcbcbc bcbbbbbbbbbcbbc ccccccbc

OpenStudy (anonymous):

also as I understand question should be written as to distinguish literals <S> -> <A><B> <A> -> a<A> | ε <B> -> b<B> | <B>c | bc

OpenStudy (anonymous):

I still have a problem with "cbc" I don't see any way to get a "c" in the middle of the "b"s S->AB->εB->εBc-> εbBc OR εBcc OR εbcc

OpenStudy (anonymous):

oh damn again I interpreted it wrongly :/ sorry I thought it's <B> b<B> | c<B> | bc you can't get cbc

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!