Algol 68

from Wikipedia, the free encyclopedia

Algol 68 is a programming language . Its design was based on the requirement that it should be capable of representing and disseminating algorithms , executing them effectively on a variety of different computing systems, and helping to teach them to students.

The Algol 68 language represented a new approach, but was based on the experience with Algol 60 and the principles of that language. The aim was a much broader scope and a more stringent language definition. The definition was first published as Report on the Algorithmic Language ALGOL 68 in 1968 and fundamentally revised in 1976 in the Revised Report .

The report names the following objectives: completeness and clarity of the description, orthogonality of the design, safety, effectiveness.

Compared to Algol 60, some concepts have been standardized; The concept of a name s, a value that references other values , the possibility of defining structures and other data types was newly introduced . From the lower acceptance of Algol 60 compared to FORTRAN , it was concluded that a definition of input and output could promote dissemination.

Critics argued that the language no longer had the simplicity of Algol 60 and was too difficult to implement. Concepts that were more widely used in practically more successful languages ​​such as C ++ , such as operator overloading, were first defined syntactically. In contrast to Algol 60, the language is largely expression-oriented, therefore also to be seen as an early example of a functional programming language .

In the description of the programming language, a new type of description procedure, the 2-stage grammar, also called van Wijngaarden grammar , was developed. This made it possible to formalize all context conditions .

Also new was the PRAGMAT concept , which allowed suggestions for optimization for the compilers without changing the semantics of a program so that the programs remained portable despite the optimization.

Algol 68 was viewed by some as an academic project because there was a long time missing usable compilers that implemented the entire language level.

Reserved symbols

In Algol 68 there are the following reserved symbols:

mode, op, prio, proc,
flex, heap, loc, long, ref, short,
struct, union,
of, at, is, isnt, true, false, empty, nil, skip,
co, comment, pr, pragmat,
case, in, ouse, out, esac,
for, from, to, by, while, do, od,
if, then, elif, else, fi
par, begin, end, go, to, goto, exit.

Some of these symbols have abbreviations:

p is q     ↦ p :=: q
r isnt nilr :/=: ∘
skip ↦ ~
at   ↦ @ 
co   ↦ ¢
case x in a, b ouse y in c, d, e out f esac ↦ ( x | a, b |: y | c, d, e | f )
if x then a elif y then b else c fi         ↦ ( x | a |: y | b | c )
begin a; bc end                           ↦ ( a; b; c )

The designations for modes and operators are written with the same character set as the reserved symbols, but are not reserved, but can be declared with a different meaning which then applies within a block. The following modes are defined without an explicit declaration:

bits, bool, bytes, char, compl, int, real, sema, string, void,
channel, file, format

Compiler instructions and comments

Compiler instructions are inserted into the program. They typically contain hints for the compiler, e.g. B .:

pragmat heap=32 pragmat
pr heap=32 pr

Comments can be inserted in different ways:

¢ Der ursprüngliche Weg einen Kommentar hinzuzufügen (analog der englischen Phrase: Adding your 2 cents) ¢
comment "bold" comment comment
co Kommentar 1. Form co
# Kommentar 2. Form #
£ Dieser Kommentar benutzt das hash/pound Zeichen einer UK Tastatur £

Normally, comments cannot be nested in Algol 68. This restriction can be circumvented by using different comment symbols (e.g. the hash is only used for temporary deletion).

Data types

Algol 68 denotes data types as modes. The basic data types are real, int, compl, bool, char, bits, bytesand void. For example:

int n = 2;
co n ist eine Konstante mit dem Wert 2. co
real avogadro = 6.0221415⏨23; co Avogadrozahl co
long long real pi = 3.14159 26535 89793 23846 26433 83279 50288 41971 69399 37510;
compl square root of minus one = 0 ⊥ 1

The data type voidcomprises only a single value, namely empty, has no information content. This characterizes expressions and functions that do not provide a usable result; this unifies the concepts of expression and instruction , as well as function and procedure . Examples:

exit     ¢ Ausdruck vom Mode void, entspricht der FORTRAN-Anweisung STOP ¢
print(f) ¢ Ausdruck vom Mode void, da print keinen Funktionswert liefert ¢
7*"8"    ¢ Ausdruck vom Mode string mit dem Wert "8888888"               ¢
proc (int)int  doppelt     = (int i)int : i*2;          ¢ Funktion mit int-Ergebnis ¢
proc (int)void wellenlinie = (int n)void: print(n*"~"); ¢ Prozedur (ohne Ergebnis)  ¢

Instead of modes like DOUBLE, or LONGand SHORT, etc. there are 68 modifiers in Algol . For example, or instead of writing. Type attributes such as (smallest real value, which when added to 1.0 produces a result not equal to 1.0) and (largest representable long - int value) are used to adapt programs to different implementations. long reallong long realDOUBLEsmall realmax long int

Declarations

All identifiers, e.g. for constants, names (corresponds to variables and pointers in earlier programming languages) or functions, must be declared; the agreement does not have to be made before the first use, but of course the block structure must be observed for its visibility area . Many standard identifiers, for example, printor max intare contained in a fictitious block that surrounds the entire program.

The so-called equivalence declaration, with which an identifier is assigned a meaning consisting of mode and value, is used uniformly. Examples:

co Konstanten co
  int  f = 5;      ¢ der Bezeichner f bezeichnet nun den int-Wert 5                          ¢
  real z = f/2;    ¢ der Bezeichner z bezeichnet nun den real-Wert 2.5                       ¢
  real r = random; ¢ der Wert der Konstanten r wird erst zur Laufzeit des Programms bestimmt ¢
co Variablen co
  ref int v = loc int; ¢ v bezeichnet eine neu deklarierte lokale int-Variable               ¢
  ref int w = loc int := f; ¢ w bezeichnet eine lokale int-Variable mit Anfangswert 5        ¢
co Funktionen co
  proc (real)real h = (real x)real: x/2; ¢ h bezeichnet eine real-Funktion mit real-Parameter¢

However, constants, variables, pointers and functions can also be used anonymously, i.e. without a declaration. This is useful if you only need the entity in question at one point in the program. Example:

¢ integral sei eine Funktion, die ein bestimmtes Integral über einer real-Funktion berechnet.  ¢
¢ Die zu integrierende Funktion kann man entweder namentlich oder anonym an integral übergeben; ¢
¢ die zu integrierende Funktion hat offensichtlich den Mode proc(real)real                ¢
print(("Integral x/2    von 0 bis 3 =", integral (h,   0, 3 ))); ¢ h siehe oben ¢
print(("Integral sin(x) von 0 bis π =", integral (sin, 0, pi))); ¢ sin und pi sind Standard-Bezeichner ¢
print(("Integral (2x+1) von 0 bis 1 =", integral ((real x)real: 2*x+1, 0, 1))); ¢ Anonyme Funktion ¢

Modes and operators can be declared in a similar way to identifiers. Examples:

mode rfunproc(real)real; ¢ rfun ist der Mode einer real-Funktion mit real-Parameter ¢
¢ Operatoren sind Funktionen in anderer Gestalt; also werden sie wie Funktionen deklaratiert: ¢
op (string,int)string * = (string s, int n)string: n*s;
print("/\"*17); ¢ im Gültigkeitsbereich der obigen op-Deklaration druckt das dasselbe wie print(17*"/\") ¢

There are abbreviations for some common equivalence declarations. For example:

loc int v; ¢ statt ref int v = loc intint-Variable ¢
loc int w := f; ¢ statt ref int w = loc int := f – int-Variable mit Anfangswert¢
int w := f; ¢ statt ref int w = loc int := f ¢
proc h = (real x)real: x/2;  ¢ statt proc (real)real h = (real x)real: x/2 ¢
op * = (string s, int n)string: n*s; ¢ statt op (string,int)string * = (string s, int n)string: n*s ¢

literature

Web links