Hierarchy of operators, Arithmetic operators, Hierarchy of operators -3 arithmetic operators -3 – Rockwell Automation 1746-BAS BASIC LANGUAGE User Manual

Page 25: Add ( + )

Advertising
background image

Publication 1746-RM001A-US-P

Expressions and Operators 3-3

Hierarchy of Operators

The hierarchy of operators is the order that the operations in an expression are
performed. You can write complex expressions using only a small number of
parentheses. To illustrate the hierarchy of operators, examine the following
equation:

4+3*2 = ?

In this equation, multiplication has precedence over addition. Therefore, multiply
(3*2) and then add 4.

4+3*2 = 10

When an expression is scanned from left to right, an operation is not performed
until an operator of lower or equal precedence is encountered. In the example, you
cannot perform addition until the multiplication operation is complete because
multiplication has a higher precedence. Use parentheses if you are in doubt about
the order of precedence or to enhance program readability. The precedence of
operators from highest to lowest in the module is:

1.

1.

1.

1. Operators that use parentheses ( )

2.

2.

2.

2. Exponentiation (**)

3.

3.

3.

3. Negation (-)

4.

4.

4.

4. Multiplication (*) and division (/)

5.

5.

5.

5. Addition (+) and subtraction (-)

6.

6.

6.

6. Relational expressions (-, <>, >, >=, <, <-).

7.

7.

7.

7. Logical AND (.AND.)

8.

8.

8.

8. Logical OR (.OR.)

9.

9.

9.

9. Logical XOR (.XOR.)

Arithmetic Operators

The module contains a complete set of arithmetic operators that are divided into
two groups: dual-operand operators and single-operand operators.

The general form of all dual-operand instructions is:

(expr) OP (expr), where OP is one of the following arithmetic operators

Add ( + )

Use the Addition operator to add the first and the second expressions together.

Example

Result

>PRINT 3+2

5

Advertising