November 2001

Version 0.0.1: pre-alpha release


Recent Algol 68 Genie revisions are here

Table of contents

Algol 68 for GNU/Linux

ALGOL68G implements an extended subset of the language described in the Revised Report. ALGOL68G is an interpreter that offers many runtime checks, in this sense ALGOL68G bears resemblance to FLACC. ALGOL68G is intended for small to medium sized algorithms, solving not too complex problems.

Description of the implementation

ALGOL68G actually is a Mailloux-type implementation. A hand coded parser makes several passes resolving the program text hence tags can be applied before they are declared, etcetera. This type of implementation also produces few spurious errors while parsing since ALGOL68G only allows a pass to start when the preceeding ones terminated succesfully.

About this Algol 68 implementation

Deviations from the Revised Report

Memory model

ALGOL68G's interpreter emulates a stack machine with a heap. Two stacks are used, one to evaluate expressions, and one to stack call frames. Heap management in Algol 68 is implicit; when the heap is full, a garbage collector will compact it. This requires pointers in the heap to be actually handles, as to allow the garbage collector to shift data in the heap.

The stacks and the heap - and handle pool are separate blocks with presetable size. The reason for memory being set up this way is that fixed-size blocks prevent ALGOL68G from allocating all memory available to it before the garbage collector is called, which would impede overall system performance.

The sizes of the four blocks can be controlled using options, and are specified as the number of 1 kB blocks. Current default values are expression stack 512, frame stack 512, handle pool 1024 and heap 4096.

Execution speed

It is difficult to determine at forehand at what speed the interpreter will run on a certain platform. To have an idea however, ALGOL68G is rated with the Whetstone benchmark and currently peaks at 3.3 MWhets on a 100 MWhets G3 PowerPC (233 MHz) running LinuxPPC 2000. Note that this performance is reached with all run time checks enabled. For comparison, a VAX 11/785 rated approximately 1.1 MWhets and a VAX 8650 rated approximately 3.8 MWhets, both running FORTRAN.

Bugs and caveats

How to use language extensions

Assertions as pre- or postconditions

ALGOL68G supports an extension called assertions. Assertions can be viewed in two ways. First, they provide a notation for invariants that can be used to code a proof of correctness together with an algorithm. Hardly anyone does this, but assertions make for debugging statements. The syntax for assertions reads

Under control of the `assertions' and `noassertions' pragmat items, the enquiry clause of an assertion is elaborated at runtime. If the enquiry clause yields false, the program is terminated and a runtime error is generated. Example:

will produce a runtime error when faculty is called with a negative argument.

Drawing using GNU plotutils

Introduction

ALGOL68G offers a number of routines for drawing. To this end it implements a subset of libplot from GNU plotutils. This allows for drawing in for example X windows and pnm files from Algol 68. Note that ALGOL68G is not an Algol 68 binding for libplot.

A plotter (window, postscript file, etcetera) can be considered as a stream to which plotting commands are `written', hence ALGOL68G considers plotters to be objects of mode ref file. To interface with libplot, the transput model has been augmented as to accommodate plotters. A plotter must be opened and closed, just like any file. To specify the file to be a drawing device, stand draw channel is declared in the standard environment, that yields true when inspected by draw possible. To specify details on the plotter type and page size, a procedure make device has to be used. For example:

Implemented drawing routines are part of the standard environment.

Setting up a graphics device

proc make device = (file file, string type, string params) void
Sets parameters for plotter file. One sets plotter type to either "X" or "pnm" (the ALGOL68G alpha release only supports these two). X plotters write graphics to an X Window System display rather than to an output stream. Error messages from libplot are written to the ALGOL68G log file. A runtime error results when the plotter could not be opened.

Argument params currently is interpreted as an image size only. For X plotters and pnm plotters the syntax reads "x pixels x y pixels".
proc draw erase = (file file) void
Begins the next frame of a multiframe page, by clearing all previously plotted objects from the graphics display, and filling it with the background color (if any).
proc draw show = (file file) void
Flushes all pending plotting commands to the display device. This is useful only if the currently selected plotter does real-time plotting, since it may be used to ensure that all previously plotted objects have been sent to the display and are visible to the user. It has no effect on plotters that do not do real-time plotting.
proc draw move = (file file, real x, y) void
The arguments specify the coordinates (x, y). The graphics cursor is moved to (x, y). The values of x and y are fractions 0 .. 1 of the page size in respectively the x and y directions.
proc draw aspect = (file file) real
Yields the aspect ratio (y size / x size).
proc draw fill style = (file file, int level) void
Sets the fill fraction for all subsequently drawn objects. A value of level = 0 indicates that objects should be unfilled, or transparent. This is the default. A value in the range 16r0001 .. 16rffff, indicates that objects should be filled. A value of 1 signifies 100% filling; the fill color will be the color specified by calling draw color. If level = 16rffff, the fill color will be white. Values 16r0002 .. 16rfffe represent a proportional saturation level, for instance 16r8000 denotes 50%.
proc draw linestyle = (file file, []char style) void
Sets the line style for all lines subsequently drawn on the graphics display. The supported line styles are "solid", "dotted", "dotdashed", "shortdashed", "longdashed", "dotdotdashed", "dotdotdotdashed", and "disconnected". The first seven correspond to the following dash patterns:
"solid"             --------------------------------
"dotted"            -   -   -   -   -   -   -   -   
"dotdashed"         ----   -   ----   -   ----   -
"shortdashed"       ----    ----    ----    ----    
"longdashed"        -------    -------    -------    
"dotdotdashed"      ----   -   -   ----   -   -
"dotdotdotdashed"   ----   -   -   -   ----   -   -   -
In the preceding patterns, each hyphen stands for one line thickness. This is the case for sufficiently thick lines, at least. So for sufficiently thick lines, the distance over which a dash pattern repeats is scaled proportionately to the line thickness. The "disconnected" line style is special. A "disconnected" path is rendered as a set of filled circles, each of which has diameter equal to the nominal line thickness. One of these circles is centered on each of the juncture points of the path (i.e., the endpoints of the line segments or arcs from which it is constructed). Circles with "disconnected" line style are invisible. Disconnected circles are not filled. All line styles are supported by all plotters.
proc draw linewidth = (file file, real thickness) void
Sets the thickness of all lines subsequently drawn on the graphics display. The value of thickness is a fraction 0 .. 1 of the page size in the y direction. A negative value resets the thickness to the default. For plotters that produce bitmaps, i.e., X plotters, and pnm plotters, it is zero. By convention, a zero-thickness line is the thinnest line that can be drawn.

Specifying colors

proc draw background color = (file file, real red, green, blue) void
Sets the background color for plotter file's graphics display, using fractional intensities in a 48-bit RGB color model. The arguments red, green and blue specify the red, green and blue intensities of the background color. Each is a real value in the range 0 .. 1. The choice (0, 0, 0) signifies black, and the choice (1, 1, 1) signifies white. This procedure affects only plotters that produce bitmaps, i. e. , X plotters and pnm plotters. Its effect is that when the draw erase procedure is called for such a plotter, its display will be filled with the specified color.
proc draw color = (file file, real red, green, blue) void
Sets the foreground color for plotter file's graphics display, using fractional intensities in a 48-bit RGB color model. The arguments red, green and blue specify the red, green and blue intensities of the foreground color. Each is a real value in the range 0 .. 1. The choice (0, 0, 0) signifies black, and the choice (1, 1, 1) signifies white.

Drawing objects

proc draw point = (file file, real x, y) void
The arguments specify the coordinates (x, y) of a point that will be drawn. The graphics cursor is moved to (x, y). The values of x and y are fractions 0 .. 1 of the page size in respectively the x and y directions.
proc draw line = (file file, real x, y) void
The arguments specify the coordinates (x, y) of a line that will be drawn starting from the current graphics cursor. The graphics cursor is moved to (x, y). The values of x and y are fractions 0 .. 1 of the page size in respectively the x and y directions.
proc draw rect = (file file, real x, y) void
The arguments specify the corner coordinates (x, y) of a rectangle that will be drawn starting from the diagonally opposing corner represented by the current graphics cursor. The graphics cursor is moved to (x, y). The values of x and y are fractions 0 .. 1 of the page size in respectively the x and y directions.
proc draw circle = (file file, real x, y, r) void
The three arguments specifying the centre (x, y) and radius (r) of a circle, and the circle is drawn. The graphics cursor is moved to (x, y). The values of x and y are fractions 0 .. 1 of the page size in respectively the x and y directions. The value of r is a fraction 0 .. 1 of the page size in the y direction.

Drawing text

proc draw text = (file file, char horiz_justify, vert_justify, [] char s) void
The justified string s is drawn according to the specified justifications. If horiz_justify is equal to `l', `c', or `r', then the string will be drawn with left, centre or right justification, relative to the current graphics cursor position. If vert_justify is equal to `b', `x', `c', or `t', then the bottom, baseline, centre or top of the string will be placed even with the current graphics cursor position. The graphics cursor is moved to the right end of the string if left justification is specified, and to the left end if right justification is specified. The string may contain escape sequences of various sorts (see section Text string format and escape sequences in the plotutils manual), though it should not contain line feeds or carriage returns; in fact it should include only printable characters. The string may be plotted at a nonzero angle, if draw textangle has been called.
proc draw text angle = (file file, int angle) void
Argument angle specifies the angle in degrees counter clockwise from the x (horizontal) axis in the user coordinate system, for text strings subsequently drawn on the graphics display. The default angle is zero. The font for plotting strings is fully specified by calling draw font name, draw font size, and draw text angle.
proc draw font name = (file file, [] char name) void
The case-insensitive string name specifies the name of the font to be used for all text strings subsequently drawn on the graphics display. The font for plotting strings is fully specified by calling draw font name, draw font size, and draw text angle. The default font name depends on the type of plotter. It is "Helvetica" for X plotters, for pnm it is "HersheySerif". If the argument name is NIL or an empty string, or the font is not available, the default font name will be used. Which fonts are available also depends on the type of plotter; for a list of all available fonts, see section Available text fonts in the plotutils manual.
proc draw font size = (file file, int size) void
Argument size is interpreted as the size, in the user coordinate system, of the font to be used for all text strings subsequently drawn on the graphics display. A negative value for size sets the size to the default, which depends on the type of plotter. Typically, the default font size is 1/50 times the size (i. e. , minimum dimension) of the display. The font for plotting strings is fully specified by calling draw font name, draw font size, and draw text angle.

Reference

Options

Options are passed to ALGOL68G either from the command line or through pragmats. Options are not case sensitive. In the table below, bold letters denote letters mandatory for recognition. Listing and tracing options, and also -pragmat, -nopragmat, take their effect when they are encountered in a left-to-right pass of the program text, and can thus be used, for example, to generate a cross reference for a particular part of the user program.

One-liners

-print unit
Command line only. Prints the value yielded by Algol 68 unit unit. In this way ALGOL68G can execute one-liners from the command line. See also -execute.
-execute unit
Command line only. Executes Algol 68 unit unit. In this way ALGOL68G can execute one-liners from the command line. See also -print.

Memory size

ALGOL68G manages allocation and deallocation of heap space. However, if memory would be unbound, ALGOL68G might claim all available memory before the garbage collector is called. This would impede overall system performance. Therefore memory size is bound.

-heap number
Sets heap size to number kB. This is the size of the block that will actually hold data, not handles. At run-time ALGOL68G will use the heap to store temporary arrays, so even a program that has no heap generators requires some heap space, and might even invoke the garbage collector.
-handles number
Sets handle space size to number kB. This is the size of the block that hold handles that point to data in the heap. A reference to the heap does not point to the heap, but to a handle as to make it possible for the garbage collector to compact the heap.
-frame number
Sets frame stack size to number kB. A heavily recursive program with many local variables may require a large frame stack space.
-stack number
Sets expression stack size to number kB. A heavily recursive program may require a large expression stack space.

Listing options

-extensive
Generates extensive listing, including source listing, syntax tree, cross reference etcetera. This listing can be quite bulky.
-listing
Generates concise listing.
-moids
Generates overview of moids in listing file.
-preludelisting
Generates a listing of preludes.
-source, -nosource
Starts (or stops) listing of source lines in listing file.
-statistics
Generates statistics in listing file.
-terminal
Echo listing file to stdout.
-tree, -notree
Generates syntax tree listing in listing file. This option can make the listing file bulky, so use considerately.
-unused
Generates an overview of unused tags in the listing file.
-xref, -noxref
Starts (or stops) generating a cross reference in the listing file.

Miscellaneous options

-assertions, -noassertions
Starts (or stops) elaboration of assertions.
-help
Provides an overview of options.
-norun
Check syntax only, interpreter does not start.
-nowarnings
Suppresses warning messages.
-pragmats, -nopragmats
Starts (or stops) elaboration of pragmat items. When disabled, pragmat items are ignored, except for -pragmats.
-precision number
Sets precision for long long real to number significant digits. Note that ALGOL68G algorithms for extended precision are not really suited for precisions larger than a few hundred digits.
-trace, -notrace
Starts (or stops) tracing of a running program.
-verbose
ALGOL68G will inform you on its actions.
-version
States the version of the running copy of ALGOL68G, including date of compilation.

Examples

Quick reference of coercions and standard environment

Widenings

Enquiries

Modes

Transput

Math constants

Math functions

Operator synonyms

Operator priorities

Monadic operators

Dyadic operators

Miscellaneous


References

Appendix. Example programs

Towers of Hanoi by a recursive mode declaration

After a program from the MC Revised Algol 68 Test Set.

# After `P. G. Hibbard, Proc. Int. Conf. A68 III, Winnipeg, June, 1974'         #
# Applied occurrence of mode-indication in actual-bounds of its actual-declarer #

  INT n := read int; 
CHAR a := "a", b := "b", c := "c"; PROC swap = (REF CHAR c1, c2) VOID: (CHAR d = c1; c1 := c2; c2 := d); MODE HANOI = [ IF n > 0 THEN n -:= 1; swap(b, c); HANOI h1; swap(b, c); print((newline, "move ", whole(LWB h1 + 1, 0), " from ", a, " to ", c, ".")); swap(a, b); HANOI h2; swap(a, b); n +:= 1 ELSE 0 FI : 1] INT; LOC HANOI

Algol 68
Algol 68 Genie


This website is archived by the National Library of the Netherlands.

© J.M. van der Veer   •   jmvdveer@algol68genie.nl