ALGOL 68, the foundation of all modern languages
The purpose of this sheet is to give an overview of the ALGOL 68 syntax and show how the language has influenced its successors, including C, Pascal and all C-like languages, especially Go. Refer to the manuals at the bottom of the page for a detailed description of the language.
The first ALGOL 68 compiler was developed in 1970 by Peck, Coster, Mayu and Weingaarden in the IFIP working group. Nicklaus Wirth and Tony Hoare had already developed ALGOL W, another successor to ALGOL 60, in 1966.
ALGOL W was the basis for the Pascal language, which also appeared in 1970 and took, in fact, the place of the universal language that the authors intended for ALGOL 68. However, the latter inspired all C-like languages.
ALGOL Language Description 68
The complexity of ALGOL 68 will actually make it difficult for a modern programmer to understand, which is not obvious in the code below, which is limited by the simplest syntax.
Types
- int: Integer.
- bool.
- real: Real number.
- compl: Complex number.
- charms.
- string: string.
- bytes: character pair.
- struct.
- emptiness.
- bits: Bit string.
- file: File.
It should be noted that, logically, a real number is represented by a real type adopted by Pascal, while C uses float, which is the name of the memory representation: "floating point" or "floating point." And C was foolishly followed by most subsequent languages.
The string type is also replaced in C by char *, but later it will return in C++ and modern languages.
For numeric types, the long and short modifiers specify the number of bytes of memory representation that B receives.
Predefined values:
- nil: Nothing, short for "nihil" (nothing) or an acronym for "Not In List" in Lisp.
- true, false.
Operators
Most are found in C.
- ( )
- , Separator.
- ; Terminator.
- :Terminator.
- =,: = Purpose.
- [] Declare a slice, index, or array.
- +, -, * ,/, ^,%,% *: Arithmetic.
- + is also a string concatenation operator.
- * can also multiply a character or string.
- >, >=, <, <=,
- =, eq: Equal to.
- ~ = ,/=, ne: not equal to .
- + =, * = ,/=: Simplified assignment .
- #, co, comment: Comment, ends with the same character.
- &, and, or: Boolean operators.
A non-equal operator is the most controversial. ALGOL 68 has several options, Pascal uses <>, C uses! = instead of, which is accepted by all C-like operators. ~ = later reappears in Lua.
Purpose and declaration
Tasks:
a := 10;
a := b := c := 10; // 10 assigned to a, b, and c.
a + := b; // equivalent to a := a + b
+ can be replaced by any other arithmetic operator.
Declarations:
int i = 10;
real r = 1.2;
[]int ai = (2,5,89,6,3);
[]string astr = ("a", "b", "hello");
[1:2,4:5]int mi = ((10,20), (100,200)); // Two-dimensional array.
Constant and variable
int i = 10;
int j := 20;
i is a constant, while j is a variable. This was not used in any other language.
Indexing and slicing
[]int ai = (10,20,30,40,50);
ai [2] returns 30.
ai [2:3] returns 40.50.
The language has a complex syntax for accessing the content of a multidimensional array, or string, which unnecessarily complicates compiler development.
Dynamic array
The flex modifier allows you to define an array as a variable-size array.
Structure
The declaration is similar to the function header.
struct (int i, real r) s;
i of s := 10;
r of s := 1.23;
The C equivalent would be:
struct s {
int i = 10;
real r = 1.23;
}
Pascal decided to use a recording construct that comes from ALGOL 60, which in turn inherited it from COBOL. Both are complex types and class ancestors.
Union
In union, variables share the same memory area, and therefore the same value can be available for different types.
union(int i, real r) u;
If the management structure
Terminator is a word if backward. A strange syntax not found in any other language that has followed, not even Pascal.
if condition then
...
[else ... ]
fi
or
if condition then
...
elif condition then
...
[else ...]
fi
for management structure
He does a lot of things at once .
for variable from start [by increment] to end [while condition] do
...
od
Example:
for i from 1 to 10 while i ne 11 do
...
od
The various parts are optional. Exempli gratia
to 10 do ... od
executes the loop ten times. Whereas:
for i while i < 11 do ... od
Executes the loop while the condition is met.
The tendency then was to divide the structure into several others: for, while, do until, for in. However, the Go language returned to this compartmentalized structure.
Foreach was later added to ALGOL 68 by compilers.
Variant Control Structure
The ancestor of the switch case management structure was more limited:
case variable in
statements,
statements,
...
esac;
An example of the number of days in months of the year, from January to December.
The month variable has a value between 1 and 12.
case month in
31,
if year % 4 = 0 and year % 100 ~= 0 or year % 400 = 0 then 29 else fi;
31,30,31,30,31,31,30,31,30,31
esac;
Procedure
The return type is placed at the end of the header, unlike C and is found in some modern languages; it is derived from ALGOL.
proc p = (int a, real b) real:
begin
...
end;
Parameters are given in parentheses; the return type is placed after .
The return value is the value of the last expression evaluated in the body of the procedure. The idea adopted by the language of Julia.
Procedure format without parameters and without returns:
proc q = void:
begin
...
end;
Pascal thought it would be a good idea to complicate matters by distinguishing between functions that return value and procedures that return nothing, a duality that also exists in Fortran. This is regression and adds nothing. In addition, the Fortran subroutine can return multiple values at once, which Pascal lacks.
Overlapping
Procedures can be performed in parallel with the par command:
par begin
...
end;
Go's co-programs are pretty similar.
Conclusion
The language seems to have been defined by a discussion group where everyone wants to contribute their ideas to complete the language and where no one cares about the construction of the compiler that will implement it. This prompted Nicklaus Wirth to get a powerful compiler, create Pascal based on ALGOL, but getting rid of most of the elements of the language.
However, many of the concepts present in ALGOL occur in its successor languages, and some that have been abandoned reappear in recent languages such as Go and Julia. Conversely, various syntax and concepts of other older languages, such as Tcl, Rebol, etc., have been forgotten.
Links: