X-Language Docs
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Operators

X supports all standard mathematical operators a language like C has. For a formal understanding of operator precedence, check out the grammar page, but it can be summarised as below. All expressions are left-associative.

    • unary negation and positive (- and +) for integers
    • unary negation (!) for booleans
    • function calls
    • literal values (e.g. true, 12)
    • bracketed expressions
    • modulo %
    • multiplication *
    • division /
    • addition +
    • subtraction -
    • less than, less than or equal < <=
    • greater than, greater than or equal > >=
    • equals ==
    • not equals !=
    • and-logic &&
    • or-logic ||

X supports some shorthand syntax for redeclaring numeric types

fn main() -> void {
    let mut x = 21;
    x += 21; // '+=', '-=', '*=' and '/=' are all supported
}

Note X does not support the postfix and prefix operators ++ and --. This was an intentional choice as such operators are not necessary and can cause confusion.

Pointer Arithmetic

X supports basic pointer arithmetic where a pointer value can be added to or subtracted from. No error checking will happen regarding bounds in pointer arithmetic, so use this feature carefully. An example of pointer arithmetic can be shown below in the str_len method found in the str library.

fn str_len(mut v: i8*) -> i64 {
    let mut s: i8*;
    let mut c = 0;
    for s = v; *s != '\0'; s += 1 {
        c += 1;
    }
    return c;
}