githubEdit

Precedence

OSL evaluates expressions using a fixed operator precedence hierarchy. Operators with higher precedence bind tighter and are evaluated before lower-precedence operators. Operators at the same precedence level are evaluated left-to-right, unless otherwise stated.

Parentheses (...) may always be used to override precedence.

Precedence Table

Level

Operators

Description

1

()

Grouping / explicit precedence override

2

+ - / * ^ % ?? |>

Operators

3

== != < > <= >=

Comparisons

4

bool ? val1 val2

Ternary operator

5

| & >> << >>> ^^ <<<

Bitwise operators

6

and, or, nor, nand, xor, xand

Increment (prefix or postfix, context-dependent)

7

Lambda and inline functions

This table is in order of what gets evaluated first, within these groups its the left most operator that takes precedence.

// Think of:
log 1 + 1 * 4

// As:
log (1 + 1) * 4

Because operators come first in the table, they are evaluated before comparisons and so you can do things like this:

// this logs `false`
log 1 + 1 == 5 * 4

// the code above is functionally equivalent to
log (1 + 1) == (5 * 4)

Last updated