How do I know how many times to repeat a replacement when generating a grammar?

20 Views Asked by At

My textbook discusses Context Free Grammars, and provides the following rules:

A -> 0A1

A -> B

B -> #

The resulting string is 000#111. Shouldn’t it just be 0#1? My steps:

A

0A1

0B1

0#1

I’m missing something obvious, what it is?

How do I know how many times to repeat a replacement when generating a grammar?