Algol-68D Summary ----------------- Version 1 02-07-12 MODES ----- Predefined modes are INT (32-bit signed twos complement) BOOL (8-bits with value 0 or 1) REAL (64-bit IEEE float) CHAR (8-bit ASCII) Defining new modes (AMODE is any mode) REF AMODE Reference to given mode. You can think of this as a pointer to an amode value, or a variable of type AMODE (these notions are the same in A68D). [expr]AMODE [expr:expr]AMODE []AMODE These declare a one dimensional array. The expr values are expressions that are of mode INT (or can be coerced to INT) and represent the bounds. In the first form, the lower bound is 1. The expr values are evaluated when the mode is declared. The form with no bounds is used only for procedure formal modes, where it indicates that the bounds are passed in as parameters. STRUCT (AMODE field, field, AMODE field, ....) Declares a struct type (record type) with given fields. A restriction is that if row (array) modes appear as field modes, then they must have fixed bounds known at compile time (explicit integers). UNION (AMODE, AMODE, AMODE, ...) A union mode, values can be of any of the given modes, and the value is stored with an implicit tag showing what kind of value is stored currently. The Mode declaration gives a name to a mode, e.g. MODE PTR = REF INT; Mode names have upper case letters and digits, and start with an upper case letter. DECLARATIONS ------------ Form of declaration is AMODE xy = expression where expression is of mode AMODE. The effect is to bind the name xy to the given expression. Identifiers have lower case letters and digits, and start with a lower case letter. ASSIGNMENTS ----------- An assignment has the form: expr := expr where the expr on the left has mode REF AMODE, and the expr on the right has mode AMODE, the effect is to assign the given value to the referenced cell, and the result is the REF AMODE value. ALLOCATORS ---------- Allocators are expressions that allocate space for a value and return a reference to the created space. LOC AMODE creates space on the local stack frame for a value of mode AMODE. HEAP AMODE creates space on the garbage collected heap for a value of mode AMODE. These allocators return a value of REF AMODE, so they are suitable for use on the left side of an assignment for example: LOC INT := 3; Most often the allocators are used in declarations as in REF INT xx = LOC INT uninitialized integer variable REF INT xx = LOC INT := 3 initialized integer variable A short hand is permitted AMODE xyz means REF AMODE xyz = LOC AMODE AMODE xyz := expr means REF AMODE xyz = LOC AMODE := expr EXPRESSIONS ----------- Literals 12 14.0 3.1E-5 TRUE FALSE SKIP, undefined value of appropriate mode NIL, pointer to no value (of type REF any mode) Arithmetic operators expr + expr expr - expr expr * expr expr / expr + expr - expr ABS expr Also: expr +:= (plus and becomes) Logical operators (operate on BOOL) expr AND expr expr OR expr expr Short circuiting expr ANDTH expr expr OREL expr Arithmetic comparison operators = < > >= <= /= Pointer comparison IS ISNT Selection from structure next OF expr where expr is of mode STRUCT AMODE, and next is one of the field names in this mode. Subscripting an array aexpr [sexpr] sexpr is of mode INT, aexpr is a row mode, the effect is to yield the corresponding value. Slicing an array aexpr [expr Control Structures ------------------ A series is a a sequence of one or more declarations or expressions separated by semicolons. Evaluated left to right in sequence. Each value is computed and then discarded, except the last, which is the value of the series. Serial clause BEGIN series END ( series ) Collateral clause BEGIN expr, expr, expr ... , expr END ( expr, expr, expr ... , expr ) The expressions are evaluated in any order, or even in parallel. The result is either VOID, or it can be a STRUCT value for a STRUCT whose field values match the modes of the expressions. IF series THEN series ELSE series FI ( series | series | series ) IF series THEN series ELIF series THEN series ... ELSE series THEN series FI ( series | series |: series | series | series | series FI FOR idf FROM series BY series TO series WHILE series DO series OD The loop counter, idf, is of mode INT (not REF INT) and its declaration is created by (and local to) the loop. It is effectively re-declared on each iteration and can not be modified from within the loop. Any declarations in the subclause between the WHILE and DO are visible in the subclause between the DO and OD. The yield of a loop clause is void. Case Conformity Clause CASE series IN (AMODE idf): series (AMODE idf): series OUT series ESAC COMMENTS -------- Comments are {text} COERCIONS --------- Uniting AMODE => UNION(AMODE, ...) Dereference REF AMODE => AMODE Rowing AMODE => []AMODE Voiding AMODE => VOID