*********** Expressions *********** Operator precedence =================== Operator precedence is as follows: +----------+---------------+ | Operator | Associativity | +==========+===============+ | ``!`` | right | | ``~`` | | +----------+---------------+ | ``*`` | left | +----------+---------------+ | ``+`` | left | | ``-`` | | +----------+---------------+ | ``==`` | left | | ``!=`` | | +----------+---------------+ | ``&&`` | left | +----------+---------------+ | ``||`` | left | +----------+---------------+ | ``&`` | left | +----------+---------------+ | ``|`` | left | +----------+---------------+ If there are multiple ways to parse a section of the source code, the precedence rules apply. The operators bind to their arguments in the order they appear in the table. If two operators appear in the same row, they are bound in the order they appear in the source code. Operators not specified in this table cannot be parsed ambiguously. Integer expressions =================== .. productionlist:: expression: `constant` | `identifier` | `binaryop` | `complement` | `call` Constants --------- .. productionlist:: constant: `integer` A constant evaluates to its value. Identifiers ----------- .. productionlist:: identifier: `identifier` Binary operators ---------------- .. productionlist:: binaryop: `expression` ("+" | "-" | "*" | "&" | "|" | "^") `expression` The standard mathematical operators ``+``, ``-`` and ``*`` result in ``left`` (operator) ``right``. ``left & right`` results in the bitwise AND of ``left`` and ``right``. ``left | right`` results in the bitwise OR of ``left`` and ``right``. ``left ^ right`` results in the bitwise XOR of ``left`` and ``right``. Unary operators --------------- .. productionlist:: complement: "~" `expression` ``~expression`` results in the bitwise complement of ``expression``. Function calls -------------- .. productionlist:: call: `identifier` "(" `callargs`? ")" callargs: `datatype` `identifier` ("," `callargs`)? The result of a function call is the return value of that function. ``foo.bar(123, something)`` calls ``foo.bar`` with ``123`` and ``something`` as arguments. Boolean expressions =================== .. productionlist:: boolexpr: `constant_bool` | `readbit` | `comparison` | `logic` | `not` Constants --------- .. productionlist:: constant_bool: "true" | "false" Read bit -------- .. productionlist:: readbit: `expression` "@" `integer` The result of ``expression@4`` is the fourth bit of the value of ``expression``. Comparisons ----------- .. productionlist:: comparison: `expression` (">" | ">=" | "==" | "<=" | "<" | "!=") `expression` Boolean logic ------------- .. productionlist:: logic: `boolexpr` ("&&" | "||" | "==" | "!=") `boolexpr` not: "!" `boolexpr` ``left && right`` results in ``left`` AND ``right``. ``left || right`` results in ``left`` OR ``right``. ``!value`` results in NOT ``value``. .. vim: tw=100