The Wayback Machine - https://web.archive.org/web/20080109161728/http://www.xs4all.nl:80/~jmvdveer/syntax.html#coercions
Documentation for Algol 68 Genie Mark 11

Context-free syntax summary

 · Notions and notation
 · Reserved symbols
 · Coercions
 · Tags
 · Particular program
 · Clauses
 · Expressions
  · Primaries
  · Secondaries
  · Tertiaries
  · Units
 · Declarations
 · Declarers
 · Formats
 · Pragments
 · Refinements

Algol68G Mark 11

 · Contents

 · Introduction
 · Installation
 · Description
 · Example programs
 · Synopsis
 · Syntax

 · A68 Resources
 · Downloads
 · Contact

This syntax summary provides a quick reference for Algol68G syntax. Predefined tags can be found in a different chapter. There is a separate chapter with sample programs.

The syntax described here is context-free. The advantage of presenting a context-free syntax is that the backbone of constructions can be explained quickly. The disadvantage is that a context-free grammar cannot reject programs that are semantically incorrect, for instance those that apply undeclared tags. The two-level Algol 68 syntax is described in the Revised Report.

Notions and notation

This paragraph introduces notions and notation used in this reference text.

Notion, notationMeaning
a value
  • integer number or real number
  • truth value (TRUE or FALSE)
  • character
  • void value (EMPTY)
  • structured value, f.i. a COMPLEX number
  • multiple value, a n-dimensional row of values, f.i. a STRING value
  • name
  • routine

    (note that there is neither a united value nor a flexible value, id est there is no value with mode UNION or FLEX)
  • a namea name is a value that refers to another value, or which can be NIL (that refers to no value)
    ( )used to group notions
    [SOME]means "optional SOME"
    a: b.means "definition of a is b"
    a, bmeans "a or b"
    `SOME'means literal symbol SOME
    SOME-listSOME [`,' SOME-list]
    SOME-sequenceSOME [SOME-sequence]

    Reserved symbols

    Next symbols are reserved in Algol 68 Genie Mark 11:

    ANDF, ANDTH, ASSERT, ASSIGN, AT, BEGIN, BITS, COMMENT, PRAGMAT, BOOL, BY, BYTES, CASE, CHANNEL, CHAR, CODE, COL, COMPLEX, COMPL, DIAG, DO, DOWNTO, EDOC, ELIF, ELSE, ELSF, EMPTY, END, ENVIRON, ESAC, EXIT, FALSE, FILE, FI, FLEX, FORMAT, FOR, FROM, GO, GOTO, HEAP, IF, IN, INT, ISNT, IS, LOC, LONG, MODE, NIL, OD, OF, OP, OREL, ORF, OUSE, OUT, PAR, PIPE, PRIO, PROC, REAL, REF, ROW, SEMA, SHORT, SKIP, SOUND, STRING, STRUCT, THEF, THEN, TO, TRNSP, TRUE, UNION, UNTIL, VOID, WHILE

    Coercions

    The "strength" of a context determines what coercions are possible in that context. A "strong" context allows all coercions, and typically requires that the resulting mode is known a priori; for example in the case of initial values assigned in a declaration or parameters in procedure calls.

    Context strength Allowed coercions
    soft deproceduring
    weak dereferencing or deproceduring, yielding a name
    meek dereferencing or deproceduring
    firm meek, followed by uniting
    strong firm, followed by widening, rowing or voiding

    In a strong context, Algol68G implements next widenings:

    FromTo
    INT REAL
    LONG INT
    LONG INT LONG LONG INT
    LONG LONG REAL
    LONG LONG INT LONG LONG REAL
    REAL COMPLEX
    LONG REAL
    LONG REAL LONG LONG REAL
    LONG COMPLEX
    LONG LONG REAL LONG LONG COMPLEX
    COMPLEX LONG COMPLEX
    LONG COMPLEX LONG LONG COMPLEX
    BITS LONG BITS
    LONG BITS LONG LONG BITS
    BITS
    LONG BITS
    LONG LONG BITS
    [ ] BOOL
    BYTES
    LONG BYTES
    [ ] CHAR

    Tags

    Declarer-identifier tags, identifier tags and label tags

    Operator tags

    To avoid ambiguity in parsing operator tag sequences, operator characters are divided into monads and nomads, the latter group being inherently dyadic. Next rules force that for instance 1++-1 can only mean 1 `+' `+' `-' 2, and 1+>2 can only mean 1 `+>' 2.

    Note that Algol 68 forbids operator tags that start with a double monad, such as `++' or `&&', though dyadic operator tags starting with a double nomad (`**', `>>', etcetera) are allowed.


    Particular program

    A particular program is the actual application, embedded in the standard environ.


    Clauses

    Serial - and enquiry clauses describe how declarations and units ("statements") are put in sequence. Algol 68 requires clauses to yield a value. As declarations yield no value, serial- and enquiry-clauses cannot end in a declaration.

    EXIT leaves a serial-clause, yielding the value of the preceeding unit. If the unit following EXIT would not be labeled, it could never be reached. Hence Revised Report syntax for the serial-clause is more elaborate than presented here to require that the unit following EXIT is labeled. In a serial-clause there cannot be labeled units before declarations to prevent re-entering declarations once they have been executed.

    An enquiry-clause provides a value to direct the conditional-clause, integer-case-clause, united-case-clause or while-part in a loop-clause. An enquiry-clause has no labels, so you cannot for instance jump back to the enquiry-clause at IF from the serial-clause at THEN.

    Enclosed clauses provide structure for a particular program.


    Expressions

    Expressions are orthogonal, for instance an enclosed-clause can be an operand in a formula. The constituent constructs of expressions are primaries, secondaries, tertiaries and units.

    Primaries


    Secondaries


    Tertiaries


    Units


    Declarations

    Declarations introduce definitions of tags. Algol 68 does not require that a tag is defined before it is used (although Algol 68 does require that a tag is assigned a value before it is used). Hence there is no need for forward declarations when defining mutually recursive procedures, or recursive modes.


    Declarers

    Declarers describe modes. The context determines whether a mode must be formal, virtual, or actual. Formal- or virtual-declarers are needed where the size of rows is irrelevant. Actual declarers are needed where the size of rows must be known, for instance when allocating memory for rows.

    Algol 68 employs structural equivalence for modes. Note that field identifiers in structured values are part of the mode, but bounds of a row are not (these are part of the value). For example:


    Formats

    Formats describe the lay-out for transputting data. Formats are values so you can have format-variables, procedures yielding formats etcetera. A format-text can be considered as a (dynamic) "format-denotation".


    Pragments

    Pragments are either pragmats or comments. Pragmats contain preprocessor directives, or set options from within an Algol 68 program.


    Refinements

    The refinement preprocessor is a low-level tool for top-down programming. It is not really a part of Algol68G syntax, but superimposed on top of it. Note that refinements interfere somewhat with labels.


    Copyright © 2001-2007 J. Marcel van der Veer.
    Algol 68 Genie Mark 11 (November 2007)