Category:ALGOL 68: Difference between revisions

Content added Content deleted
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"
* soft - deproceduring
! Context name !! Coercions applied in this context !! Context location !! Coercion examples
* weak - dereferencing or deproceduring, yielding a name
|-
* meek - dereferencing or deproceduring
|soft || deproceduring
* firm - meek, followed by uniting
|| The LHS of assignments, as in: <lang algol68>:=</lang>
* strong - firm, followed by widening, rowing or voiding
||

* 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
|-
of precision. For example: An INT will be coerced to a REAL, and a REAL will be
|weak || all ''soft'' above then weak dereferencing
coerced to a LONG REAL. But not vice-versa. Examples:
||
* INT to REAL
* Primaries of slices
* REAL to COMPL
* Secondaries of selections, as in: <lang algol68>OF</lang>
* BITS to []BOOL
||
* BYTES to STRING
<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))
||
<lang algol68>REF REF REF REAL to REAL</lang>
|-
|firm || all ''meek'' then uniting
||
*Operands of formulas
*Parameters of transput calls
|| e.g. <lang algol68>UNION(INT,REAL) var := 1</lang>
|-
||strong
|| all ''firm'' followed by widening, rowing or voiding
||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
||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:
A variable can also be coerced (rowed) to an array of length 1. For example:
* INT to [1]INT
<lang algol68>INT to [1]INT
* REAL to [1]REAL etc
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]].
* REF REF REAL to REAL

== Code Specimen ==
== Code Specimen ==
{{language programming paradigm|Concurrent}}
{{language programming paradigm|Concurrent}}