Ionus Algol 60 Compiler
By
John F. Green
The Ionus Algol 60 compiler tries to be as close as possible to the Algol 60 Revised Report (RR) but being a hardware representation and an implementation there are differences. This hardware representation uses UPPER stropping, that is upper case letters are used to represent symbols such as BEGIN, END and PROCEDURE and operators. These appear a bold words in the RR and is called the reference language.
Where the Revised Report (RR) does not define certain situations then the Modified Report (MR) is used where the MR has clarified that particular situation. This does not mean it complies with the MR, merely that it uses the MR solution where the RR does not provide sufficient definition. An example of this is own arrays.
Also where the RR does not specify anything at all the MR is the first choice. One obvious example of this is Input/Output procedures. However this compiler will eventually have more extensive Input/Output routines, but the MR routines are the minimum and in fact they are fairly primitive.
Later versions of the compiler will have options for MR compatibility.
<letter> ::= a | b | c | d | e | f | g | h | i | j | k | l |
m | n | o | p | q | r | s | t | u | v | w | x | y | z
Deviation: The RR has upper and lower case letters but in this HRR upper case letters are not treated as letters only as making up independent basic symbols which have no relation to the individual letters of which they are composed. They may appear in strings however.
Deviation: the 10 is represented by E.
Deviation: the restriction of 3.2.4 is not currently enforced (See further discussion in section 3.2.4).
Deviation: The bounds of an array declared as own may only be of the syntactic form <integer> (see Section 2.5.1). This is in line with the MR.
Algol | Deviations |
< | <, LT |
≤ | <=, LE |
= | =, EQ |
≥ | >=, GE |
> | >, GT |
≠ | <>, NE |
Algol | Deviations |
≡ | ==, EQV |
⸧ | =>, IMP |
∧ | /\, AND |
∨ | \/, OR |
¬ | ~, NOT |
Algol Symbol | Deviations |
10 | E,# |
Algol | Deviations |
+ | + |
- | - |
× | * |
/ | / |
÷ | //, % |
↑ | **, ^ |
Deviation: A <unsigned integer> constant passed as a parameter is never passed as a label except in the situations below:
1.The procedure specifies the parameter as LABEL.
2.The label is in a switch and the switch element is used eg. SWITCH s := 17; proc(s[1]);
3.A designational expression which unambiguously defines the number as a label eg proc(IF x < 5 THEN 17 ELSE labelx); here because labelx is a label, the expression is a designational expression and 17 will need to be a label, the value of the designational expression is a label.
Note: Version 1.1 (currently under test) of the compiler supports integer labels in all positions and so complies to the RR completely except maybe the treatment of strings.
Additional functions added to the standard library. These functions are from the Modified Report.
Function | Description |
INTEGER PROCEDURE iabs(E); VALUE E; INTEGER E; | iabs := IF E >= 0 THEN E ELSE -E; |
INTEGER PROCEDURE length(str); STRING str; | length := number of characters in the open string enclosed by the outermost string quotes |
PROCEDURE outterminator(channel); VALUE channel; INTEGER channel; | outputs a terminator for use after a number. |
PROCEDURE inchar(channel, str, int); VALUE channel; INTEGER channel, int; STRING str; | Set int to value corresponding to the first position in str of current character on channel. Set int to zero if character not in str. Move channel pointer to next character; |
PROCEDURE outchar(channel, str, int); VALUE channel, int; INTEGER channel, int; string str; | Pass to channel the character in str, corresponding to the value of int; |
PROCEDURE ininteger(channel, int); VALUE channel; INTEGER channel, int; | int takes the value of an integer, as defined in Section 2.5.1, read from channel. |
PROCEDURE outinteger(channel, int); VALUE channel, int; INTEGER channel, int; | Passes to channel the characters representing the value of int, followed by a terminator; |
PROCEDURE inreal(channel, re); VALUE channel; INTEGER channel; REAL re; | re takes the value of a number, as defined in Section 2.5.1, read from channel. |
PROCEDURE outreal(channel, re); VALUE channel, re; INTEGER channel; REAL re; | Passes to channel the characters representing the value of re, following by a terminator; |
PROCEDURE outstring(channel, str); VALUE channel; INTEGER channel; STRING str; | Output the string to the channel. |
REAL PROCEDURE maxreal; | Maxreal: the maximum allowable positive real number |
REAL PROCEDURE minreal; | Minreal:the minimum allowable positive real number |
INTEGER PROCEDURE maxint; | Maxint: the maximum allowable positive integer |
REAL PROCEDURE epsilon; | The smallest positive real number such that the computational result of 1.0 + epsilon is greater than 1.0 and the computational result of 1.0 - epsilon is less than 1.0; |
PROCEDURE stop; | Stop execution. |
PROCEDURE fault(str, r); VALUE r; STRING str; REAL r; | Output the str and real and anyother information about the fault and call stop. |
These functions are described in the report by the “International Federation for Information Processing, Working Group 2.1 on Algol, Chairman: W.L. Van Der Poel, Technological University Delft, Delft, Netherlands”
Function | Description |
PROCEDURE inarray(channel, a); VALUE channel; INTEGER channel; ARRAY a; | Read in the array ‘a’ on channel ‘channel’ in row wise order. |
PROCEDURE outarray(channel, a); VALUE channel; INTEGER channel; ARRAY a; | Write out the array ‘a’ on channel ‘channel’ in row wise order. |
Additional Functions added to the standard library. These functions are added by Ionus.
These have been added as functions and not operators as in Algol68 since new operator symbols are not pat of the Algol60 philosophy.
It is still being considered if the Simula functions upperbound and lowerbound will be used or are also accepted. Simula is a much closer extension of Algol60 then Algol68 and so maybe they should be at least accepted. In fact it maybe that more of the Simula functions could be added. Algol68 though is Algol.
The upb and lwb are short names but in expressions that may be a bonus. E.g.
FOR i := lwb(1,a) STEP 1 UNTIL upb(1, a) DO … ;
as opposed to
FOR i := lowerbound(a, 1) STEP 1 UNTIL upperbound(a, 1) DO … ;
Function | Description |
INTEGER PROCEDURE upb(n, a); VALUE n; INTEGER n; ARRAY a; | Upper bound of the nth dimension of the array ‘a’. Equivalent to n upb a in Algol68. The parameters are reversed in Simula’s upperbound. |
INTEGER PROCEDURE lwb(n, a); VALUE n; INTEGER n; ARRAY a; | Lower bound of the nth dimension of the array ‘a’. Equivalent to n lwb a in Algol68. The parameters are reversed in Simula’s lowerbound. |
INTEGER PROCEDURE dim(a); ARRAY a; | Return the number of dimensions of array ‘a’. |
REAL PROCEDURE cputime; | Returns a real value of seconds from the start of execution. Similar to the Simula function. |
See
https://en.wikipedia.org/wiki/Tower_of_Hanoi
>cat hanoi.a60
BEGIN COMMENT towers of hanoi;
PROCEDURE hanoi(n, from, to, via);
VALUE n, from, to, via;
INTEGER n, from, to, via;
IF n > 0 THEN
BEGIN
hanoi(n - 1, from, via, to);
outstring(1, `Move disk from pole '); outinteger(1, from);
outstring(1, `to pole '); outinteger(1, to); outterminator(1);
hanoi(n - 1, via, to, from)
END;
hanoi(3, 1, 2, 3)
END
>algol60cr hanoi.a60
Ionus Algol60 Compiler
(compile and run release) Version 1.0
Move disk from pole
1
to pole
2
Move disk from pole
1
to pole
3
Move disk from pole
2
to pole
3
Move disk from pole
1
to pole
2
Move disk from pole
3
to pole
1
Move disk from pole
3
to pole
2
Move disk from pole
1
to pole
2
Program Halted
INSTRUCTIONS EXECUTED = 1696
TIME TO EXECUTE 0.000130332s
No Warnings
No Errors
Man or Boy
See
https://en.wikipedia.org/wiki/Man_or_boy_test
>cat man_or_boy.a60
BEGIN COMMENT Man or boy test, https://en.wikipedia.org/wiki/Man_or_boy_test;
REAL PROCEDURE a(k, x1, x2, x3, x4, x5);
VALUE k; INTEGER k;
BEGIN
REAL PROCEDURE b;
BEGIN k := k - 1;
b := a := a(k, b, x1, x2, x3, x4);
END;
IF k <= 0 THEN a := x4 + x5 ELSE b;
END;
outreal(1, a(10, 1, -1, -1, 1, 0));
END
>algol60cr man_or_boy.a60
Ionus Algol60 Compiler
(compile and run release) Version 1.0
-67
Program Halted
INSTRUCTIONS EXECUTED = 51450
TIME TO EXECUTE 0.000895485s
No Warnings
No Errors
Ackermann
See
https://en.wikipedia.org/wiki/Ackermann_function
>cat ackermann.a60
BEGIN COMMENT Ackermann function;
INTEGER i, j;
INTEGER PROCEDURE ackermann(m, n);
VALUE m, n;
INTEGER m, n;
ackermann :=
IF m = 0 THEN
n + 1
ELSE IF n = 0 THEN
ackermann(m - 1, 1)
ELSE
ackermann(m - 1, ackermann(m, n - 1));
FOR i := 1 STEP 1 UNTIL 10 DO
BEGIN
j := ackermann(3, i);
outinteger(1, j);
END
END
>algol60cr ackermann.a60
Ionus Algol60 Compiler
(compile and run release) Version 1.0
13
29
61
125
253
509
1021
2045
4093
8189
Program Halted
INSTRUCTIONS EXECUTED = 2770046799
TIME TO EXECUTE 19.8140692s
No Warnings
No Errors