Algol 68 operators and priorities
last modified November 13, 2026
Algol 68 has no statement grammar separate from expressions: operators build formulas, and formulas are units like any other. An operator is either monadic, with one operand, or dyadic, with two. This article describes the predeclared operators, the nine priorities that decide evaluation order, and the way a program declares operators of its own.
Monadic operators
A monadic operator stands in front of its operand and has priority 9, the
highest one. The predeclared monadic operators include minus, NOT
for booleans, ABS for a magnitude, ENTIER and
ROUND for rounding, SIGN, ODD,
REPR, LWB, and UPB.
BEGIN REAL r = -3.7; print((whole(ABS -5, 0), " ", whole(ENTIER r, 0), " ", whole(ROUND r, 0), newline)); print((whole(SIGN -5, 0), " ", ODD 7, " ", NOT FALSE, newline)); print((REPR 65, " ", whole(ABS "A", 0), newline)) END
ENTIER returns the largest integer not greater than its operand,
so -3.7 becomes -4; ROUND rounds to the
nearest integer and produces the same result here. SIGN returns
-1, 0, or 1. REPR turns an integer code into a character, while
ABS applied to a character does the opposite.
$ a68g monadic.a68 5 -4 -4 -1 T T A 65
Priorities
Every dyadic operator has a priority from 1 to 9. A formula is read as a sequence of operands joined by operators, and an operator of higher priority binds its neighbours first. Operators of equal priority are applied from left to right. The predeclared priorities are:
| Priority | Operators |
|---|---|
| 9 | monadic operators: -, NOT, ABS, ENTIER, ROUND, SIGN, ODD, REPR, LWB, UPB |
| 8 | ** |
| 7 | *, /, OVER, MOD, % |
| 6 | +, - |
| 5 | <, <=, >=, > |
| 4 | =, /= |
| 3 | AND, & |
| 2 | OR |
| 1 | :=, +:=, -:=, *:=, /:= |
The table explains why 1 + 2 = 3 is a comparison of a sum with 3
rather than a sum of a comparison and 3: addition has a higher priority than
equality. Assignment has the lowest priority, so everything on the right of
:= is computed first.
BEGIN print((whole(2 + 3 * 4, 0), newline)); print((whole(2 ** 3 ** 2, 0), newline)); print((whole(- 2 ** 2, 0), newline)); print((1 + 2 = 3, newline)); print((TRUE OR FALSE AND FALSE, newline)); print((whole(10 - 2 - 3, 0), newline)) END
The first line is 14 because multiplication binds tighter than addition. The
second line shows that two operators of the same priority are applied from
left to right, so 2 ** 3 ** 2 is (2 ** 3) ** 2 and
not 2 ** (3 ** 2). Monadic minus has priority 9, so
- 2 ** 2 means (-2) ** 2. The boolean line is true
because AND binds tighter than OR.
$ a68g priorities.a68 14 64 4 T T 5
Arithmetic operators
The arithmetic operators are +, -, *,
/, OVER, MOD, and **. On
integers, OVER is integer division and MOD returns
the remainder. The operator / always produces a real, even when
both operands are integers, and ** raises a value to a power.
BEGIN print((whole(7 OVER 2, 0), " ", whole(7 MOD 2, 0), newline)); print((fixed(7 / 2, 0, 2), newline)); print((whole(8 OVER 3, 0), " ", whole(8 MOD 3, 0), newline)) END
Seven divided by two leaves a quotient of 3 and a remainder of 1. The same
division written with / yields the real 3.5, which
fixed prints with two decimals. The last line shows that
OVER discards the remainder and leaves it to MOD.
$ a68g division.a68 3 1 3.50 2 2
Comparison operators
The comparison operators are =, /=,
<, <=, >, and
>=. They are defined for numbers, characters, strings, and
other ordered modes, and they return a boolean. The negated equality operator
is written /=, not !=.
BEGIN
print((3 = 3, " ", 3 /= 4, " ", 3 < 4, " ", 3 <= 3, newline));
print((3 > 4, " ", 3 >= 3, newline));
print(("abc" < "abd", newline))
END
The first line prints four true comparisons. The second line prints the two
remaining operators, one false and one true. Strings are compared character
by character, so "abc" is less than "abd" because
c precedes d.
$ a68g comparison.a68 T T T T F T T
Boolean operators
AND, OR, XOR, and the monadic
NOT combine boolean values. & is a short
spelling of AND. The operators do not short-circuit: both
operands are elaborated before the result is computed.
BEGIN print((TRUE AND FALSE, " ", TRUE OR FALSE, " ", TRUE XOR TRUE, newline)); print((NOT TRUE, " ", ODD 3 AND TRUE, newline)) END
AND is true only when both operands are true, OR is
true when at least one is, and XOR is true when exactly one is.
The last line combines a test with a boolean value. Because both operands are
always evaluated, a test that must not run can be guarded with a nested
IF, as the conditionals
article shows.
$ a68g booleans.a68 F T F F T
Declaring an operator
A program declares a dyadic operator with OP, giving its
operands and result. The declaration must be preceded by a PRIO
declaration that assigns the new operator a priority between 1 and 9.
PRIO LOW = 6; OP LOW = (REAL a, REAL b) REAL: (a + b) / 2.0; PRIO HIGH = 7; OP HIGH = (REAL a, REAL b) REAL: (a + b) / 2.0; BEGIN print((fixed(1.0 + 3.0 LOW 2.0, 0, 1), newline)); print((fixed(1.0 + 3.0 HIGH 2.0, 0, 1), newline)) END
Both operators compute the same average, and only their priorities differ.
LOW shares priority 6 with +, so the operators are
applied from left to right: 1 and 3 are added, and the average of 4 and 2 is
3. HIGH has priority 7, so it binds its neighbours before the
addition: the average of 3 and 2 is 2.5, and 1 plus 2.5 gives 3.5. The
priority belongs to the operator tag, which is why PRIO precedes
the OP declaration.
$ a68g opdecl.a68 3.0 3.5
Declaring a monadic operator
A monadic operator needs no PRIO declaration, because every
monadic operator has priority 9. It is declared with a single parameter and
called by writing the operator before its operand.
OP DOUBLE = (INT n) INT: 2 * n; BEGIN print((whole(DOUBLE 5, 0), newline)); print((whole(DOUBLE 5 + 1, 0), newline)) END
DOUBLE 5 is an ordinary formula whose operator happens to be
declared by the program. Because the priority is 9, the operator applies to
the operand that follows it, so DOUBLE 5 + 1 means
(DOUBLE 5) + 1 and prints 11. Write
DOUBLE (5 + 1) to double the sum instead; parentheses keep such
formulas readable.
$ a68g monadicop.a68 10 11
Next steps
The coercions article explains how operands of different modes are brought together, and the literals article describes the values that operators work on. Conditionals uses the boolean operators in complete programs, while program structure shows where formulas fit among the other units.
Source
Revised Report on the Algorithmic Language Algol 68
In this article we have used the monadic operators, read formulas with the
priority table, applied arithmetic, comparison, and boolean operators, and
declared new operators with OP and PRIO. The
coercions article continues with the way
operands of different modes meet.
Author
List all Algol 68 tutorials.