Category:ALGOL 68: Difference between revisions

(→‎Code samples: Renamed, made expanable/collapsible)
 
(28 intermediate revisions by 2 users not shown)
Line 7:
|compat=structural
|checking=both
|tags=algol68
|LCT=yes}}
ALGOL 68 (short for ALGOrithmic Language 1968) is an [[imperative programming|imperative]] computer programming language that was conceived as a successor to the ALGOL 60 programming language, designed with the goal of a much wider scope of application and more rigorously defined syntax and semantics.
Line 20 ⟶ 21:
#* Loop optimization,
#* Representations - in minimal & larger character sets.
<br><br>
 
==Execute an ALGOL 68 program online==
* http://www.compileonline.com/execute_algol_online.php
* Algol 68G is available as one of the languages at https://tio.run
 
==Tasks not implemented in ALGOL 68==
[[Tasks not implemented in ALGOL 68]]
 
==Grammar==
The grammarformal definition forof ALGOLAlgol 68 is officiallygiven inby thea two"Two-Level" level,or [[wp:Van Wijngaarden grammar|"Van Wijngaarden" grammar]] but a subset has been done in the one level [[wp:Backus–Naur Form|Backus–Naur Form]]:.
This specifies much more than "just" the syntax and includes such semantic details as the requirement of identifiers to be declared, the necessary type checking and coercions to be applied, etc. The degree of precision allowed by the grammar came at the cost of increased complexity relative to Backus Naur Form, which was used to define [[ALGOL 60]]. It is recomended that less formal material (such as the books mentioned under "Resources" below) be consulted before delving into the Revised Report.
* [[wp:Van Wijngaarden grammar|Van Wijngaarden grammar]]: [http://www.fh-jena.de/~kleine/history/languages/Algol68-ReportAttachement.pdf]
<br>
* [[wp:Backus–Naur Form|Backus–Naur Form]]/[[wp:Yacc|Yacc]]: [http://wwwmathlabo.univ-poitiers.fr/~maavl/algol68/syntax68]
<br>
*A syntax chart is available [http://www.softwarepreservation.org/projects/ALGOL/book/Lindsey_van_der_Meulen-IItA68-Revised-SyntaxOnly.pdf/view Syntax Chart (Size 516.6 kB - File type application/pdf)here]
 
==Resources==
* [http://archive.computerhistory.org/resources/text/algol/algol_bulletin ALGOL BULLETIN] - March 1959 to August 1988, in 52 issues[http://archive.computerhistory.org/resources/text/algol/algol_bulletin]
* [https://lists.sourceforge.net/lists/listinfo/algol68-user Algol68 mailinglist] - December 2008 - algol68-user AT lists.sourceforge.net[https://lists.sourceforge.net/lists/listinfo/algol68-user]
* Algol68 group at linked: [http://www.linkedin.com/groups/Algol68-2333923 Algol68 group at linkedin] - includes various famous compiler composers.
<br>
'''Books available online''':
* [http://jmvdveer.home.xs4all.nl/algol68gen.pdfalgol-68-genie.html Algol 68G Manual - By Marcel van der Veer] Includes the Revised Report
* [http://www.softwarepreservation.org/projects/ALGOL/book/pame.2008.a4.pdf/view Programming Algol 68 Made Easy - by Sian Mountbatten (on softwarepreservation.org)]
* [http://www.softwarepreservation.org/projects/ALGOL/book/Lindsey_van_der_Meulen-IItA68-Revised.pdf/view Informal Introduction to Algol 68 - by C. H. Lindsey & S. V. Van der Meulen (on softwarepreservation.org)] - if you prefer (and find) a hardcopy, be sure to get the 1977 edition. Highly recomended!
 
<br>
FYI: There are two online manual pages:
'''Editor modes''':
* [http://jmvdveer.home.xs4all.nl/algol68g.pdf Algol 68G Manual - By Marcel van der Veer]
* [http://www.poenikatujemarch.co.uk/algol68net/a68-mode.el ProgrammingEmacs mode] for Algol 68 Made Easysupporting -syntax Sianhighlighting Mountbatten]and context-sensitive indentation.
 
Or - if you prefer a hardcopy - you can try and pick up a hard cover manual like "''Informal Introduction to Algol 68''" - by C. H. Lindsey & S. V. Vander Meulen. Be sure to get the 1977 edition:
* [http://www.amazon.com/gp/offer-listing/0720405041/ref=dp_olp_used?ie=UTF8&condition=used www.amazon.com] - Aboout $119
* [http://search.barnesandnoble.com/Informal-Introduction-to-ALGOL-68/C-H-Lindsey/e/9780720407266/?itm=3&USRI=Informal+Introduction+to+Algol+68 barnesandnoble.com] - about $40
IItA68 is a beautiful book, and makes great "bedtime" reading... Highly recommended!
* '''NEW:''' [http://www.softwarepreservation.org/projects/ALGOL/book/Lindsey_van_der_Meulen-IItA68-Revised.pdf softwarepreservation.org has an on-line IItA68 PDF] ready for download.
 
Editor modes:
* [http://www.jemarch.net/a68-mode Emacs mode] for Algol 68 supporting syntax highlighting and context-sensitive indentation.
* [http://www.vim.org/scripts/script.php?script_id=1927 Vim script] providing support for syntax highlighting.
* '''NEW:''' [http://qbnz.com/highlighter/demo.php GeSHi syntax highlighting]
* [https://marketplace.visualstudio.com/items?itemName=jlguenego.algol68 VS-Code Algol 68 syntax highlighting]
 
==Status==
Line 64 ⟶ 68:
*Dec. 1968: Report on the Algorithmic Language ALGOL 68 - Offprint from Numerische Mathematik, 14, 79-218 (1969); Springer-Verlag. - Edited by: A. van Wijngaarden, B.J. Mailloux, J.E.L. Peck and C.H.A. Koster.
*Sep 1973: Revised Report on the Algorithmic Language Algol 68 - Springer-Verlag 1976 - Edited by: A. van Wijngaarden, B.J. Mailloux, J.E.L. Peck, C.H.A. Koster, M. Sintzoff, C.H. Lindsey, L.G.L.T. Meertens and R.G. Fisker.
==Coding style of samples, alphabets and stropping==
Click "Expand" for more details.
<div class="mw-collapsible mw-collapsed" style="width:1200px880px; overflow:auto; background-color:parent;">
<div class="mw-collapsible-content" style="padding-left:2em;">
 
Line 71 ⟶ 76:
 
On some compilers, it may be necessary to include appropriate "job cards"
or precludespreludes in order for the programs to compile successfully. Hopefully
not too much else is required. Examples:
{|border="1" style="border-collapse: collapse; border: 5px double grey;" align="center"
Line 92 ⟶ 97:
FINISH
|}
<br><br>'''Alphabets'''
===Example of different program representations===
<br><br>
Notionally, Algol 68 source is written in two alphabets. The reserved words, mode indicants (type names) and operators that are non-symbolic (.e.g. '''and''', '''or''', ...) are generally referred to as "bold words" and usually shown in a bold font in literature. Words that are identifiers (used for "variable" names, procedure names, structure member names, ...) are in a separate, non-bold font.<br>
The [https://www.softwarepreservation.org/projects/ALGOL/manual/a68s.txt/view Manual for CMU ALGOL 68S (on softwarepreservation.org)] refers to the non-bold words as being in timid face.
===Example<br><br>'''Examples of different program representations==='''
<br><br>
At the time when ALGOL 68 was defined some predominant computers had
24 or 36 bit words, with 6 bit character sets. Hence it was desirable that
ALGOL 68 should be able to run on machines with only uppercase.
As multiple fonts were generally unavailable, a method of identifying the bold words was required.<br>
The official spec provided for different representations of the same
program.
program. Quote stropping (enclosing the bold words in single quotes)
and Point stropping (preceeding the bold words with a dot)
were used.<br>
were used. A variant of Point stropping called RES stropping was also defined.
In RES stropping some language-defined bold words are not preceded by a dot. <br>
A pragmatic comment may have been required to indicate which
stropping convention was to be used, as in some of the examples below.<br>
Upper stropping (representing the bold words by upper case and
non-bold words in lower case) was introduced by Algol 68R. Upper stropping<br>
Upper stropping is used by Algol 68RS and is one of the options for Algol 68G.<br>
Rutgers ALGOL 68 uses quote stropping. Most of the samples<br>
Most of the samples on Rosetta Code use Upper stropping.<br><br>
Examples (pragmatic comments to set the stropping regime not shown):
Example:
{|border="1" style="border-collapse: collapse; border: 5px2px double grey;" align="centerleft"
|| Algol68 as typically published
¢ bold/underline typeface ¢
'''mode''' '''xint''' = '''int''';
'''xint''' sum sq:=0;
Line 119 ⟶ 131:
sum sq+:=i↑2
'''od'''
|| quoteQUOTE stropping (similar to wiki)
'pr' quote 'pr'
'mode' 'xint' = 'int';
'xint' sum sq:=0;
Line 128 ⟶ 139:
sum sq+:=i↑2
'od'
|| POINT stropping
|| 7-bit/ascii compiler
.PR UPPER .PR
MODE XINT = INT;
XINT sum sq:=0;
FOR i WHILE
sum sq/=70*70
DO
sum sq+:=i**2
OD
|| 6-bits/byte compiler
.PR POINT .PR
.MODE .XINT = .INT;
.XINT SUM SQ:=0;
Line 147 ⟶ 148:
.OD
|| RES stropping
.PR RES .PR
mode .xint = int;
.xint sum sq:=0;
Line 156:
od
|| Upper stropping
# upper case = bold #
MODE XINT = INT;
XINT sum sq:=0;
Line 169 ⟶ 168:
 
== Coercion (casting) ==
ALGOL 68 has a hierarchy of contexts which determine which kind of coercions are available at a particular point in the program.
<br>
coercions are available at a particular point in the program.
Click "Expand" for more details.
<div class="mw-collapsible mw-collapsed" style="width:1000px880px; overflow:auto; background-color:parent;">
<div class="mw-collapsible-content" style="padding-left:2em;">
 
Line 197:
g
||Right hand side of:
* Identity-declarations, as "~" in: <langsyntaxhighlight algol68>REAL x = ~</langsyntaxhighlight>
* Initialisations, as "~" in: <langsyntaxhighlight algol68>REAL x := ~</langsyntaxhighlight>
Also:
* Actual-parameters of calls, as "~" in:<langsyntaxhighlight algol68>PROC: sin(~)</langsyntaxhighlight>
* Enclosed clauses of casts, as "~" in: <langsyntaxhighlight algol68>REAL(~)</langsyntaxhighlight>
* Units of routine-texts
* Statements yielding VOID
* All parts (but one) of a balanced clause
* One side of an identity relation, as "~" in: <langsyntaxhighlight algol68> ~ IS ~</langsyntaxhighlight>
|bgcolor=aaaaff rowspan=4 width="50px"| deproc- eduring
|bgcolor=aaeeaa rowspan=3 width="50px"| all '''soft''' then weak deref- erencing
Line 213:
|colspan=1 bgcolor=ffcccc|
Widening occurs if there is no loss of precision. For example: An INT will be coerced to a REAL, and a REAL will be coerced to a LONG REAL. But not vice-versa. Examples:
<langsyntaxhighlight algol68>INT to LONG INT
INT to REAL
REAL to COMPL
BITS to []BOOL
BYTES to STRING</langsyntaxhighlight>
A variable can also be coerced (rowed) to an array of length 1.
 
For example:
<langsyntaxhighlight algol68>INT to [1]INT
REAL to [1]REAL</langsyntaxhighlight> etc
|-
!F<br>
Line 229:
m
||
*Operands of formulas as "~" in:<langsyntaxhighlight algol68>OP: ~ * ~</langsyntaxhighlight>
*Parameters of transput calls
|colspan=3 bgcolor=ffcc99| Example:
<langsyntaxhighlight algol68>UNION(INT,REAL) var := 1</langsyntaxhighlight>
|-
!M<br>
Line 241:
* Trimscripts (yielding INT)
* Enquiries: e.g. as "~" in the following
<langsyntaxhighlight algol68>IF ~ THEN ... FI</langsyntaxhighlight> and
<langsyntaxhighlight algol68>FROM ~ BY ~ TO ~ WHILE ~ DO ... OD etc</langsyntaxhighlight>
* Primaries of calls (e.g. sin in sin(x))
|colspan=4 bgcolor=ffee99|Examples:
<langsyntaxhighlight algol68>REF REF BOOL to BOOL
REF REF REF INT to INT</langsyntaxhighlight>
|-
!W<br>
Line 253:
k
||
* Primaries of slices, as in "~" in: <langsyntaxhighlight algol68>~[1:99]</langsyntaxhighlight>
* Secondaries of selections, as "~" in: <langsyntaxhighlight algol68>value OF ~</langsyntaxhighlight>
|colspan=5 bgcolor=aaeeaa|Examples:
<langsyntaxhighlight algol68>REF BOOL to REF BOOL
REF REF INT to REF INT
REF REF REF REAL to REF REAL
REF REF REF REF STRUCT to REF STRUCT</langsyntaxhighlight>
|-
!S<br>
Line 265:
f<br>
t
|| The LHS of assignments, as "~" in: <langsyntaxhighlight algol68>~ := ...</langsyntaxhighlight>
|colspan=6 bgcolor=aaaaff| Example:
* deproceduring of: <langsyntaxhighlight algol68>PROC REAL random: e.g. random</langsyntaxhighlight>
|}
For more details about Primaries and Secondaries refer to [[Operator_precedence#ALGOL_68|Operator precedence]].
Line 284:
 
== Library code used in Rosetta Code samples ==
[https://rosettacode.org/wiki/Category:ALGOL_68-primes/prelude PrimeVarious related(including the standard prelude)]<br/>
[https://rosettacode.org/wiki/Category:ALGOL_68-primes Prime related]<br/>
<br>
[https://rosettacode.org/wiki/Category:ALGOL_68-rows Row (array) related]<br/>
[https://rosettacode.org/wiki/Category:ALGOL_68-l-system L-System related]
 
== Tools ==
[[Syntax_highlighting_using_Mediawiki_formatting#ALGOL 68|Format an upper-stropped Algol 68 source with Mediawiki markup]]<br/>
[[Compiler/Simple_file_inclusion_pre_processor#ALGOL 68|Implement ''read'' and ''include'' pragmatic-comments for compilers that don't support file inclusion]]
 
{{language programming paradigm|Concurrent}}
3,028

edits