|
| 1 | +# Operator Precedence in LiveCode builder |
| 2 | +Copyright © LiveCode Ltd. |
| 3 | + |
| 4 | +## Introduction |
| 5 | + |
| 6 | +The Builder standard library provides a large variety of syntax definitions. |
| 7 | +Syntax operators can be combined in a huge number of ways, and it's important |
| 8 | +that the interaction is sensible and consistent. |
| 9 | + |
| 10 | +Choosing appropriate precedence levels fulfils some important objectives: |
| 11 | + |
| 12 | +- The ordering of precedence is consistent with LiveCode Script |
| 13 | +- Complicated expressions can easily be written without needing many |
| 14 | + parentheses `(…)` |
| 15 | +- The ordering of precedence is reasonably consistent with other programming |
| 16 | + languages |
| 17 | + |
| 18 | +The precedence levels are named. This makes it much clearer, when reading an |
| 19 | +operator syntax definition, why its assigned precedence level is appropriate. |
| 20 | + |
| 21 | +Multiple named precedence levels may share the same numeric priority. |
| 22 | + |
| 23 | +## Precedence levels |
| 24 | + |
| 25 | +Lower precedence numbers are more tightly-binding. |
| 26 | + |
| 27 | +| Level | Name | Examples | |
| 28 | +|-------|-------------------|-------------------------------| |
| 29 | +| 1 | scope resolution | `.` | |
| 30 | +| 2 | function call | `MyHandler()` | |
| 31 | +| | subscript | `tList[1]`, `tArray["key"]` | |
| 32 | +| 3 | property | `the paint of this canvas` | |
| 33 | +| | subscript chunk | `char 2 of tString` | |
| 34 | +| | function chunk | `the length of tList` | |
| 35 | +| | constructor chunk | `rectangle tList` | |
| 36 | +| 4 | conversion | `tString parsed as number` | |
| 37 | +| 5 | modifier | `-tNum`, `bitwise not` | |
| 38 | +| 6 | exponentiation | `^` | |
| 39 | +| 7 | multiplication | `/`,`*`,`mod`, `div` | |
| 40 | +| 8 | addition | `+`, `-` | |
| 41 | +| | concatenation | `&`, `&&` | |
| 42 | +| 9 | bitwise shift | `1 shifted left by 3 bitwise` | |
| 43 | +| 10 | bitwise and | `7 bitwise and 1` | |
| 44 | +| 11 | bitwise xor | `7 bitwise xor 5` | |
| 45 | +| 12 | bitwise or | `2 bitwise or 4` | |
| 46 | +| 13 | comparison | `<=`, `<`, `is` | |
| 47 | +| | classification | `is a` | |
| 48 | +| 14 | logical not | `not tBoolean` | |
| 49 | +| 15 | logical and | `Foo() and Bar()` | |
| 50 | +| 16 | logical or | `Foo() or Bar()` | |
| 51 | +| 17 | sequence | `,` | |
0 commit comments