Hapter, Perators, Operations – Teledyne LeCroy CATC Scripting Language Reference Manual User Manual

Page 12: Operator precedence and associativity

Advertising
background image

C

HAPTER

4

Operators

CATC Scripting Language

8

C

HAPTER

4: O

PERATORS

An operator is a symbol that represents an action, such as addition or subtraction,
that can be performed on data. Operators are used to manipulate data. The data
being manipulated are called operands. Literals, function calls, constants, and
variables can all serve as operands. For example, in the operation

x + 2

the variable

x

and the integer

2

are both operands, and

+

is the operator.

Operations

Operations can be performed on any combination of value types, but will result in
a null value if the operation is not defined. Defined operations are listed in the
Operand Types column of Table 4.2 on page 12. Any binary operation on a null and
a non-null value will result in the non-null value. For example, if

x = null

then

3 * x

will return a value of 3.

A binary operation is an operation that contains an operand on each side of the
operator, as in the preceding examples. An operation with only one operand is
called a unary operation, and requires the use of a unary operator. An example of a
unary operation is

!1

which uses the logical negation operator. It returns a value of 0.

The unary operators are

sizeof()

,

head()

,

tail()

,

~

and

!

.

Operator Precedence and Associativity

Operator rules of precedence and associativity determine in what order operands are
evaluated in expressions. Expressions with operators of higher precedence are
evaluated first. In the expression

4 + 9 * 5

the

*

operator has the highest precedence, so the multiplication is performed before

the addition. Therefore, the expression evaluates to 49.

Advertising