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?
Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.
Sign up to join this communityIn 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.