Software
Crestron
SIMPL+
Operators, Expressions, and Statements
This section deals with the core programming elements in SIMPL+.
Operators
Operators take one or two “operands” and combine them in some way to produce a
result. In SIMPL
+
operators can be binary (takes two arguments) or unary (takes a
single argument). For example, the + operator is binary (e.g., x + y), while the
– operator can be binary or unary (e.g., x – y, or –x are valid). Most operators in
SIMPL
+
are binary. Notice that operands do not have to be simple constants or
variables. Instead they can be complex expressions that result in an integer.
SIMPL+ operators can be classified into three categories: arithmetic, bitwise, and
relational. The sections below describe each category briefly. For a complete list of
operators and their function, consult the latest revision of the SIMPL+ Language
Reference Guide (Doc. 5797)
.
Arithmetic Operators
Arithmetic operators are used to perform basic mathematical functions on one or two
variables. In all but one case, these operations make sense only for integer types
(includes analog inputs and outputs). For example, to add two integers, x and y,
together, use the addition op, as follows.
x + y
As mentioned in the previous paragraph, use these operators with integers in all but
one case. The exception is the + operator when used with string variables. In this
case the operator performs a concatenation instead of addition, which is very handy
for generating complex strings from smaller parts. This is discussed in more detail
later.
Bitwise Operators
Arithmetic operators deal with integers as a whole. Bitwise operators treat the
individual binary bits of a number independently. For example, the unary operator
NOT
simply negates each bit in number, while the & operator performs a binary
“and” operation to each bit in the arguments (bit0 and-ed with bit0, bit1 with bit1,
etc.).
Relational Operators
Relational operators are used in expressions when it is necessary to relate (compare,
equate, etc.) two values in some way (the exception to this is the unary operator
NOT). When a comparison is done using a relational operator, the result is an
integer, which represents TRUE or FALSE. In SIMPL
+,
TRUE results equal 1 and
FALSE results equal 0. In general, any non-zero value is considered by SIMPL
+
to
be TRUE, while FALSE is always 0.
Typically, relational operators are used to help control the program flow. That is, test
certain conditions and the result determines what happens next. This is discussed in
more detail in “Controlling Program Flow: Branching” on page 24.
22
•
SIMPL+
Programming Guide – DOC. 5789A