Derived CompositionsΒΆ
Elementary compositions enable the definition of more complex and more practical operations. A fixed number of concatenations of the same DFA may be manually written as:
RRRRRRRR
which matches if and only if there are eight adjacent lexemes matched by R
.
The shorthand for n
repeated concatenations is
- R{n}
With
n
being an integer greater or equal zero, the expression matches exactlyn
concatenations of lexemes matched byR
.
- R{n,m}
With
n
andm
being integers greater or equal zero, the expression matchesn
tom
(includingm
) concatenations of lexemes matched byR
. It is a shorthand for the union of allR{i}
withi
iterating fromn
tom
.
In general, a restriction on the number of repetitions is accomplished with
ranges in {
and }
brackets. In practical applications, repetitions are
often restricted with respect to their number. While the Kleene closure also
matches the lexeme of zero length, the Kleene plus operation requires at
least one repetition to match.
- R+
The Kleene plus operation. It matches an arbitrary number of repetitions of what is matched by
R
but not zero repetitions. It is a shorthand for the concatenation ofR
andR*
.
The minimum number of repetitions can also be restricted by integers greater than one.
- R{n,}
With
n
being an integer greater or equal zero, matches an arbitrary number of repetitions of what is matched byR
but not less thann
number of repetitions. It is a shorthand for the concatenation ofR{n}
andR*
.
Zero or one repetition are called optional expressions and their
syntax is the ?
suffix.
- R?
Matches zero or one occurrence of what matches
R
. It is a shortand for the union of\Nothing
andR
.