[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
Signtoken.A
DateYeartoken.The literal "-".
A
DateMonthtoken.The literal "-".
A
DateDaytoken.
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
Decimaltoken.The literal "e".
An optional
Signtoken.One or more
Digittokens.
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
HexDigittokens.
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..;