I would like to write something like

<byte> ::= <bit>*8

to mean that a <byte> is a sequence of exactly 8 <bit>'s.

Is there a way to do this in BNF[1][2] or a widely used extension of BNF? How?


In BNF, you would just define that by repeating the symbol:

<byte> ::= <bit> <bit> <bit> <bit> <bit> <bit> <bit> <bit>

On the other hand, Augmented Backus–Naur form defines repetition:

<example> ::= *<bit>

The above means:

<example> ::= "" | <bit> <example>

So, none or more bit.

For one or more you can say:

<example> ::= 1*<bit>

For a range (for example one to four), inclusive:

<example> ::= 1*4<bit>

Or a fixed number:

<example> ::= 8*8<bit>

Which you can also write like this:

<example> ::= 8<bit>

Note: In ABNF, < and > are optional.

  • Thanks. Based on the reference, it looks like this is called "specific repetition." – Ana Nimbus Oct 10 '19 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.