Expressions contain literals or other such expressions of objects, including arithmetic and various conditions.
- Constant Expressions
- Primary Expressions
- Postfix Expressions
- Unary Expressions
- Binary Expressions
- Ternary Expressions
Constant expressions are expressions that do not contain mutation of state or function calls. We define them simply as expressions.
Primary expressions can be one of:
- An identifier for a constant or variable.
superkeyword, which references the parent type.
- Any literal.
- A vector literal.
- An expression in parentheses.
Vector literals are not under object literals as they are not constants in the same manner as other literals, since they contain expressions within them. As such, they are expressions, not proper value-based literals.
vector3 may be made by either grammar. In the former
grammar, the first expression (
X1) must be a
vector2 and the
X2) must be a
double. It will be equivalent to
(X1.X, X1.Y, X2). In any other case, all expressions must be
Much like vector literals, color literals are not "real" literals,
since they contain expressions. Color literals may be either RGB
(where alpha is implied to be maximum) or RGBA. The three (or four)
expressions must be
Postfix expressions are affixed at the end of an expression, and are used for a large variety of things, although the actual amount of postfix expressions is small.
The postfix expressions are:
- Function call.
- Type cast.
- Class type reference cast.
- Array access.
- Member access.
- Post-increment, which increments the object after the expression is evaluated.
- Post-decrement, which decrements the object after the expression is evaluated.
Function calls may name arguments which have defaults, possibly skipping over other defaulted arguments. After the first named defaultable argument, all other arguments must be named as well.
Unary expressions are affixed at the beginning of an expression. The
simplest example of a unary expression is the negation operator,
The unary expressions are:
- Logical negation.
- Pre-increment, which increments the object before the expression is evaluated.
- Pre-decrement, which decrements the object before the expression is evaluated.
- Bit-wise negation. Flips all bits in an integer.
- Affirmation. Doesn't actually do anything.
- Alignment of a type of an expression.
- Size of a type of an expression.
Binary expressions operate on two expressions, and are the most common
kind of expression. They are used inline like regular math syntax,
1 + 1.
The arithmetic expressions are:
- Division quotient.
- Division remainder, also known as "modulus." Unlike C, this works on floats, too.
- Left bit-wise shift.
- Right bit-wise shift.
- Right unsigned bit-wise shift.
The vector expressions are:
- Vector cross-product.
- Vector dot-product.
Concatenation creates a string from two expressions.
The following basic types may be cast to strings through concatenation:
- StringLikeReferenceType except
The comparison expressions are:
- Less than.
- Greater than.
- Less than or equal.
- Greater than or equal.
- Approximate equality. For strings, this is a case-insensitive comparison. For floats and vectors, this checks if the difference between the two expressions is smaller than ε.
Lazy boolean expressions evaluate the left and right hand side expressions separately.
The first, logical and, will only evaluate the right hand side if the
left hand side is
true, and will evaluate to
true if both
The second, logical or, will only evaluate the right hand side if the
left hand side is
false, and will evaluate to
true if either
Logical type equality. Will check if the type of the left hand side is equal to or a descendant of the right hand side.
Signed difference. Will return
-1 if the left hand side is lesser
than the right hand side,
0 if they are equal, and
1 if the left
hand side is greater than the right hand side.
The logical expressions are:
- Bit-wise and.
- Bit-wise exclusive or.
- Bit-wise or.
Not implemented. Will simply cause a compiler error.
Assignment expressions are a subset of binary expressions which are never constant expressions. They assign a value to another value.
Besides the normal assignment operation, there are assignment operations for assigning the result of arithmetic expressions and logical expressions.
The ternary expression will evaluate to the left hand side if the
true, or the right hand side if it is