Consider the following CFG:
S | → | B(S)|B|BC |
B | → | aB|bbB|b |
C | → | cCc|c|[B] |
Which of the following strings can be derived from the start symbol
S?
Click on the arrow for the answer.
- bbb ⇒
- Yes. Replace S with B and follow your nose.
- bb ⇒
- No. Starting from B, if
you introduce b, you must stop. So
you introduce bb, but you cannot stop there, so there is
no way to produce two bs.
You can only make odd numbers of bs.
- ba ⇒
- No. There is no way to introduce an a at the end of
the string.
- abbb(bccc) ⇒
- Yes. Use S→B(S), then use S→BC
on the second S.
- bbb[ab] ⇒
- Yes. Start with S→BC, and use C→[B],
then you can derive each part from B.
- cabc ⇒
- No. To generate a c, you must introduce a C.
From S, you can't use S→B(S) since you don't
want the parens. You can't use S→B since you can never
introduce a C. So you must start with S→BC. But
anything that comes from B must start with a or
b. So nothing can generate cabc.
- bbab(bc[b]c) ⇒
- Yes. Start with S→B(S)→B(BC)→B(BcCc)→B(Bc[B]c).
Proceed from there.
- bbbccc ⇒