Expressions - coldrockgames/doc-scriptor GitHub Wiki
Expressions are the foundation of scriptor and any other programming language. TThe ability to evaluate combinations of values and logical operators like And, Or, Xor and Not into boolean expressions(returning true
or false
) is essential for enabling your code to make decisions.
Scriptor includes a precedence engine and supports all common expressions, including the use of parentheses for grouping (brackets {}
).
Scriptor follows standard operator precedence rules, similar to most modern programming languages. The table below outlines the precedence levels, in **descending **order:
Expressions are evaluated in this order:
Rule | Description |
---|---|
++ -- |
Increment/Decrement assigned first |
<< >> |
Bit shift over short assign |
+= -= *= /= %= |
Short assigns over comparison |
== <= >= < > |
Comparison |
& | ^ ! |
Logical assignments (^ = Xor) |
** over */%+-
|
Power is calculated before */%+-
|
* / % over + -
|
Multiplication and Division score higher than Addition and Subtraction (% = modulo) |
|| over &&
|
a && b || c is the same as a && (b || c) and not (a && b) || c
|
( and )
|
The lowest precedence, means, every expression inside brackets is evaluated, before the result of the bracket is known |
As you can see in the table above, expression evaluation is by far the most complex topic of a language parser and the language design itself.
Note
Long story short: Scriptor
should be able to evaluate any combination of the rules. The ability to handle complex expressions seamlessly is one of Scriptor's core strengths.