Repetition
[This content is no longer valid. For the latest information on "M", "Quadrant", SQL Server Modeling Services, and the Repository, see the Model Citizen blog.]
Repetition operators specify that multiple occurrences of a term occur. The operators include the following:
? indicates optionality, or in other words, that zero or one of the term is valid.
+ indicates that one or more occurrences of the term are valid.
* indicates that zero or more occurrences of the term are valid.
#n where "n" is an integer, indicates that exactly n occurrences of the term are valid.
#n..m where "n" and "m" are integers and m is greater than n, indicates that between n and m occurrences of the term are valid.
#n.. where "n" is an integer, indicates that n or more occurrences of the term are valid.
Examples
These examples are taken from the grammars that define the “M” modeling language.
Optionality
This example states that when tokenizing the input stream, the DateLiteral
token is inserted when the following tokens are recognized, in order:
An optional
Sign
token.A
DateYear
token.The literal "-".
A
DateMonth
token.The literal "-".
A
DateDay
token.
token DateLiteral = Sign? DateYear "-" DateMonth "-" DateDay;
One or More
This example states that when tokenizing the input stream, the Scientific
token is inserted when the following tokens are recognized, in order:
A
Decimal
token.The literal "e".
An optional
Sign
token.One or more
Digit
tokens.
token Scientific = Decimal "e" Sign? Digit+;
Zero or More
This example states that when tokenizing the input stream, the Binary
token is inserted when the following tokens are recognized, in order:
The literal "0x".
Zero or more
HexDigit
tokens.
token Binary = "0x" HexDigit*;
Range Operator Examples
The following examples show the different versions of this operator.
// Recognizes exactly 5 "A"s : "AAAAA"
token A5 = "A"#5;
// Recognizes from 2 to 5 "A"s : "AA", "AAA", "AAAA", "AAAAA"
token A5 = "A"#2..5;
// Recognizes 3 or more "A"s : "AAA", "AAAA", "AAAAA"....
token A5 = "A"#3..;