Category:ALGOL 68: Difference between revisions
m (→Grammar: http://www.softwarepreservation.org/projects/ALGOL/book/Lindsey_van_der_Meulen-IItA68-Revised-SyntaxOnly.pdf/view) |
(→Coercion (casting): more details) |
||
Line 143: | Line 143: | ||
ALGOL 68 has a hierarchy of contexts which determine which kind of |
ALGOL 68 has a hierarchy of contexts which determine which kind of |
||
coercions are available at a particular point in the program. These contexts are: |
coercions are available at a particular point in the program. These contexts are: |
||
{|class="wikitable" |
|||
⚫ | |||
! Context name !! Coercions applied in this context !! Context location !! Coercion examples |
|||
* weak - dereferencing or deproceduring, yielding a name |
|||
|- |
|||
* meek - dereferencing or deproceduring |
|||
⚫ | |||
* firm - meek, followed by uniting |
|||
|| The LHS of assignments, as in: <lang algol68>:=</lang> |
|||
⚫ | |||
|| |
|||
* deproceduring of: <lang algol68>PROC REAL random: e.g. random</lang> |
|||
Depending on the context a MODE (type) will be coerced (widened) to another type if there is no loss |
|||
|- |
|||
⚫ | |||
|weak || all ''soft'' above then weak dereferencing |
|||
coerced to a LONG REAL. But not vice-versa. Examples: |
|||
|| |
|||
⚫ | |||
* Primaries of slices |
|||
⚫ | |||
* Secondaries of selections, as in: <lang algol68>OF</lang> |
|||
⚫ | |||
|| |
|||
⚫ | |||
<lang algol68>REF REF REF INT to REF INT</lang> |
|||
|- |
|||
|meek |
|||
|| all ''weak'' above then dereferencing |
|||
|| |
|||
* Trimscripts (yielding INT) |
|||
* Enquiries: e.g. "~" in the following<lang algol68>IF ~ THEN ... FI</lang> and <lang algol68>FROM ~ BY ~ TO ~ WHILE ~ DO ... OD etc</lang> |
|||
* Primaries of calls (e.g. sin in sin(x)) |
|||
|| |
|||
⚫ | |||
|- |
|||
|firm || all ''meek'' then uniting |
|||
|| |
|||
*Operands of formulas |
|||
*Parameters of transput calls |
|||
|| e.g. <lang algol68>UNION(INT,REAL) var := 1</lang> |
|||
|- |
|||
||strong |
|||
⚫ | |||
||Right hand side of: |
|||
* Identity-declarations :=: |
|||
* Initialisations |
|||
Also: |
|||
* Actual-parameters of calls |
|||
* Enclosed clauses of casts |
|||
* Units of routine-texts |
|||
* Statements yielding VOID |
|||
* All parts (but one) of a balanced clause |
|||
* One side of an identity relation |
|||
⚫ | |||
<lang algol68>INT to LONG INT |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
A variable can also be coerced (rowed) to an array of length 1. For example: |
A variable can also be coerced (rowed) to an array of length 1. For example: |
||
<lang algol68>INT to [1]INT |
|||
REAL to [1]REAL</lang> etc |
|||
|} |
|||
Pointers are followed (dereferenced), For example: |
|||
For more details about Primaries and Secondaries refer to [[Operator_precedence#ALGOL_68|Operator precedence]]. |
|||
⚫ | |||
== Code Specimen == |
== Code Specimen == |
||
{{language programming paradigm|Concurrent}} |
{{language programming paradigm|Concurrent}} |
Revision as of 11:21, 23 April 2013
This programming language may be used to instruct a computer to perform a task.
Parameter passing methods: | By reference, By value |
---|---|
Type safety: | Safe |
Type strength: | Soft, weak, meek, firm and strong - depending on context. |
Type compatibility: | Structural |
Type expression: | Explicit |
Type checking: | Dynamic, Static |
See Also: |
ALGOL 68 (short for ALGOrithmic Language 1968) is an 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.
The main aims and principles of design of ALGOL 68:
- Completeness and clarity of design,
- Orthogonal design,
- Security,
- Efficiency:
- Static mode checking,
- Mode-independent parsing,
- Independent compilation,
- Loop optimization,
- Representations - in minimal & larger character sets.
Execute an ALGOL 68 program online
Grammar
The grammar for ALGOL 68 is officially in the two level, Van Wijngaarden grammar but a subset has been done in the one level Backus–Naur Form:
- Van Wijngaarden grammar: [1]
- Backus–Naur Form/Yacc: [2]
- Syntax Chart (Size 516.6 kB - File type application/pdf)
Resources
- ALGOL BULLETIN - March 1959 to August 1988, in 52 issues[3]
- Algol68 mailinglist - December 2008 - algol68-user AT lists.sourceforge.net[4]
FYI: There are two online manual pages:
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:
- www.amazon.com - Aboout $119
- barnesandnoble.com - about $40
IItA68 is a beautiful book, and makes great "bedtime" reading... Highly recommended!
Editor modes:
- Emacs mode for Algol 68 supporting syntax highlighting and context-sensitive indentation.
- Vim script providing support for syntax colouring.
Status
- 20th December 1968 - ALGOL 68's Final Report was ratified by UNESCO's IFIP working group 2.1 in Munich.
- 20th December 2008 - Zig Zag - the 100th ALGOL 68 code contribution on rosettacode.org!
- Happy 40th Birthday ALGOL 68,
- AND 50th Birthday ALGOL 58.
- 23rd August 2009 - algol68g-1.18.0-9h released
- 20th December 2009 - Happy 51st/41st Birthdays with Hamming numbers - the 200th ALGOL 68 code contribution on rosettacode.org!
- This time code was by Marcel van der Veer, author of Algol 68 Genie
- 25th October 2011 - Jejones3141 added Soundex - the 300th ALGOL 68 code specimen.
Revisions
- Mar. 1968: Draft Report on the Algorithmic Language ALGOL 68 - Edited by: A. van Wijngaarden, B.J. Mailloux, J.E.L. Peck and C.H.A. Koster.
- Oct. 1968: Penultimate Draft Report on the Algorithmic Language ALGOL 68 - Chapters 1-9 - Edited by: A. van Wijngaarden, B.J. Mailloux, J.E.L. Peck and C.H.A. Koster.
- 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.
Code samples
Most of the code samples provided here have a leading main:(
and a matching )
at the end. These are not actually required in the language, but are included so as to highlight that the code sample is complete, and works with (at least) ALGOL 68G unmodified.
On some compilers, it may be necessary to include appropriate "job cards" or precludes in order for the programs to compile successfully. Hopefully not too much else is required. Examples:
Brief Algol68 | Algol68 as in rosettacode | Actual ELLA Algol 68RS code |
print(("Hello, world!",new line)) |
main:( print(("Hello, world!",new line)) ) |
PROGRAM helloworld CONTEXT VOID USE standard BEGIN print(("Hello, world!", new line)) END FINISH |
Example of different program representations
At the time when ALGOL 68 was defined some predominant computers had 36 bit words, and 6 bit character sets. Hence it was desirable that ALGOL 68 should be able to run on machines with only uppercase. Hence the official spec provided for different representations of the same program. Example:
Algol68 as typically published
¢ bold/underline typeface ¢ mode xint = int; xint sum sq:=0; for i while sum sq≠70×70 do sum sq+:=i↑2 od |
quote stropping (similar to wiki)
'pr' quote 'pr' 'mode' 'xint' = 'int'; 'xint' sum sq:=0; 'for' i 'while' sum sq≠70×70 'do' sum sq+:=i↑2 'od' |
Code for a 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 |
Code for a 6-bits/byte compiler
.PR POINT .PR .MODE .XINT = .INT; .XINT SUM SQ:=0; .FOR I .WHILE SUM SQ .NE 70*70 .DO SUM SQ .PLUSAB I .UP 2 .OD |
Algol68 using RES stropping
.PR RES .PR mode .xint = int; .xint sum sq:=0; for i while sum sq≠70×70 do sum sq+:=i↑2 od |
Coercion (casting)
ALGOL 68 has a hierarchy of contexts which determine which kind of coercions are available at a particular point in the program. These contexts are:
Context name | Coercions applied in this context | Context location | Coercion examples |
---|---|---|---|
soft | deproceduring | The LHS of assignments, as in: <lang algol68>:=</lang> |
|
weak | all soft above then weak dereferencing |
|
<lang algol68>REF REF REF INT to REF INT</lang> |
meek | all weak above then dereferencing |
|
<lang algol68>REF REF REF REAL to REAL</lang> |
firm | all meek then uniting |
|
e.g. <lang algol68>UNION(INT,REAL) var := 1</lang> |
strong | all firm followed by widening, rowing or voiding | Right hand side of:
Also:
|
Widening occures 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:
<lang algol68>INT to LONG INT INT to REAL REAL to COMPL BITS to []BOOL BYTES to STRING</lang> A variable can also be coerced (rowed) to an array of length 1. For example: <lang algol68>INT to [1]INT REAL to [1]REAL</lang> etc |
For more details about Primaries and Secondaries refer to Operator precedence.
Code Specimen
Subcategories
This category has the following 3 subcategories, out of 3 total.
@
- ALGOL 68 Implementations (9 P)
- ALGOL 68 User (8 P)
Pages in category "ALGOL 68"
The following 200 pages are in this category, out of 1,021 total.
(previous page) (next page)N
O
- O'Halloran numbers
- Object serialization
- Odd and square numbers
- Odd squarefree semiprimes
- Odd word problem
- Odd words
- Old lady swallowed a fly
- Old Russian measure of length
- One of n lines in a file
- One-dimensional cellular automata
- One-two primes
- Operator precedence
- Optional parameters
- Orbital elements
- Order two numerical lists
- Ordered words
- Ormiston pairs
- Overloaded operators
- Own digits power sum
P
- Padovan n-step number sequences
- Padovan sequence
- Pairs with common factors
- Palindrome dates
- Palindrome detection
- Palindromic primes
- Palindromic primes in base 16
- Pan base non-primes
- Pandigital prime
- Pangram checker
- Parse EBNF
- Parsing/RPN calculator algorithm
- Parsing/RPN to infix conversion
- Parsing/Shunting-yard algorithm
- Partial function application
- Partition an integer x into n primes
- Pascal matrix generation
- Pascal's triangle
- Pascal's triangle/Puzzle
- Pathological floating point problems
- Peano curve
- Pell numbers
- Pell's equation
- Penta-power prime seeds
- Percolation/Mean run density
- Perfect numbers
- Perfect shuffle
- Perfect totient numbers
- Periodic table
- Perlin noise
- Permutations
- Permutations by swapping
- Permutations with repetitions
- Pernicious numbers
- Phrase reversals
- Pi
- Pick random element
- Pierpont primes
- Piprimes
- Pisano period
- Playing cards
- Plot coordinate pairs
- Pointers and references
- Polymorphic copy
- Polymorphism
- Polynomial derivative
- Polynomial long division
- Polynomial regression
- Population count
- Positive decimal integers with the digit 1 occurring exactly twice
- Power set
- Practical numbers
- Pragmatic directives
- Price fraction
- Primality by trial division
- Primality by Wilson's theorem
- Prime conspiracy
- Prime decomposition
- Prime numbers p for which the sum of primes less than or equal to p is prime
- Prime numbers which contain 123
- Prime numbers whose neighboring pairs are tetraprimes
- Prime reciprocal sum
- Prime triangle
- Prime triplets
- Prime words
- Primes which contain only one odd digit
- Primes whose first and last number is 3
- Primes whose sum of digits is 25
- Primes with digits in nondecreasing order
- Primes: n*2^m+1
- Print itself
- Probabilistic choice
- Problem of Apollonius
- Product of divisors
- Product of min and max prime factors
- Program name
- Program termination
- Proper divisors
- Pseudo-random numbers/Middle-square method
- Pseudo-random numbers/PCG32
- Pseudo-random numbers/Splitmix64
- Pseudo-random numbers/Xorshift star
- Pythagorean quadruples
- Pythagorean triples
Q
R
- Radical of an integer
- Ramanujan primes
- Ramer-Douglas-Peucker line simplification
- Random Latin squares
- Random number generator (included)
- Random numbers
- Random sentence from book
- Range consolidation
- Range expansion
- Range extraction
- Ranking methods
- Rare numbers
- Ray-casting algorithm
- Read a file line by line
- Read a specific line from a file
- Read entire file
- Real constants and functions
- Reduced row echelon form
- Regular expressions
- Remove duplicate elements
- Remove lines from a file
- Remove vowels from a string
- Rename a file
- Rep-string
- Repeat
- Repeat a string
- Repunit primes
- Return multiple values
- Reverse a string
- Reverse words in a string
- Rhonda numbers
- Rice coding
- Riordan numbers
- Rock-paper-scissors
- Rodrigues’ rotation formula
- Roman numerals/Decode
- Roman numerals/Encode
- Roots of a function
- Roots of a quadratic function
- Roots of unity
- Rosetta Code/Rank languages by popularity
- Rot-13
- Round-robin tournament schedule
- RPG attributes generator
- RSA code
- Run-length encoding
- Runge-Kutta method
- Runtime evaluation
- Runtime evaluation/In an environment
- Ruth-Aaron numbers
S
- S-expressions
- Safe and Sophie Germain primes
- Safe primes and unsafe primes
- Sattolo cycle
- Scope modifiers
- Scope/Function names and labels
- Search a list
- Search a list of records
- SEDOLs
- Selective file copy
- Selectively replace multiple instances of a character within a string
- Self numbers
- Self-describing numbers
- Self-hosting compiler
- Semiprime
- Semordnilap
- SEND + MORE = MONEY
- Separate the house number from the street name
- Sequence of non-squares
- Sequence of primes by trial division
- Sequence of primorial primes
- Sequence: nth number with exactly n divisors
- Sequence: smallest number greater than previous term with exactly n divisors
- Sequence: smallest number with exactly n divisors
- Set
- Seven-sided dice from five-sided dice
- Shell one-liner
- Shift list elements to left by 3
- Shoelace formula for polygonal area
- Short-circuit evaluation
- Shortest common supersequence
- Show ASCII table
- Show the (decimal) value of a number of 1s appended with a 3, then squared
- Sierpinski arrowhead curve
- Parameter passing/By reference
- Parameter passing/By value
- Typing/Safe
- Typing/Soft, weak, meek, firm and strong - depending on context.
- Typing/Compatibility/Structural
- Typing/Expression/Explicit
- Typing/Checking/Dynamic
- Typing/Checking/Static
- Programming Languages
- Programming paradigm/Concurrent
- Programming paradigm/Imperative