Virgil Language Reference: operators

This reference page contains a complete listing of the operators in the Virgil language and their binding precedence. As operators are added to the language and semantics are refined, they are tracked separately.

Virgil I-01

All operators in Virgil are strict (all operands are evaluated before performing the operation), unless specified otherwise. Order of evaluation for all operators is left to right. The initial version of the Virgil language, version I-01, defines the following set of operators:

Boolean operators

  • and    binary infix (boolean, boolean) -> boolean
    Denotes the logical and operation on booleans. Lazy: in the expression A and B, the expression B is only evaluated if A evaluates to true.
  • or    binary infix (boolean, boolean) -> boolean
    Denotes the logical or operation on booleans. Lazy: in the expression A or B, the expression B is only evaluated if A evaluates to false.
  • !    unary prefix (boolean) -> boolean
    Denotes the logical not operation on booleans.

Integer operators

  • +    binary infix (int, int) -> int
    Denotes the integer addition operation on integers. Overflow or underflow semantics are dictated by standard 32-bit two's complement arithmetic.
  • -    binary infix (int, int) -> int
    Denotes the integer subtraction operation on integers. Overflow or underflow semantics are dictated by standard 32-bit two's complement arithmetic.
  • *    binary infix (int, int) -> int
    Denotes the integer multiplication operation on integers. Overflow or underflow semantics are dictated by standard 32-bit two's complement arithmetic.
  • /    binary infix (int, int) -> int
    Denotes the integer division operation on integers. Overflow or underflow semantics are dictated by standard 32-bit two's complement arithmetic. Generates a DivideByZeroException if the second operand has integer value 0.
  • <    binary infix (int, int) -> boolean
    Denotes the integer less than comparison operation on integers.
  • <=    binary infix (int, int) -> boolean
    Denotes the integer less than or equal comparison operation on integers.
  • >    binary infix (int, int) -> boolean
    Denotes the integer greater than comparison operation on integers.
  • >=    binary infix (int, int) -> boolean
    Denotes the integer greater than comparison operation on integers.
  • -    unary prefix (int) -> int
    Denotes the integer complement operation on integers. Semantics are defined by standard 32-bit two's complement operation.

Character operators

  • <    binary infix (char, char) -> boolean
    Denotes the character less than comparison operation on characters.
  • <=    binary infix (char, char) -> boolean
    Denotes the character less than or equal comparison operation on integers.
  • >    binary infix (char, char) -> boolean
    Denotes the character greater than comparison operation on characters.
  • >=    binary infix (char, char) -> boolean
    Denotes the character greater than comparison operation on characters.

Type operators

  • instanceof T    polymorphic unary postfix (X) -> boolean
    Denotes the dynamic type query (instanceof) operation on objects. Retrieves the dynamic type of object, D and tests whether D is a subtype of the specified type T.
  • <: T    polymorphic unary postfix (X) -> boolean
    Equivalent to instanceof T.
  • :: T    polymorphic unary postfix (X) -> T (with T subclass of X)
    Denotes the dynamic type cast (cast) operation on objects. Retrieves the dynamic type of object, D and tests whether D is a subtype of the specified type T. Generates a TypeCheckException if the test fails.
  • :: T    polymorphic unary postfix (X) -> T (with X convertible to T)
    Denotes the explicit value conversion (convert) operation on value types such as int. See language specification for details on legal conversions.

Comparison operators

  • ==    polymorphic binary infix (X, Y) -> boolean (with X and Y comparable)
    Denotes the value equality operation on values. For details on legal value comparisons, see the language specification.
  • !=    polymorphic binary infix (X, Y) -> boolean (with X and Y comparable)
    Denotes the value inequality operation on values. For details on legal value comparisons, see the language specification.

Raw operators

  • &    binary infix (m, n) -> min(m, n) (with m and n raw)
    Denotes the bitwise and operation on raw values.
  • |    binary infix (m, n) -> max(m, n) (with m and n raw)
    Denotes the bitwise or operation on raw values.
  • ^    binary infix (m, n) -> max(m, n) (with m and n raw)
    Denotes the bitwise exclusive-or operation on raw values.
  • <<    binary infix (m, int) -> m (with m raw)
    Denotes the shift left operation within a window of m bits on raw values.
  • >>    binary infix (m, int) -> m (with m raw)
    Denotes the shift right operation within a window of m bits on raw values.
  • #    binary infix (m, n) -> m+n (with m and n raw)
    Denotes the bitwise concatentation operation on raw values.
  • []    e[e]    (m, int) -> 1 (with m raw)
    Denotes the bit access operation, which retrieves a single bit from the specified value. If the index is out of bounds, this operation will return the raw value 0 without generating an exception.