user1807108
user1807108

Reputation:

BNF repeating sequence of characters

How do I find a sequence of 3 or more "a" followed by the same number of "b" with a BNF expression?

I know that

{<letter>} or {<letter> | <digit>}

are used for repetitive items occuring zero or more times but I don't know how to get the number of times "a" has repeated to make sure "b" repeats the same number of times

Upvotes: 1

Views: 1501

Answers (1)

Martin Ender
Martin Ender

Reputation: 44279

Something like this:

<valid-string> ::= "aaa" <ab> "bbb"
<ab>           ::= "a" <ab> "b" | ""

This starts off with three a and three b to take care of the minimum requirement. Then it allows the insertion of a and b at the same time (keeping the amount the same) while repeating itself in the middle of the string.

Upvotes: 2

Related Questions