Algol 60

Algol 60 is a very nice programming language, and probably would have become extremely popular if it were not for the I/O problem. Because the Algol 60 document did not provide for any I/O, it was provided in ad-hoc ways by various compiler writers. No two I/O systems were compatible with one another, so it was not possible to write a "Hello World" program that would run on more than one implementation.

Another serious problem is the way ALGOL 60 keywords were defined. Keywords like WHILE were not to be considered strings of characters, they were to be interpreted as symbols like + or /. At the time Algol 60 was defined, compiler technology had not advanced to the point were it was understood how to handle keywords and reserved words. Some compilers forced programmers to put all keywords in quotes, which was permitted by the language definition. The old Z80 compiler that is still available on the web uses this convention, as did the IBM 360 ALGOL compiler. Another alternative is to force all variables to be in lower case and all keywords be in upper case. Our example below follows this convention. The Z80 compiler also uses this convention. It looks at the keyword "BEGIN" to determine which convention you've used. If you use the quoted keyword convention, you also must use upper case for your variables.

The formal definition of the language permitted the use of both upper and lower case, which was unusual at the time. Also, arithmetic operations were supposed to be designated by standard mathematical symbols. An "x" was to be used for multiplication and a line with dots above and below was to be used for integer division. Obviously, this did not motivate computer manufacturers to include such symbols in their equipment, so in actual implementations, the now conventional symbols * and / were used. Logical operations included AND, OR, NOT, and IMPLICATION, which were also intended to be specified by standard mathematical symbols. In implementations the keywords AND, OR, NOT, and IMPLY took the place of the special symbols.

My first ALGOL 60 program (circa 1969) was written in an all upper case dialect with no quotes on the keywords. This was the implementation provided by the Dartmouth Time Sharing System, the system that first gave us the BASIC language.

The program below compiles and runs correctly on the old Z80 compiler., This compiler requires that the program be terminated by the extra keyword "FINISH," which is non-standard. Formally, an Algol 60 program is any single Algol 60 statement, including compound statements created with BEGIN/END pairs. I found this compiler extremely difficult to figure out, so if you want to use it, do the following.

1. Store your program with the suffix ".alg" and make sure the part of the file name before the period is no longer than 8 characters.
2. Compile your program using the following command, replacing x.alg with the real file name:
Algol x.alg
3. A correct compilation will give you a file named x.obj where x is the original name of your file minus the .alg suffix.
4. Execute the linker, alink, with no parameters. (They will be ignored anyway.)
5. At the prompt type the following, replacing x with the original name of your file minus the .alg suffix:
x.asc=x.obj
6. To run your program type the following command where x is the original name of your program minus the .alg suffix:
arun x.asc

Algol 60 is a "semicolon as separator" language. Other such languages are Algol 68 and Pascal. This is in contrast to languages like C and PHP in which semicolons are statement terminators. What this means in practice is that a semicolon that is followed by END is not required. The following code contains several superfluous semicolons. Because it is quite difficult to figure out where the semicolons don't belong, "semicolon as separator" languages invariably will accept null statements anywhere in the code.

Believe it or not, there are people who care passionately about this issue. That's why the "semicolon as separator" convention has survived despite the fact that "semicolon as terminator" is easier for both programmers and compiler writers.


BEGIN

COMMENT

//////////////////////////////////////////////////////////

// Name: Peter M. Maurer

// Program: Sieve of Eratosthenes

// Due: Never

// Language: Algol 60

//////////////////////////////////////////////////////////

;

COMMENT define the sieve data structure ;

INTEGER ARRAY candidates[0:1000];

INTEGER i,j,k;

COMMENT 1000 to protect against strict evaluation of AND ;

FOR i := 0 STEP 1 UNTIL 1000 DO

BEGIN

COMMENT everything is potentially prime until proven otherwise ;

candidates[i] := 1;

END;

COMMENT Neither 1 nor 0 is prime, so flag them off ;

candidates[0] := 0;

candidates[1] := 0;

COMMENT start the sieve with the integer 0 ;

i := 0;

FOR i := i WHILE i<1000 DO

BEGIN

COMMENT advance to the next un-crossed out number. ;

COMMENT this number must be a prime ;

FOR i := i WHILE i<1000 AND candidates[i] = 0 DO

BEGIN

i := i+1;

END;

COMMENT insure against running off the end of the data structure ;

IF i<1000 THEN

BEGIN

COMMENT cross out all multiples of the prime, starting with 2*p.;

j := 2;

k := j*i;

FOR k := k WHILE k < 1000 DO

BEGIN

candidates[k] := 0;

j := j + 1;

k := j*i;

END;

COMMENT advance to the next candidate ;

i := i+1;

END

END;

COMMENT all uncrossed-out numbers are prime (and only those numbers) ;

COMMENT print all primes ;

FOR i := 0 STEP 1 UNTIL 999 DO

BEGIN

IF candidates[i] # 0 THEN

BEGIN

write(1,i);

text(1," is prime*N")

END

END;

END

FINISH

Click Here for the actual code.