Opaque Expressions
Behavior Execution Engine processes opaque behaviors and opaque expressions almost identically, so this documentation simply refers to them collectively as "opaque expressions."
Opaque expressions are specified by a Body
and Language
.
Behavior Execution Engine requires opaque expressions' language type to be English
or unspecified.
The only exception is that opaque behaviors that are used as the Method
of an operation
can have the language be ModelCenter
.
For opaque expression bodies, Behavior Execution Engine uses a Java-like syntax.
This syntax enables you to easily traverse the current SysML object's properties and operations using the dot
(.
) operator, making the opaque expressions in your state machines much more readable.
Behavior Execution Engine also provides a few global identifiers for the simulation that you can use in opaque
expressions.
Behavior Execution Engine executes all opaque expressions in zero simulation time.
Java-like syntax
Behavior Execution Engine evaluates expressions against the current context object, which is the instance specification that owns those expressions.
So, given the class and instance specifications in Figure 1, the examples in the following table show how to navigate properties
and operations using Behavior Execution Engine's Java-like syntax.
The example results are all for robert
's state machine session, and they assume that the
belongsToDepartment(department : String)
operation is backed by an appropriate
delegate implementation.
Figure 1: A class with instance specifications
Expression | Description | Result |
---|---|---|
nickname
|
Accesses the context object's property. | The string "Bob" |
manager
|
Accesses the context object's property. | The instance specification alice |
belongsToDepartment("Development")
|
Executes the context object's operation. | The boolean true |
manager.nickname
|
Accesses an accessible object's property. | The string "Alice" |
manager.belongsToDepartment("Development")
|
Executes an accessible object's operation. | The boolean true |
nickname = "Robbie"
|
Assigns a new value to the context object's property. |
Supported features
The following table lists common Java-like features that Behavior Execution Engine supports.
Feature | Description | Notation |
---|---|---|
String literals | Are specified with either ' or " .
|
'Development' , "Robbie" |
Number literals | Are either integers or real numbers. | 42 , 3.14 |
Boolean literals | Are either true or false .
|
true , false |
Arithmetic operators | Add, subtract, multiply, divide, or find the remainder (modulus) of two numbers. | + , - , * , / ,
% |
Comparison operators | Check whether one number is less than, greater than, or equal to another number. | < , <= , > ,
>= , == , != |
Logical operators | Determine the logical "and", "or", or "not" of boolean values. | && , || , ! |
Parenthetical expression | Resolves the contents of the parentheses before the rest of the expression. | ()
|
Assignment operator | Assigns a new value to a property. | =
|
Dot operator | Accesses the specified property of an object or executes the specified operation on the object. It may be chained, as long as the property or operation returns another object. | manager.nickname , manager.belongsToDepartment("Development") ,
manager.manager.manager.nickname |
Operators can accept values from literals, properties, or operation results, as long as the values have valid types.
For example, an integer can be assigned to a real, but not vice versa.
Arithmetic, comparison, and logical operators can only accept primitive types
(SysML::Libraries::PrimitiveValueTypes
).
Global identifiers
Opaque expressions often only need values that are either defined by the current context object or accessible through its properties, but Behavior Execution Engine provides a few identifiers that are available independent of class definitions, for use in special situations:
Identifier | Meaning | Description | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
$SELF
|
The current context object | $SELF is the implied start of an opaque expression in Behavior Execution Engine.
So $SELF.nickname and nickname are equivalent.
$SELF is most useful for when you need to pass the current context object as an argument to an operation,
for example otherObject.accept($SELF) .
|
|||||||||||||||||||||
$NOW
|
The current simulation time | $NOW is only available within state entry and exit behaviors and
within transition guards and effects, not within triggers.
Since Behavior Execution Engine treats transitions as instantaneous, $NOW will represent the same instant in time for the exit,
the guard, the effect, and the entry executed by a transition.
$NOW returns a >Moxie-Base::Structure::TimeInstant .
|
|||||||||||||||||||||
$SIMULATION_START
|
The start time of the simulation | $SIMULATION_START is available within state entry and exit behaviors
and within transition triggers, guards, and effects.
$SIMULATION_START returns a Moxie-Base::Structure::TimeInstant .
|
|||||||||||||||||||||
$SIMULATION_STOP
|
The stop time of the simulation | $SIMULATION_STOP is available within state entry and exit behaviors
and within transition triggers, guards, and effects.
$SIMULATION_STOP returns a Moxie-Base::Structure::TimeInstant .
|
|||||||||||||||||||||
$TIME
|
Operations to convert primitive datatypes to types usable in time events |
|