Anonymous user
Category:ALGOL 68: Difference between revisions
→Coercion (casting): more details
m (→Grammar: http://www.softwarepreservation.org/projects/ALGOL/book/Lindsey_van_der_Meulen-IItA68-Revised-SyntaxOnly.pdf/view) |
(→Coercion (casting): more details) |
||
Line 143:
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:
{|class="wikitable"
* soft - deproceduring▼
! Context name !! Coercions applied in this context !! Context location !! Coercion examples
|-
|| 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>
|-
of precision. For example: An INT will be coerced to a REAL, and a REAL will be▼
|weak || all ''soft'' above then weak dereferencing
||
* 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))
||
|-
|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
▲||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
A variable can also be coerced (rowed) to an array of length 1. For example:
|}
For more details about Primaries and Secondaries refer to [[Operator_precedence#ALGOL_68|Operator precedence]].
▲* REF REF REAL to REAL
== Code Specimen ==
{{language programming paradigm|Concurrent}}
|