Category:ALGOL 68

From Rosetta Code
Language
Language
ALGOL 68
This programming language may be used to instruct a computer to perform a task.
Parameter passing methods: By reference, By value
Type safety: Safe
Type strength: Strong
Type compatibility: Structural
Type expression: Explicit
Type checking: Dynamic, Static
Lang tag(s): algol68
See Also:
Listed below are all of the tasks on Rosetta Code which have been solved using ALGOL 68.

ALGOL 68 (short for ALGOrithmic Language 1968) is an imperative computer programming language that was conceived as a successor to the ALGOL 60 programming language, designed with the goal of a much wider scope of application and more rigorously defined syntax and semantics.

The main aims and principles of design of ALGOL 68:

  1. Completeness and clarity of design,
  2. Orthogonal design,
  3. Security,
  4. Efficiency:
    • Static mode checking,
    • Mode-independent parsing,
    • Independent compilation,
    • Loop optimization,
    • Representations - in minimal & larger character sets.



Execute an ALGOL 68 program online

Tasks not implemented in ALGOL 68

Tasks not implemented in ALGOL 68

Grammar

The formal definition of Algol 68 is given by a "Two-Level" or "Van Wijngaarden" grammar. This specifies much more than "just" the syntax and includes such semantic details as the requirement of identifiers to be declared, the necessary type checking and coercions to be applied, etc. The degree of precision allowed by the grammar came at the cost of increased complexity relative to Backus Naur Form, which was used to define ALGOL 60. It is recomended that less formal material (such as the books mentioned under "Resources" below) be consulted before delving into the Revised Report.

A syntax chart is available here

Resources


Books available online:


Editor modes:

Status

  • 20th December 1968 - ALGOL 68's Final Report was ratified by UNESCO's IFIP working group 2.1 in Munich.
  • 20th December 2008 - Zig Zag - the 100th ALGOL 68 code contribution on rosettacode.org!
    • Happy 40th Birthday ALGOL 68,
    • AND 50th Birthday ALGOL 58.
  • 23rd August 2009 - algol68g-1.18.0-9h released
  • 20th December 2009 - Happy 51st/41st Birthdays with Hamming numbers - the 200th ALGOL 68 code contribution on rosettacode.org!
  • 25th October 2011 - Jejones3141 added Soundex - the 300th ALGOL 68 code specimen.

Revisions

  • Mar. 1968: Draft Report on the Algorithmic Language ALGOL 68 - Edited by: A. van Wijngaarden, B.J. Mailloux, J.E.L. Peck and C.H.A. Koster.
  • Oct. 1968: Penultimate Draft Report on the Algorithmic Language ALGOL 68 - Chapters 1-9 - Edited by: A. van Wijngaarden, B.J. Mailloux, J.E.L. Peck and C.H.A. Koster.
  • Dec. 1968: Report on the Algorithmic Language ALGOL 68 - Offprint from Numerische Mathematik, 14, 79-218 (1969); Springer-Verlag. - Edited by: A. van Wijngaarden, B.J. Mailloux, J.E.L. Peck and C.H.A. Koster.
  • Sep 1973: Revised Report on the Algorithmic Language Algol 68 - Springer-Verlag 1976 - Edited by: A. van Wijngaarden, B.J. Mailloux, J.E.L. Peck, C.H.A. Koster, M. Sintzoff, C.H. Lindsey, L.G.L.T. Meertens and R.G. Fisker.

Coding style of samples

Click "Expand" for more details.

Many of the code samples provided here have a leading main:( and a matching ) at the end. These are not actually required in the language, but are included so as to highlight the main routine.

On some compilers, it may be necessary to include appropriate "job cards" or preludes in order for the programs to compile successfully. Hopefully not too much else is required. Examples:

Brief Algol68 Algol68 as in rosettacode Actual ELLA Algol 68RS code
print(("Hello, world!",new line))
main:(
  print(("Hello, world!",new line))
)
PROGRAM helloworld CONTEXT VOID
USE standard
BEGIN
  print(("Hello, world!", new line))
END
FINISH



Examples of different program representations

At the time when ALGOL 68 was defined some predominant computers had 24 or 36 bit words, with 6 bit character sets. Hence it was desirable that ALGOL 68 should be able to run on machines with only uppercase. The official spec provided for different representations of the same program. Quote stropping (enclosing the bold words in single quotes) and Point stropping (preceeding the bold words with a dot) were used. A variant of Point stropping called RES stropping was also defined. In RES stropping some language-defined bold words are not preceded by a dot. A pragmatic comment may have been required to indicate which stropping convention was to be used, as in some of the examples below. Upper stropping (representing the bold words by upper case and non-bold words in lower case) was introduced by Algol 68R. Upper stropping is used by Algol 68RS and is one of the options for Algol 68G. Rutgers ALGOL 68 uses quote stropping. Most of the samples on Rosetta Code use Upper stropping. Examples (pragmatic comments to set the stropping regime not shown):

Algol68 as typically published
mode xint = int;
xint sum sq:=0;
for i while
  sum sq≠70×70
do
  sum sq+:=i↑2
od 
QUOTE stropping (similar to wiki)
'mode' 'xint' = 'int';
'xint' sum sq:=0;
'for' i 'while'
  sum sq≠70×70
'do'
  sum sq+:=i↑2
'od' 
POINT stropping
.MODE .XINT = .INT;
.XINT SUM SQ:=0;
.FOR I .WHILE
  SUM SQ .NE 70*70
.DO
  SUM SQ .PLUSAB I .UP 2
.OD
RES stropping
mode .xint = int;
.xint sum sq:=0;
for i while
  sum sq≠70×70
do
  sum sq+:=i↑2
od 
Upper stropping
MODE XINT = INT;
XINT sum sq:=0;
FOR i WHILE
  sum sq /= 70*70
DO
  sum sq PLUSAB i UP 2
OD

Coercion (casting)

ALGOL 68 has a hierarchy of contexts which determine which kind of coercions are available at a particular point in the program.
Click "Expand" for more details.

These contexts are:

N

a
m
e

Context location Coercions available in this context Coercion examples
Soft Weak Meek Firm Strong
S

t
r
o
n
g

Right hand side of:
  • Identity-declarations, as "~" in:
    REAL x = ~
  • Initialisations, as "~" in:
    REAL x := ~

Also:

  • Actual-parameters of calls, as "~" in:
    PROC: sin(~)
  • Enclosed clauses of casts, as "~" in:
    REAL(~)
  • Units of routine-texts
  • Statements yielding VOID
  • All parts (but one) of a balanced clause
  • One side of an identity relation, as "~" in:
     ~ IS ~
deproc- eduring all soft then weak deref- erencing all weak then deref- erencing all meek then uniting all firm then widening, rowing and voiding

Widening occurs if there is no loss of precision. For example: An INT will be coerced to a REAL, and a REAL will be coerced to a LONG REAL. But not vice-versa. Examples:

INT to LONG INT
INT to REAL
REAL to COMPL
BITS to []BOOL
BYTES to STRING

A variable can also be coerced (rowed) to an array of length 1.

For example:

INT to [1]INT
REAL to [1]REAL
etc
F

i
r
m

  • Operands of formulas as "~" in:
    OP: ~ * ~
  • Parameters of transput calls
Example:
UNION(INT,REAL) var := 1
M

e
e
k

  • Trimscripts (yielding INT)
  • Enquiries: e.g. as "~" in the following
IF ~ THEN ... FI
and
FROM ~ BY ~ TO ~ WHILE ~ DO ... OD etc
  • Primaries of calls (e.g. sin in sin(x))
Examples:
REF REF BOOL to BOOL
REF REF REF INT to INT
W

e
a
k

  • Primaries of slices, as in "~" in:
    ~[1:99]
  • Secondaries of selections, as "~" in:
    value OF ~
Examples:
REF BOOL to REF BOOL
REF REF INT to REF INT
REF REF REF REAL to REF REAL
REF REF REF REF STRUCT to REF STRUCT
S

o
f
t

The LHS of assignments, as "~" in:
~ := ...
Example:
  • deproceduring of:
    PROC REAL random: e.g. random

For more details about Primaries and Secondaries refer to Operator precedence.

See also


Library code used in Rosetta Code samples

Prime related
Row (array) related

Subcategories

This category has the following 3 subcategories, out of 3 total.

Pages in category "ALGOL 68"

The following 200 pages are in this category, out of 999 total.

(previous page) (next page)

C

(previous page) (next page)