Operators

An operator is a symbol that performs a specific mathematical, relational, or logical function. The Security Policy Scripting Language supports the types of operators that are listed in the following table.

Operator Type Symbols
Arithmetic Operators *, /, +, -, %, ++, --, +=, -=, *=, /=, %=
Logical Operators &&, ||, !
Relational Operators >, >=, <, <=, ==, !=
Special Operators ( ), [ ], +, ?:, in, ,

Every operator has an intrinsic precedence order associated with it. The precedence order determines the evaluation order for expressions containing more than one operator. The operator with the highest precedence evaluates first. In most cases, operators of the same precedence are evaluated left to right. The following table lists the operator precedence.

Precedence Operator Associativity
Highest {} Left to right
  ( )[] Left to right
  in Left to right
  !++-- Right to left
  - (unary) Left to right
  */% Left to right
  +- Left to right
  <><=>= Left to right
  ==!= Left to right
  && Left to right
  || Left to right
  ?: Right to left
  =+=-=*=/=%= Right to left
Lowest , Left to right
Following the rules of operator precedence, the statement
5 + 6 - 3 * 4 + 8 / 4
        

is resolved as:

Step 1: 3*4 = 12
Step 2: 8/4 = 2
Step 3: 5 + 6 - (12) + (2)
Result: 1

Modifying the operator precedence order as shown here can change the result produced in the example above.

(5 + 6 - 3) * (4 + 8) / 4

The statement is resolved as follows:

Step 1: 5 + 6 -3 = 8
Step 2: (4 + 8) = 12
Step 3: 8 * 12 / 4
Result: 24