![]() |
![]() |
|
![]() |
![]() |
Encyclopedia :
A :
AL :
ALG :
ALGOL 68 |
|
|
ALGOL 68ALGOL 68 was conceived as a successor to the ALGOL 60 programming language, designed with the goal of a much wider scope of application and a more rigorously defined syntax and semantics. Contributions of ALGOL 68 to the field of computer science are deep and wide ranging, although some of them were not publicly identified until they were passed, in one form or another, to one of many subsequently developed programming languages.ALGOL 68 was defined using a two-level grammar formalism invented by Adriaan van Wijngaarden. Van Wijngaarden grammars use a context-free grammar to generate an infinite set of productions that will recognize a particular ALGOL 68 program; notably, they are able to express the kind of requirements that in many other programming language standards are labelled "semantics" and have to be expressed in ambiguity-prone natural language prose, and then implemented in compilers as ad hoc code attached to the formal language parser. The main principles of design are completeness and clarity of design, orthogonal design, security, efficiency, the latter by static mode checking, mode-independent parsing, independent compilation and loop optimization. Critics of ALGOL 68, prominently C. A. R. Hoare, point out that it abandoned the simplicity of ALGOL 60 and became a vehicle for various complex ideas of its designers. The language also did little to make the compiler writer's task easy, in contrast to deliberately simple contemporaries (and competitors) C, S-algol and Pascal. The ALGOL 68 heritage is acknowledged by Scheme, and by C++. For a full length treatment of the language, see Programming Algol 68 Made Easy by Dr. Sian Leitch. Notable Language ElementsUnits (Expressions)The basic language construct is the unit. A unit may be a formula, an enclosed clause, a routine text or one of several technically needed constructs. The technical term enclosed clause unifies some of the inherently bracketting constructs known as block, do statement, switch statement in other contemporary languages. When keywords are used, generally the inversed character sequence of the introducing keyword is used for terminating the enclosure ( IF - FI, CASE - ESAC, DO - OD). This feature was reused in the common UNIX Bourne shell. DeclarationsAll variables need to be declared, the declaration does not have to appear prior to the first use. The basic datatypes (called modes in ALGOL 68 parlance) are real, int, compl (complex number), bool and char. For example:real pi = 3.1415926; int n = 2; However, the declaration real pi; is just syntactic sugar for ref real pi = loc real;. That is, pi is really the constant name for a reference to a newly generated local real variable.Furthermore, instead of defining both real and double, or int and long and short, etc., ALGOL 68 provided modifiers, so that the presently common double would be written as long real instead, for example. Type queries of the kind of max real and min long int are provided to adapt programs to different implementations.Expressions and compound statementsALGOL 68 being an expression-oriented programming language, the value returned by an assignment statement is a reference to the destination. Thus, the following is valid ALGOL 68 code: real twice pi = 2 * real pi = 3.1415926; This notion is present in C and Perl, among others. Note that twice pi is a single identifier, i.e., blanks are permitted within ALGOL 68 names (effectively avoiding the underscores versus camel case versus all lowercase issues at once, but at the price of introducing a cornucopia more serious problems in software engineering). As another example, to express the mathematical idea of a sum of Compound statements are all terminated by distinctive (if somewhat irreverent) closing brackets: Arrays and structuresALGOL 68 supports arrays with any number of dimensions, and it allows for the slicing of whole or partial rows or columns, among many other choices. ALGOL 68 supports multiple field structures (structs). Union types (modes) are supported. Reference variables may point to both array slices and structure fields. For an example of all this, here is the traditional linked list declaration: mode node = union (real, int, compl, string); mode list = struct (node val, ref list next); ProceduresProcedure (proc) declarations require type specifications for both the parameters and the result (void if none):
proc max of real (real a, b) real:or, using the compact form of the conditional statement:
proc max of real (real a, b) real: (a>b | a | b);The return value of a proc is the value of the last statement executed before the procedure returns. References to procedures (ref proc) are also permitted. Call-by-reference parameters are provided by specifying references (such as ref real) in the formal argument list. The following example defines a procedure that applies a function (specified as a parameter) to each element of an array:
proc apply (ref [] real a, proc (real) real f):This simplicity of code was unachievable in ALGOL 68's predecessor ALGOL 60. OperatorsThe programmer may define new operators and both those and the pre-defined ones may be overloaded. The following example defines operator max with both dyadic and monadic versions (scanning across the elements of an array).
prio max = 9;
Input and outputTransput is the term used to refer to ALGOL 68's input and output facilities. There are pre-defined procedures for unformatted, formatted and binary transput. Files and other transput devices are handled in a consistent and machine-independent manner. The following example prints out some unformatted output to the standard output device:print ((newpage, "Title", newline, "Value of i is ", i, "and x[i] is ", x[i], newline)); Note the predefined constants newpage and newline.Parallel processingA little used feature of ALGOL 68 (and in fact, rarely implemented by compiler designers) was parallel processing. Code sampleThis sample program implements the Sieve of Eratosthenes to find all the prime numbers that are less than 100. nil is the ALGOL 68 analogue of the null pointer in other languages. The notation x of y accesses a member x of a struct or union y. Program representationA feature of ALGOL 68, inherited from ALGOL tradition, is its different representations. There is a representation language used to describe algorithms in printed work, a strict language (rigorously defined in the Report) and an official reference language intended to be used in actual compiler input. In the examples above you will observe underlined words. This is the formal representation of the language. ALGOL 68 has no reserved words, and spaces are allowed in identifiers, so the fragment: int a real int = 3 ; is legal. The programmer who actually writes the code does not have the option of underlining the code. Depending on hardware and cultural issues, different methods to denotate these identifiers, have been devised, called stropping regimes. So all or some of the following may be possible programming representations: 'INT' A REAL INT = 3 ; .INT A REAL INT = 3 ; INT a real int = 3 ; int a real_int = 3; Some VanitasFor its technical intricacies, ALGOL 68 needs a cornucopia of methods to deny the existence of something: skip - an undefined value always syntactically valid, void - syntactically like a mode, but not one, nil - a name not denoting anything, of no mode, empty - the only value admissible to void, needed for selecting void in a union, [1:0]int - an empty array of mode int, undefined - a procedure raising an exception in the runtime system. The term nil is var always evaluates to true for any variable, whereas it is not knownto which value a comparison x < skip evaluates for any integer x. ALGOL 68 leaves intentionally undefined, what happens in case of integer overflow, the integer bit representation, and the degree of numerical accuracy for floating point. In contrast, the language Java has been criticized for overspecifying the latter (Borneo). Comparison to C++Regarding the computing features, the nearest living sibling to ALGOL 68 may be C++, making this a good comparison candidate: C++ has not: ALGOL 68 has not: VariantsThe language described above is that of the "Revised Report". The original language differs in syntax of the mode cast, and it had the feature of proceduring, i.e. coercing the value of a term into a procedure which evaluates the term. Proceduring effectively can make evaluations lazy. The most useful application could have been the short-circuited evaluation of boolean operators. In op andf = (boola,proc boolb)bool:(a | b | a); b is only evaluated, if a is true. As defined in ALGOL 68, it did not work as expected. Most implementations emulate this behaviour by extension of the language. ALGOL 68R from RRE was the first ALGOL 68 subset implementation, In ALGOL 68S from Carnegie_Mellon_University the power of parallel processing was improved by adding an orthogonal extension, eventing. Any variable declaration containing keyword event made assignments to this variable eligible for parallel evaluation, i.e. the right hand side was made into a procedure which was moved to one of the processors of the C.mmp multiprocessor system. Accesses to such variables were delayed after termination of the assignment. Cambridge ALGOL 68C was a portable compiler that implemented a subset of ALGOL 68 by enforcing definition before use, restricting operator definitions and omitting garbage collection. ALGOL 68G by M. van der Veer implements a usable Algol68 interpreter for today's computers and operating systems. A minor restriction is that formatted transput is still not conforming to the Revised Report. ReferencesExternallinks
|
|
|
This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License. |
|
| © 2008 Chamas Enterprises Inc. |