Compartir a través de


RepetitionBehavior

The RepetitionBehavior enables repeating a behavior or making it optional.

Syntax Definition

RepetitionBehavior ::= Behavior ( * | + | ? ) | Behavior { Number [, [ , Number] ] } .

Remarks

This notation works as shown in the following table.

Notation Description

B*

Perform behavior B zero or more times (potentially infinite). Equivalent to B{0,}.

B+

Perform behavior B one or more times (potentially infinite). Equivalent to B{1,}.

B?

Perform behavior B zero or one times. In effect, makes B optional by making its initial states accepting. Equivalent to B{0,1}.

B{n}

Perform behavior B exactly n times where 0 <= n.

B{n,}

Perform behavior B at least n times (potentially infinite) where 0 <= n.

B{n,m}

Perform behavior B at least n times and at most m times where 0 <= n <= m. For example, B{3,5} means perform B at least 3 times and up to 5 times. This range repetition is always finite.

The offered signature is that of the behavior operand. An error results if behavior B has no accepting states, B{0} being a special case of an initial empty state of B marked as accepting without an outgoing transition. If B is an action, the last required repetition transitions to an accepting state for the expression as do any subsequent optional occurrences. Each prior non-final action transitions is accepting only within the sequence.

Example

The following Cord code shows the use of the RepetitionBehavior operators. This code is extracted from the stand-alone Operators sample (see Finding the Code Samples).

machine ZeroOrMore() : AllActivities
{
    Party*
}

machine OneOrMore() : AllActivities
{
    Party+
}

machine Optional() : AllActivities
{
    Party? ; NoParty
}

In machine ZeroOrMore, the Zero or More RepetitionBehavior operator (*) constructs a behavior consisting or zero or more occurrences of its Party operand. Note that the accepting initial state allows the empty behavior and the looping paths allow the behavior to restart.

In machine OneOrMore, the One or More RepetitionBehavior operator (+) builds a behavior consisting of arbitrary occurrences of its Party operand. Note that the non-accepting initial state, meaning the empty path, is not included.

In machine Optional, the Option RepetitionBehavior operator (?) makes the whole Party behavior optional. The example also shows use of the Tight SequencingBehavior operator (;).

See Also

Reference

Machine
CordScript

Concepts

Cord Syntax Definition

Other Resources

Cord Scripting Language