Matchbox 0.2

Operators

Matchbox 0.2 operators work on signed 32-bit integers.

Arithmetic

Form Operation
a + b Addition
a - b Subtraction
a * b Multiplication
a / b Division
a // b Integer division
a % b Remainder
a ** b Exponentiation

Division truncates toward zero. The remainder has the sign of the left operand, so -7 / 3 is -2 and -7 % 3 is -1.

The exponent should be non-negative and its result must fit in int. Division or remainder by zero and arithmetic overflow are not defined by the language.

Arithmetic Assignment

Form Equivalent Form
a += b a = a + b
a -= b a = a - b
a *= b a = a * b
a /= b a = a / b
a //= b a = a // b
a %= b a = a % b
a **= b a = a ** b

Bitwise

Form Operation
a & b Bitwise AND
a | b Bitwise OR
a ^ b Bitwise XOR
a << b Left shift
a >> b Right shift
~a Bitwise complement

A shift count must be between 0 and 31. Left-shifting a negative value or producing a value outside the int range is not defined. Right shift follows the behavior of the compiler used to build Matchbox; portable programs should avoid right-shifting negative values.

Bitwise compound assignments such as &= and shift assignments such as <<= are not supported in 0.2. The compiler rejects them with an Unsupported operator diagnostic.

Unary

Form Operation
-a Negation
!a Logical NOT: 1 when a is zero, otherwise 0
~a Bitwise complement

Precedence

The following table lists operators in order of precedence, from highest to lowest, indicating the order in which expressions are evaluated.

Associativity Operator Description
N/A () Group
N/A -, !, ~ Prefix
Left ** Exponent
Left *, /, //, % Factor
Left +, - Term
Left <<, >> Shift
Left & Bitwise AND
Left ^ Bitwise XOR
Left | Bitwise OR
Right =, +=, -=, *=, /=, //=, %=, **= Assignment

Assignment operators are statement forms rather than value-producing expressions, so they cannot be chained or nested inside another expression. Use parentheses whenever the intended grouping would otherwise be unclear.

Recognized but Unsupported Forms

The 0.2 lexer recognizes comparison, equality, and logical tokens such as <, ==, &&, and ||. The compiler rejects these forms with an Unsupported operator diagnostic rather than emitting bytecode.