Empty string as base case in BNF recursion?

I write a little grammar as an exercise for the class, and my professor did not understand too much what qualifies the legal expression of BNF in terms.

The BNF grammar is supposed to recognize strings in this form: AB, AABB, AAABBB, A ... B ... (general form: AnBn)

So, what I came to, wrote:

<S> --> A<S>B | ""

My simple yes / no question is, is this legal in the BNF, and if not why?

<...> is nonterminal, I have no idea if this is an agreement or what not

+3
source share
1 answer

Yes, this is acceptable by the BNF. You can see an example of this in the Wikipedia entry in the example of US mailing addresses.

As a rule, I saw an empty string represented as & epsilon ;.

+3
source

Source: https://habr.com/ru/post/1787214/


All Articles