Operators and other symbols in EGL

The next table lists symbols in the EGL grammar, in order of decreasing precedence.

You may override the usual operator precedence by using parentheses to separate one expression from another. Operations that have the same precedence in an expression are evaluated in left-to-right order.

Symbols Meaning
{ Curly brackets define a set-values block.

The high precedence of the left curly bracket ensures that the clause new Record {} means (new Record) {} rather than (new Record {}).

[ Hard brackets define a list. They also separate an index value from a list name, or a substring value from a value of type string. For example, a[x] is a list subscript and b[x:y] is a substring.

The high precedence of the left hard bracket ensures that the clause new Record [] means (new Record)[] rather than (new Record)[]

. The member access operator (a dot) provides access to members of an entity; for example, fields in records, or functions in libraries. Multiple levels of qualification are permitted. Members become more specific as you move from left to right.
+, - Unary plus (+) or minus (-) is a sign that precedes an operand or parenthesized expression. These are not the binary plus and minus operators.
~ ~ is the bitwise negation operator. It changes 1s to 0s, 0s to 1s. The operator is unary; it affects a single operand, which might be of type smallint, int, or bigint.
You typically assign the result, as in the following code:
   myvar int = ~10;     // bit pattern (4 bytes)
                        // 0000 ... 00001010 --> 
                        // 1111 ... 11110101
   Syslib.writeStdOut(myVar);

The code displays the number -11.

! ! is the not operator, which EGL evaluates to a Boolean value (true or false) opposite to the value of a logical expression that immediately follows. That subsequent expression must be in parentheses.
as The casting operator specifies a type (second operand) for the first operand.
** ** is the exponent operator, which can be read as "to the power of." For example c = a**b means that c is assigned the value of a to the power of b. The first operand (a in the example above) is a FLOAT that cannot have a negative value. The second operand (b in the example above) is a FLOAT literal or variable, positive, negative or 0.
*, / The operators for multiplication and integer division are of equal precedence. Division of integers can result in a fractional value; for example, 7/5 yields 1.4.
% % is the remainder operator. It resolves to the modulus when the first of two operands or numeric expressions is divided by the second. For example, 7%5 yields 2.
+, - Addition (+) and subtraction (-) are binary operations of equal precedence. The plus sign is used to sum numbers and to concatenate strings.
::, ?: EGL uses two operators exclusively for concatenation (:: and ?:).
==, !=, <, >, <=, >=, isa Logical operators for Boolean comparison are of equal precedence; each expression that contains one of these operators evaluates to either true or false.
&, |, xor, <<n, >>n,>>>n Each of these bitwise operators reads an operand to its left and right and returns a value of type int. Either operand may be of type int or smallint. The operation begins by converting any smallint operand to type int.
You typically assign the result, as in the following code:
   myvar = 10 << 2;     // bit pattern (4 bytes)
                        // 0000 ... 00001010 --> 
                        // 0000 ... 00101000
   Syslib.writeStdOut(myVar);

The code displays the number 40.

The meaning of these bitwise operators is as follows:
  • & is an intersection operator. If the bits at a given position in both operands are 1, the result for that position is 1; otherwise, the result is 0.
  • | is a union operator. If the bit at a given position in either operand is 1, the result for that position is 1; if the bits are both 0, the result is 0.
  • xor is an exclusive or. If the bit at a given position in 1 for one operand and 0 for the other, the result for that position is 1; otherwise, the result is 0.
  • << shifts left by n, which is the specified number of positions. The operator retains the sign bit and fills in the right with zeros, as shown in the previous example.
  • >> shifts right by n. The effect in an arithmetic shift. The operator retains the leftmost bit and fills in the left with the value of that bit, for the specified number of positions.
  • >>> shifts right by n. The effect is a logical shift. The operator fills in the left with zeros.

    For a positive number, >>> has the same effect as >>. For a negative number, >>> results in a positive number.

is, not, in These logical operators used for comparison are of equal precedence; each expression that contains one of these operators is evaluated as true or false. See "in operator."
&&, and The && or and operator combines two logical expressions. The resulting expression resolves to true only if both of the component expressions are true; otherwise, the resulting expression resolves to false.
||, or The || or or operator combines two logical expressions. The resulting expression resolves to true if one or both of the component expressions are true; otherwise, the resulting expression resolves to false.
= = is the assignment operator, which copies a value from an expression or operand into an operand. For details on complex assignment operators such as +=, see "Assignment statement."