The following BNF grammar consists of:
a | ε
b | c | bc
a. List 10 distinct strings generated by this grammar:
ε a aa aaa bc bbc cbc bcbc bbbc ccbc
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)
yes you are kinda right from S you can get only AB, I treated it as A|B, sorry
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
so bc abc aaaabc aabbbbbcccbcbcbcbcbc bcbbbbbbbbbcbbc ccccccbc
also as I understand question should be written as to distinguish literals <S> -> <A><B> <A> -> a<A> | ε <B> -> b<B> | <B>c | bc
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
oh damn again I interpreted it wrongly :/ sorry I thought it's <B> b<B> | c<B> | bc you can't get cbc
Join our real-time social learning platform and learn together with your friends!