home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
SIMTEL
/
CPMUG
/
CPMUG028.ARK
/
USRMAN.TXT
< prev
next >
Wrap
Text File
|
1984-04-29
|
25KB
|
1,499 lines
ALGOL-M LANGUAGE REFERENCE MANUAL
This section describes the various elements of the ALGOL-M
language.
The format of the element will be shown, followed by a description
and examples of use. The following notation is used:
Braces {} indicate an optional entry.
A vertical bar | indicates alternate choices, one of
which must appear.
Elipses "..." indicate that the preceding item may
be optionally repeated.
Reserved words are indicated by capital letters.
Reserved words and other special symbols must appear as
shown.
Items appearing in small letters are elements of the
language which are defined and explained elsewhere in
the language manual.
arithmetic expression
ELEMENT:
arithmetic expression
FORMAT:
integer|decimal
variable
{(} arithmetic expression binary operator
arithmetic expression {)}
{(} unary operator arithmetic expression {)}
DESCRIPTION:
Operators in ALGOL-M have an implied precedence which is
used to determine the manner in which operators and
operands are grouped. A-B/C causes the result of B divided
by C to be subtracted from A. In this case B is considered
to be "bound" to the "/" operator instead of the "-"
operator which causes the division to be performed first.
The implied precedence binds operands to the adjacent
operator of highest precedence. The implied precedence of
operators is as follows:
unary -,+
**
*,/
+,-
Parentheses can be used to override the implied precedence
in the same way as they are used in ordinary algebra. Thus
the expression (A-B)/C will cause B to be subtracted from A
and the result divided by C.
EXAMPLE:
(X + Y) * (Z * Y + X) ** 2
X + Y + Z * X * Y * Z / 5.456 + I
ARRAY declaration
ELEMENT:
ARRAY declaration
FORMAT:
INTEGER|DECIMAL|STRING {(expression)} ARRAY
identifier ... bound pair list {,identifier}
DESCRIPTION:
The array declaration dynamically allocates storage for
arrays. The optional integer expression indicates the
length of each array element. For strings, the maximum
length is 255 characters and for decimals the maximum
length is 18 digits. Integer lengths are not specified
since storage adequate to represent all integer values
between -16,383 and +16,383 is automatically allocated.
Arrays are not automatically initialized to zero.
EXAMPLE:
INTEGER ARRAY X[0:5,0:5];
DECIMAL(10) ARRAY X,Y[3:6,5:10];
STRING ARRAY WORDS[Y+3:12];
STRING(20) WORD[0:X+5,5:10,15:20];
assignment statement
ELEMENT:
assignment statement
FORMAT:
variable := {variable :=} ... expression
DESCRIPTION:
The expression is evaluated and stored into the variable.
The types of permissible assignments are indicated by the
following table:
expression
integer decimal string
integer yes no no
variable decimal yes yes no
string no no yes
Multiple assignments are allowed with the expression being
assigned to all of the listed variables.
EXAMPLE:
X := Y + Z;
Y[1] := Y[2] := 50;
assignment on the fly
ELEMENT:
assignment on the fly
FORMAT:
( variable := { variable := } ... expression )
DESCRIPTION:
Algol-m allows a special form of the assignment statement
known as assignment on the fly. This form of an assignment
statement can be used anywhere an expression is allowed.
The expression to the right of the := symbol is evaluated
and then stored into the variable on the left. The value
of the entire expression is the same as that of it's right
half. The only difference is the side-effect of storing the
intermediate result into the variable on the left. These
intermediate results can then be used at a later point in
the program without re-calculating them.
EXAMPLE:
A:= (B:=C + 5) * 2;
IF (B:=C:=D+5) > 10 THEN
WRITE(B);
balanced statement
ELEMENT:
balanced statement
FORMAT:
{label definition} simple statement
{label definition} IF boolean expression THEN balanced
statement ELSE balanced statement
DESCRIPTION:
If the boolean expression is true, the balanced statement
to the left of the ELSE is executed. If the boolean
expression is false, the balanced statement to the right of
the ELSE is executed.
EXAMPLE:
IF A < B THEN A := 1 ELSE A := 2;
IF B = C THEN
BEGIN
WRITE(B);
B := B + 1;
END
ELSE
BEGIN
WRITE(C);
C := C + 1;
END;
PROGRAMMING NOTE:
A semicolon is not allowed after the statement immediately
preceding an ELSE.
block
ELEMENT:
block
FORMAT:
BEGIN {declaration;} ... statement; ... END;
DESCRIPTION:
The block is the foundation of the ALGOL-M language. Each
time a new block is entered new variables may be declared.
These variables are unique in the sense that a variable X
declared in two different blocks represents two different
variables. All storage within a block is dynamic and
allocated when the block is entered and de-allocated when
the block is departed. A block can be used any place a
simple statement can be used.
EXAMPLE:
BEGIN
X := 1;
Y := 2;
END;
IF X = Y THEN
BEGIN
INTEGER X,Y;
X := 3;
Y := 4;
END;
PROGRAMMING NOTE:
Declarations may not appear in case blocks. The final END,
which matches the initial program BEGIN, is not followed by
a semicolon.
boolean expression
ELEMENT:
boolean expression
FORMAT:
NOT boolean expression
boolean expression OR boolean expression
boolean expression AND boolean expression
{(} expression =|<|>|>=|<=|<> expression {)}
DESCRIPTION:
Integer-integer, decimal-integer, decimal-decimal,
integer-decimal, and string-string comparisons are allowed
in ALGOL-M. For integer-decimal and decimal-integer
comparisons the integer value is converted to a decimal
value prior to comparison. The result of a comparison of
numerical values is based on the size of the numbers. The
result of a comparison of string values depends on a
character-by-character comparison where the first instance
of a non-equal character establishes the boolean result.
The collating sequence of the ASCII character set is used
for string comparisons. Generally, numbers are followed by
upper case letters which are followed by lower case
letters.
EXAMPLE:
X > Y OR Y < Z;
(X = Y) AND (Y = Z OR Z = 10);
IF NOT X = 1 THEN WRITE("HELLO");
bound pair list
ELEMENT:
bound pair list
FORMAT:
[expression : expression{,expression : expression} ...]
DESCRIPTION:
Expressions in the bound pair list must be of type integer
and greater than or equal to zero. There can be no more
than 255 dimensions.
EXAMPLE:
[1:7,0:5]
[3:6,x:y]
[y*3:z,1:12]
CASE statement
ELEMENT:
CASE statement
FORMAT:
CASE expression OF
BEGIN
statement; ...
END;
DESCRIPTION:
The CASE statement allows the programmer to choose one of
several statements to be executed. The statement chosen
depends on the value of the integer expression. The first
statement is executed if the expression evaluates to zero.
If the value of the expression is greater than the number
of statements in the case block, the resulting action is
undefined.
EXAMPLE:
CASE X+Y OF
BEGIN
WRITE("CASE 0");
WRITE("CASE 1");
END;
constant
ELEMENT:
constant
FORMAT:
integer|decimal|string
DESCRIPTION:
A constant may be either an integer, decimal, or
string constant. Integer constants are numbers with
no decimal point ranging from -16383 to +16383.
Decimal constants are numbers with a decimal point and
may not exceed 18 digits in length. String constants
may be composed of any combination of alphanumeric and
special characters and may be up to 255 characters in length.
Strings entered from the console or disk may be either enclosed
in quotation marks or delimitd with commas. Strings used as
constants in the program must be enclosed in quotation marks.
EXAMPLE:
10
10.5678
"EXAMPLE ONE"
declaration
ELEMENT:
declaration
DESCRIPTION:
See FILE declaration, ARRAY declaration, simple
declaration, procedure declaration, and function
declaration.
expression
ELEMENT:
expression
FORMAT:
boolean expression|arithmetic expression
DESCRIPTION:
See arithmetic expression and boolean expression.
FILE declaration
ELEMENT:
FILE declaration
FORMAT:
FILE identifier {(expression)} {,identifier
{(expression)}} ...
DESCRIPTION:
The identifiers used in the FILE declaration are file
identifiers which reference actual file names. The actual
file names may be assigned at compile-time or at run-time.
The optional integer expression following the file
identifier is used to specify the record length in bytes
for blocked records.
EXAMPLE:
FILE TAPE1, TAPE2(128);
PROGRAMMING NOTE:
Blocked records are not implemented.
FOR statement
ELEMENT:
FOR statement
FORMAT:
{label definition} FOR assignment statement
STEP expression UNTIL expression DO simple statement
DESCRIPTION:
Execution of all statements within the simple statement are
repeated until the indexing variable is greater than or
equal to the value of the UNTIL expression. The indexing
variable is incremented by the amount specified in the STEP
expression and must be incremented by a positive amount.
The UNTIL and STEP expressions are evaluated on each loop.
EXAMPLE:
FOR I := 1 STEP 1 UNTIL 10 DO
X := Y;
FOR INDEX := X+Y STEP 2 UNTIL X*Y DO
BEGIN
A := A + B;
WRITE(A);
END;
function call
ELEMENT:
function call
FORMAT:
identifier {(expression {,expression} ...)}
DESCRIPTION:
Functions may appear as primary elements in arithmetic or
boolean expressions. Parameter passing is by value.
Functions may be called recursively with no limit to the
number of recursive calls allowed.
EXAMPLE:
X := RAND;
Y := SQRT(5.6);
C := FUNC * RND(2);
function declaration
ELEMENT:
function declaration
FORMAT:
INTEGER|DECIMAL|STRING FUNCTION identifier
{(identifier {,identifier} ...)}
{declaration; ...} simple statement;
DESCRIPTION:
A function declaration may or may not include parameters.
If parameters are included they must be declared before the
simple statement which represents the body of the function.
Parameters are passed by value and may be of type integer,
decimal, or string. Functions return a value to the point
of call. The value to be returned is assigned to the
function name (which is used as a simple variable within
the function) prior to the end of the function. Functions
may be called recursively with no limit set as to the
number of recursive calls which can be made. Variables may
be declared within functions and are considered local to
the function.
EXAMPLE:
INTEGER FUNCTION VALUE(X);
INTEGER X;
BEGIN
X := (X * 5) + (X * 2 );
VALUE := X;
END;
GOTO statement
ELEMENT:
GOTO statement
FORMAT:
label definition GO TO identifier|integer
label definition GOTO identifier|integer
DESCRIPTION:
Execution continues at the statement labeled with the
identifier or integer following the GOTO or GO TO
statement.
EXAMPLE:
NEXT: GO TO 100;
100: GOTO NEXT;
PROGRAMMING NOTE:
GOTO statements can only be used to branch within the
current block or to an outer block. GOTO statements
branching out of subroutines can cause unkown results.
identifier
ELEMENT:
identifier
FORMAT:
letter {letter|number} ...
DESCRIPTION:
Identifiers begin with a letter and are continued with any
alphanumeric characters. Although identifiers up to 255
characters may be used, only the first 31 characters are
actually used to distinguish the identifiers.
EXAMPLE:
A
NAME
COUNTER1
IF statement
ELEMENT:
IF statement
DESCRIPTION:
See balanced statement or unbalanced statement.
if expression
ELEMENT:
if expression
FORMAT:
IF boolean expression THEN expression ELSE expression
DESCRIPTION:
The if expression allows a conditional expression
evaluation. If the boolean expression is true the value of
the if expression is the value of the expression following
the word THEN. If the boolean expression is false the
value of the if expression is the value of the expression
following the word ELSE.
EXAMPLE:
WRITE( IF A > B THEN A ELSE B );
A:= IF B=C THEN B ELSE D;
label definition
ELEMENT:
label definition
FORMAT:
identifier|integer :
DESCRIPTION:
Label definitions are optional on all balanced or
unbalanced statements.
EXAMPLE:
FINISH:
100:
procedure call
ELEMENT:
procedure call
FORMAT:
identifier {(expression {,expression} ...)}
DESCRIPTION:
Procedures can be called with or without parameters.
Parameter passing is by value. Procedures can be called
recursively with no limit set as to the number of recursive
calls.
EXAMPLE:
COMPUTE;
COMPARE("AAA", WORD);
COUNT(1, 2, 3);
procedure declaration
ELEMENT:
procedure declaration
FORMAT:
PROCEDURE identifier {(identifier {,identifier} ...)}
{declaration; ...} simple statement
DESCRIPTION:
A procedure declaration may or may not include parameters.
If parameters are included they must be declared before the
simple statement which represents the body of the
procedure. Parameters are passed by value and may be of
type integer, decimal or string. Procedures do not return
a value to the point of call. Procedures can be called
recursively. Procedures are considered separate blocks
within which local variables may be declared.
EXAMPLE:
PROCEDURE OUTPUT;
WRITE ("HELLO");
PROCEDURE COMPARE(X,Y);
INTEGER X,Y;
BEGIN
WRITE("THE LARGEST INTEGER IS ");
IF X > Y THEN
WRITE(X);
ELSE
WRITE(Y);
END;
READ statement
ELEMENT:
READ statement
FORMAT:
READ {file identifier}(variable {,variable} ...) {ONENDFILE block}
DESCRIPTION:
If the form of the READ statement is READ(, then the input
device is the console. Otherwise a file option must be
specified and the input device is the disk. A READ
statement reads one or more variables at a time. The
optional ONENDFILE section indicates action to be taken
when the end of the specified file is reached.
EXAMPLE:
READ(WORDONE, X, VALUE2);
READ FILE3 (WORDONE, X, VALUE2);
PROGRAMMING NOTE:
The ONENDFILE section is curently not implemented.
The file identifier must have a CPM file name assigned
to it prior to reading from that file. When this file
name is assigned in an assignment statement it also
opens the file. All files are automatically closed
at the end of the block in which they are declared.
A file close error will occurr if a file is declared
and never opened.
reserved word list
ELEMENT:
reserved word list
FORMAT:
letter {letter} ...
DESCRIPTION:
The following words are reserved by ALGOL-M and may not be
used as identifiers:
AND ARRAY BEGIN CASE
CLOSE DECIMAL DO ELSE
END FILE FUNCTION GO
GOTO IF INTEGER NOT
OF ONENDFILE OR PROCEDURE
READ STEP STRING TAB
THEN TO UNTIL WHILE
WRITE WRITEON
Reserved words must be preceeded and followed by either a
special character or a space. Spaces may not be embedded
within reserved words.
simple statement
ELEMENT:
simple statement
FORMAT:
block|assignment statement|for statement|
case statement||goto statement|
while statement|read statement|write statement|
procedure call|identifier
DESCRIPTION:
All ALGOL-M statements are free form and must be
separated by semicolons.
simple declaration
ELEMENT:
simple declaration
FORMAT:
INTEGER|DECIMAL|STRING {(identifier|integer)}
identifier {,identifier} ...
DESCRIPTION
Simple integer variables may be any value between -16,383
and +16,383. Simple decimal variables can be specified as
any length from one to 18 digits with a default length of
10 digits. Simple string variables can be specified as any
length from one to 255 characters with a default length of
10 characters.
EXAMPLE:
INTEGER X;
DECIMAL(15) X,Y;
STRING(33) WORDONE, WORDTWO, WORDTHREE;
special characters
ELEMENT
special characters
DESCRIPTION:
The following special characters are used by ALGOL-M:
) close parenthesis
* asterisk
+ plus
- minus
: colon
; semicolon
< less-than
> greater-than
= equal
, comma
[ open bracket
] close bracket
:= assigned equal
** exponentiation
% percentage
Any special character in the ASCII character set may appear
in a string. Special characters, other than those listed
above, will cause an error condition if used outside of a
string.
TAB expression
ELEMENT:
TAB expression
FORMAT:
TAB expression
DESCRIPTION:
TAB is optionally used in a WRITE statement to cause
spacing on the output line. The amount of spacing is
specified by the integer expression following TAB.
EXAMPLE:
WRITE("NEXT NAME", TAB 5, NAME[I]);
unbalanced statement
ELEMENT:
unbalanced statement
FORMAT:
- {label definition} IF boolean expression THEN statement
{label definition} IF boolean expression THEN balanced
statement ELSE unbalanced statement
DESCRIPTION:
Unlike the balanced statement that will always have a
balanced statement on either side of the ELSE in an IF THEN
ELSE structure, an unbalanced statement may not even
include the ELSE portion of the statement.
EXAMPLE:
IF S > Y THEN WRITE(X);
IF X < Y THEN
IF Z > Y THEN
WRITE(Z)
ELSE
WRITE(X);
PROGRAMMING NOTE:
A semicolon is not allowed after the statement immediately
preceding an ELSE.
variable
ELEMENT:
variable
FORMAT:
identifier {[bound pair list]}
DESCRIPTION:
A variable in ALGOL-M may be simple or subscripted and of
type INTEGER, DECIMAL, or STRING.
EXAMPLE:
X
VALUE[2]
Z[1,X * Y]
WHILE statement
ELEMENT:
WHILE statement
FORMAT:
WHILE boolean expression DO simple statement
DESCRIPTION:
WHILE statements continue executing the simple statement
following the DO for as long as the boolean expression is
true.
EXAMPLE:
WHILE I > 0 DO
I := I - 1;
WHILE X > 5 AND Y <> 8 DO
BEGIN
X := X / 3;
WRITE(X);
END;
WRITE statement
ELEMENT:
WRITE statement
FORMAT:
WRITE|WRITEON {file option}
(expression|tab expression|string
{,expression|tab expression|pic definition|string} ...)
DESCRIPTION:
The WRITE option indicates the output will start printing
on a new line, while the WRITEON option will continue
printing on the same line. If the form of the statement is
WRITE( or WRITEON(, the output device is the console.
Otherwise, a file option must be specified and the output
device is the disk.
EXAMPLE:
WRITE(X);
WRITE("THE NUMBER IS",X + Y);
WRITE("ANSWER", TAB 5, X * Y);
WRITE FILE("hello");