0
votes

Having some confusion on a CFG question.

Which of the following are allowed with this grammar

S -> aS | bA
A -> c  | cA


A: a*bc*
B: a*b*c*
C: a*b*c
D: a*bc+

My confusion lies within the *, which I understand to mean 0 or more times.

For A, I see this NOT working, as you can have multiple a's (aS repeated), followed by a b (bA), followed by c. But the c cannot have an *, as if you call a b (bA), A will ALWAYS give a c. and the * says you could have zero.

For B, I see this NOT working as the same rule eventually applies since c has an *.

For C, I see this MAYBE working because you can have multiple a's (aS repeated), followed by a possible b, followed by a c. I am confused here though because of the b*. Does this mean it could potentially have multiple b's? If so this would be un-true because 'b' can only occur once with this grammar context defined above.

For D, I see this COMPLETELY working as a can occur multiple times (aS repeated), b will occur ONCE, and c WILL occur 1 or more times.

So A no, B no, c maybe?, d Yes.

Is this thinking right or wrong? The * is throwing me off.

1

1 Answers

1
votes

Option D represents the grammar exactly, the others will always fail at some point, so you got it kinda right. Options A will fail because 'c' isn't allowed to be zero by the grammar, options B and C will fail because one and only one 'b' is allowed.