Arithmetic Operator Precedence

InstallShield 2020 » InstallScript Language Reference

When the InstallScript compiler encounters a complex expression—one that includes two or more simple expressions—it evaluates those expressions one at a time.

Operator Precedence

The order in which expressions are evaluated is determined by operator precedence. The compiler evaluates arithmetic operators using the same order of precedence that the C language uses:

1. Negative ( - ) unary.
2. Multiplication and division.
3. Addition and subtraction.
4. Left to Right Processing

If an expression contains two or more operators with the same precedence level, the operator to the left is processed first. For example, in the expression 15 / 3 * 7, the InstallScript compiler first performs the division (15 / 3), then multiplies the result by 7.

Using Parentheses to Affect Processing

When a lower order precedence operation must be performed first, it should be surrounded by parentheses. For example, if the addition must be performed before the multiplication in the expression 30 / 3 + 7, place parentheses around 3 + 7. The parentheses in the expression 30 / (3 + 7) cause the compiler to add 3 and 7 first, yielding 10, and then divide 30 by 10 for a final result of 3.

Nested Parentheses

You can nest parentheses within an expression. InstallShield allocates 20 temporary locations for calculating nested expressions. Therefore, you can nest 19 levels of operations within parentheses. The InstallShield Script Compiler performs the innermost operation first and works its way outward.

Example Expression

For example, in the expression 36 - (3 * ( 2 + 6 - 4) ), the InstallScript compiler first performs the operation 2 + 6, which yields 8, then subtracts 4 from 8, yielding 4, then multiplies 3 by 4, yielding 12, and finally subtracts 12 from 36, yielding 24.

Note:Within the inner parentheses, InstallShield performed the addition operation first because it was the further left of two operators with equal precedence.

See Also