ZetCode

Algol 68 literals

last modified November 13, 2026

A literal is a value written directly in the source text. Algol 68 calls its literals denotations and provides one for each primitive kind of value: integers, reals, booleans, characters, strings, and bit patterns. This article describes those forms, the special denotations NIL and SKIP, and the precision prefixes that change a mode.

Integer denotations

An integer denotation is a run of decimal digits. A minus sign in front of it belongs to the monadic minus operator, so -5 is a formula and not a single denotation. Digits are never grouped: neither underscores nor commas may appear inside a number.

integers.a68
BEGIN
  INT a = 42, b = 1000000;
  LONG INT c = 1234567890123;
  print((whole(a, 0), " ", whole(b, 0), newline));
  print((whole(c, 0), newline))
END

The first two names use the default integer width. The third is declared LONG INT, because a number of this size does not fit in an INT. When the same value is declared as INT, Genie accepts the program but stores a truncated number. The whole procedure converts an integer to a string without the padding that print applies to numbers.

$ a68g integers.a68
42 1000000
1234567890123

Real denotations

A real denotation contains a decimal point or an exponent. The digits before the point may be omitted, as in .5, but digits after the point are required, so 1. is not a valid denotation. The exponent letter may be lower-case e or upper-case E, and the exponent itself may carry a sign.

reals.a68
BEGIN
  REAL a = 3.5, b = .5, c = 1.5e3, d = 2.5e-2;
  print((fixed(a, 0, 1), " ", fixed(b, 0, 1), newline));
  print((fixed(c, 0, 1), " ", fixed(d, 0, 3), newline))
END

The exponent shifts the decimal point: 1.5e3 is 1500 and 2.5e-2 is 0.025. The fixed procedure takes the minimum field width as its second argument and the number of decimals as its third. A width of 0 keeps the string as short as possible, which is why the last value is printed as .025 without a leading zero.

$ a68g reals.a68
3.5 .5
1500.0 .025

Boolean and character denotations

TRUE and FALSE are the two boolean denotations. A character denotation is a one-character string in double quotes, and a double quote inside it is written twice. There are no backslash escapes, so control characters are produced from their numeric codes with REPR.

chars.a68
BEGIN
  CHAR letter = "A", quote = """", tab = REPR 9;
  print((letter, quote, newline));
  print((whole(ABS letter, 0), " ", whole(ABS tab, 0), newline))
END

The four double quotes in """" are an opening quote, a doubled quote, and a closing quote, so the value is a single quotation mark. The monadic operator ABS converts a character to its integer code, which is 65 for A and 9 for a tab.

$ a68g chars.a68
A"
65 9

String denotations

A string denotation is a sequence of characters in double quotes. An embedded quote is doubled, exactly as in a character denotation, and the empty string is allowed. Strings are rows of characters, so LWB and UPB return their bounds.

strings.a68
BEGIN
  STRING s = "say ""hi""", empty = "";
  print((s, newline));
  print((whole(UPB s, 0), " ", whole(UPB empty, 0), " ", whole(LWB empty, 0), newline))
END

The first string has eight characters, so its upper bound is 8. The empty string has lower bound 1 and upper bound 0. That pair of bounds is the standard way to describe a row with no elements, and it is worth remembering when a loop is written as FOR i TO UPB row DO, which runs zero times for an empty row.

$ a68g strings.a68
say "hi"
8 0 1

Based denotations

A based denotation writes a number in another base with the syntax base r digits. The result has mode BITS, not INT, so it can be shifted and masked, and ABS converts it to an integer. In res stropping the digits must be written in lower case, because an upper-case letter starts a new token.

based.a68
BEGIN
  BITS binary = 2r1010, octal = 8r17, hex = 16rff;
  print((whole(ABS binary, 0), " ", whole(ABS octal, 0), " ", whole(ABS hex, 0), newline))
END

The three denotations have the values 10, 15, and 255. Writing 16rFF instead of 16rff is a syntax error, and passing the BITS value straight to whole fails because whole expects an integer. The ABS conversion is what makes the value printable as a number.

$ a68g based.a68
10 15 255

Special values

NIL is the value of a reference that designates nothing, and SKIP is the empty unit, useful as a branch that does nothing. There is no denotation for an empty row; it is declared with explicit bounds, as in [1:0] INT. Genie rejects EMPTY in that position.

special.a68
BEGIN
  REF INT p = NIL;
  [1:0] INT empty row;
  print((p IS NIL, newline));
  print((whole(UPB empty row, 0), " ", whole(LWB empty row, 0), newline));
  SKIP;
  print(("after skip", newline))
END

The identity operator IS tests whether two references designate the same value, and NIL is the value that designates nothing, so the first test prints T. The empty row again has bounds 1 and 0, and SKIP passes control to the next statement.

$ a68g special.a68
T
0 1
after skip

Precision prefixes

LONG and SHORT are part of a mode name, so LONG REAL and LONG INT are modes in their own right. A value of a narrower mode is widened automatically when it is assigned to a wider one; the reverse conversion is not automatic.

precision.a68
BEGIN
  LONG REAL lr = 2.5;
  print((fixed(lr, 0, 2), newline));
  REAL r = 1.5;
  print((fixed(r, 0, 2), newline))
END

Both values print with two decimals. The reverse declarations, such as REAL r = lr; or INT i = big; after a LONG INT big, are rejected: narrowing must be written explicitly, which keeps loss of precision visible in the source. The limits of each mode depend on the implementation, which is why a value whose range matters is given the widest mode that the program needs.

$ a68g precision.a68
2.50
1.50

Next steps

The operators article shows what can be done with these values, and the coercions article explains the widening rules in detail. The modes article gives an overview of all modes, and Algol 68 basics puts the denotations to work in complete programs.

Source

Revised Report on the Algorithmic Language Algol 68

The Algol 68 Genie project

In this article we have written integers, reals, booleans, characters, strings, and bit patterns as denotations, used the special values NIL and SKIP, and adjusted the precision of a mode with LONG and SHORT. The operators article continues with the formulas these values take part in.

Author

My name is Jan Bodnar, and I am a passionate programmer with extensive programming experience. I have been writing programming articles since 2007. To date, I have authored over 1,400 articles and 8 e-books. I possess more than ten years of experience in teaching programming.

List all Algol 68 tutorials.