Elements of the language
KEY
IMP80 is a high-level block-structured language. Relative to Algol 60,
it adds program structuring, data structuring, event signalling and text
handling facilities, but removes (or retains in a modified form)
intrinsically inefficient features such as the Algol 60 %name-type
parameter.
Character set
KEY
An IMP80 program is a sequence of statements constructed using the ISO
seven bit character set extended with a special alphabet. The special
alphabet is used to construct keywords.
The ISO seven bit character set is as follows:
_______________________________________________________________________
| | | | |
| 0 NUL | 32 SPACE | 64 @ | 96 ` |
| 1 SOH | 33 ! | 65 A | 97 a |
| 2 STX | 34 " | 66 B | 98 b |
| 3 ETX | 35 # | 67 C | 99 c |
| 4 EOT | 36 $ | 68 D | 100 d |
| 5 ENQ | 37 % | 69 E | 101 e |
| 6 ACK | 38 & | 70 F | 102 f |
| 7 BEL | 39 ' | 71 G | 103 g |
| 8 BS | 40 ( | 72 H | 104 h |
| 9 HT | 41 ) | 73 I | 105 i |
| 10 LF(NL) | 42 * | 74 J | 106 j |
| 11 VT | 43 + | 75 K | 107 k |
| 12 FF | 44 , | 76 L | 108 l |
| 13 CR | 45 - | 77 M | 109 m |
| 14 SO | 46 . | 78 N | 110 n |
| 15 SI | 47 / | 79 O | 111 o |
| 16 DLE | 48 0 | 80 P | 112 p |
| 17 DC1 | 49 1 | 81 Q | 113 q |
| 18 DC2 | 50 2 | 82 R | 114 r |
| 19 DC3 | 51 3 | 83 S | 115 s |
| 20 DC4 | 52 4 | 84 T | 116 t |
| 21 NAK | 53 5 | 85 U | 117 u |
| 22 SYN | 54 6 | 86 V | 118 v |
| 23 ETB | 55 7 | 87 W | 119 w |
| 24 CAN | 56 8 | 88 X | 120 x |
| 25 EM | 57 9 | 89 Y | 121 y |
| 26 SUB | 58 : | 90 Z | 122 z |
| 27 ESC | 59 ; | 91 [ | 123 { |
| 28 FS | 60 < | 92 \ | 124 | |
| 29 GS | 61 = | 93 ] | 125 } |
| 30 RS | 62 > | 94 ^ | 126 ~ |
| 31 US | 63 ? | 95 _ | 127 DEL|
|_______________|____________________|_________________|______________|
The use of the character set is summarised in the sections below and
described in detail in the rest of the manual. However, some general
points about certain characters should be noted at the outset:
a) Quotes
Several language constructions call for one or more characters to be
enclosed in quotes. Within quotes all characters are significant and
stand for themselves; thus, for example, space, newline, and percent
characters may appear between quotes and stand for space, newline, and
percent.
Two quote characters are used:
' - character quote
" - string quote
Examples:
'A', ';', '"', '!'
"String", "sealing wax", "!"
If it is required to include the delimiting quote within the text it
must be represented by two consecutive quotes.
Examples:
'''' - the character quote
"A ""big"" dog" - a string of eleven characters
However, note '"' and "it's mine".
b) Spaces
Except when used to terminate keywords or when between quotes, space
characters are ignored and may be used to improve the legibility of
the program.
c) Lower case letters
Except when enclosed in quotes, lower case letters are equivalent to
the corresponding upper case letters.
d) Non-graphic characters
The ISO characters with no graphic representation have code values
less than 32 or greater than 126. Any non-graphic characters can be
included within quotes in an IMP80 program, but only one, the newline
character (NL), is included in the syntactic definition of the
language (see Appendix A). This has the ISO code value 10.
{EMAS IMP80: all characters with code values less than 32 are treated
as spaces, apart from
NL (ISO code 10)
EM (ISO code 25) - terminates program
SUB(ISO code 26) - causes a syntax fault
It ignores DEL (ISO code 127) and maps all codes greater than 127
according to the extended Regional Network Code (which is detailed in
Regional Communications Memo JID/78/M20.4). }
{IMP77
Except for NL (see above) all characters not enclosed in quotes and
with ISO codes outwith the range 32 to 126 inclusive are treated as
spaces, but will be sent to the listing unaltered. The character FF
(form feed) may be used to cause a new page to be taken in program
listing files.}
Statements
KEY
An IMP80 program typically consists of an ordered set of statements, as
follows:
%begin
<declaration statements
and procedure descriptions>
%on %event .... %start
<executable statements>
%finish
<executable statements>
<procedure descriptions>
%end %of %program
Only the delimiting keywords %begin and %end %of %program must be
present. However, assuming that all the types of statement above are
represented in an IMP80 program, the effect of running the program on a
computer is as follows:
First, storage space for the declarations is obtained. Conceptually,
all the space is obtained at once - there is no defined order of
execution of declaration statements. The procedure descriptions are
skipped, as are the statements in the %on %event block, and the first
of the executable statements is obeyed. Thereafter, the statements
themselves define the sequence of execution ("flow of control").
Control passes to the %on %event block if one of the events defined in
the %on %event statement occurs whilst executing a statement.
The %on %event block is optional and often omitted.
Here is an IMP80 program:
%begin
%integer A, B, SUM, DIFFERENCE, MAX, MIN
MAX = -1; MIN = 5000
%cycle
READ(A)
%exit %if A=-1; ! End of input.
READ(B)
PRINTSTRING("Input values:")
WRITE(A,3); PRINTSYMBOL(',')
WRITE(B,3)
SUM = A+B; DIFFERENCE = A-B
PRINTSTRING(" ... Sum is")
WRITE(SUM,3)
PRINTSTRING(", Difference is")
WRITE(DIFFERENCE,3); NEWLINE
%if SUM>MAX %start
MAX = SUM
%finish %else %if SUM<MIN %start
MIN = SUM
%finish
%repeat
! Now print out the maximum and minimum of the sums of all
! the pairs of numbers read in.
NEWLINE
PRINTSTRING("Maximum sum is")
WRITE(MAX,3); NEWLINE
PRINTSTRING("Minimum sum is")
WRITE(MIN,3); NEWLINE
%end %of %program
The different types of statement in IMP80 are listed below, with
references:
%comment 1.2.3.1
%include 1.2.3.2
%list & %end %of %list 1.2.3.3
declaration 2
assignment 2
%begin 3.1
%end %of %program 3.1
%on %event 3.1.1
procedure specification 3.2/5
procedure heading 3.2
procedure call 3.2
%end %of %file 3.3.1
jump & label 4.2.2
%start/%finish 4.3
%cycle/%repeat 4.4
Continuation
KEY
Statements are normally terminated by a newline or semi-colon
character. However, a statement may extend over several physical
lines provided that each line break occurs after a comma, or is
preceded by the keyword %c (which is otherwise ignored).
Thus:
%if X=Y %then P = 1 %c
%else P = 0
is exactly equivalent to
%if X=Y %then P =1 %else P = 0
and
%own %integer %array X(1:10) = 10, 9, 8, 7, 6,
5, 4, 3, 2, 1
is exactly equivalent to
%own %integer %array X(1:10) = 10,9,8,7,6,5,4,3,2,1
{EMAS IMP80: Blank lines between the lines of a continued statement
are ignored.}
{IMP77: the line break can also occur after the keywords %or and
%and.}
Statement components
KEY
IMP80 statements are made up of atoms. An atom is an identifier, a
constant, a special symbol or a keyword.
Identifiers
KEY
An identifier is a sequence of any number of letters and digits,
starting with a letter. For example: C1900 TO 1970, NUMBER OF BLOCKS,
MAX, x, item1, Item 2, item 2b. Spaces within identifiers are
permitted but ignored, as is the case of the letters; thus Item 2 and
ITEM2 are not distinguished.
It is recommended that meaningful identifiers be used whenever
possible, to improve the clarity of programs.
In this manual, identifiers are always given in upper case. It is
stressed that this is merely a convention.
Identifiers are used to name the following entities:
Arithmetic, string and record variables and arrays
Reference variables
Record sub-fields
Procedures (i.e. routines, functions, maps)
Record and array formats
Named constants
Simple labels and switch vectors
Identifiers used in an IMP80 program must be declared before they may
be used. The only exception to this general rule is that simple
labels are not declared. Further rules relating to the uniqueness of
identifiers are given in the relevant sections.
Constants
KEY
IMP80 includes the following types of constant:
Decimal integer constants e.g. 2243, -16, 1 000 000
Base constants e.g. 2_1001, 8_7720, 16_A06C,
B'1011', X'1A69'
Real constants e.g. 120.0, 120, 1.2@2, 12@1,
1200@-1
Character constants e.g. 'A', 'a', '+', '"', '
', '''', '6'
Multi-character constants e.g. M'Four', M'MAX', M'1+1=',
M'"#%'
String constants e.g. "Here is a string", "A",
"123", "a ""good"" boy"
Named constants (also called e.g. %constant %integer PRICE=23
"%constant variables") :
TOTAL COST = PRICE * NUMBER
Special symbols
KEY
These are as follows:
_________________________________________________________________
| |
| ! !! ' " # (or \= or <>)|
| |
| ## (or \==) & ( ) * |
| |
| \ \\ + , - |
| |
| -> . / // : |
| |
| ; < <- << <= |
| |
| = == > >= >> |
| |
| @ \ (or ~) _ { } |
| |
| newline space |
|_________________________________________________________________|
{IMP77: \ and \\ may be replaced by ^ and ^^ respectively.}
{EMAS IMP80: \ and \\ may be replaced by ** and **** respectively.}
The special symbols are used in IMP80 in various ways:
* as operators (arithmetic, string, record, relational, logical)
* as separators, e.g. (..) {..} : ; , newline space
* in constants, e.g. 3_201, +27@4, -17.6, X'8F', "Constant"
* in record subfield references, e.g. TAX(MONTH)_OVERTIME
* ! as an alternative to the keyword %comment
Keywords
KEY
A keyword is a sequence of letters in a special alphabet. In programs
stored in a computer in text form ("source" programs), representation
of this alphabet is achieved by using the character percent (%), which
is defined as causing the subsequent letters (upper or lower case) to
be shifted into the special alphabet. The effect of the % character
is terminated by any non-alphabetic character, including space and
newline. Hence the following statements are equivalent:
%string(7) %array %name P
%STRING (7) %ARRAYNAME P
In this manual keywords are given in lower case.
The following is a list of all the IMP80 keywords:
____________________________________________________________
| |
| %alias %and %array %begin %byte |
| %c %comment %const %constant %continue |
| %cycle %dynamic %end %event %exit |
| %external %file %finish %fn %for |
| %format %function %half %if %include |
| %integer %list %long %map %monitor |
| %name %not %on %of %or |
| %own %program %real %record %repeat |
| %result %return %routine %short %signal |
| %spec %start %stop %string %switch |
| %system %then %unless %until %while |
|____________________________________________________________|
Miscellaneous statements
KEY
Certain statements are described here rather than in subsequent
sections, as they are different in kind from the other statements of the
language, and do not readily fit into any of the categories used in the
rest of the manual.
Comments
KEY
Textual comments can be included in an IMP80 program. They have no
effect on the program when it runs, but may be used to render it
meaningful both to the originator and to others. A comment is a
statement, and must be separated from the preceding statement by a
newline or semi-colon and from the succeeding statement by a newline -
not by a semi-colon. Note that the continuation rules described above
apply to comment statements. The keyword %comment is used to
introduce the text of the comment, which may contain any character
except newline. %comment may be replaced by the symbol '!'.
{IMP77: comments cannot be continued onto subsequent lines by any of
the methods described.}
Example:
%begin
%comment This program sorts a list of names
%comment into alphabetical order
:
:
%end %of %program
The IMP80 language also allows comments to be embedded within other
statements. An embedded comment is any sequence of characters,
excluding '}' and newline, enclosed in a pair of braces, '{' and '}'.
This form of comment may appear between any two atoms, but may not
occur within an atom. For convenience the closing brace may be
replaced by a newline.
Example:
! This is a portion of a test program
COUNT = 0; ! Note the semi-colon before the '!'; note thenext one
! next one (in the text of the comment).
LIMIT = 100 {Only 100 cases}
MINIMUM = 0 {all positive
PROCESS(X {cases}, Y {total cost})
This fragment of program is exactly equivalent to
COUNT = 0
LIMIT = 100
MINIMUM = 0
PROCESS(X,Y)
Note that this type of comment never counts as a statement in its own
right, even when given on a line by itself. Thus it can be interposed
between lines of a continued statement.
%include statement
KEY
A file of IMP80 statements (terminated by the statement %end %of
%file) may be included in a source program by giving a statement of
the form
%include <file specification>
where <file specification> is a string constant representing a
system-dependent file name. Refer to the relevant section of
Appendix B for details of any implementation-dependent limitations on
the use of %include.
Example:
%begin
%include "WXYZ83.EXTSPECS"
%integer TIME, DISPLACEMENT, ...
:
:
Note that the %include statement appears in the program listing
generated by the compiler, followed by the contents of the file
referred to (including the %end %of %file). The %include statement
should not be followed on the same line of the source program by other
statements, since the complete source line will appear in the program
listing before the statements included, while in the actual program
the statements following the %include follow the statements included.
%list and %end %of %list
KEY
Normally the compiler generates a listing of a program as it compiles
it. The precise layout of this listing is implementation-dependent.
The production of the listing can normally by controlled by setting a
system option prior to the compilation. In addition, however, the
programmer can control the generation of the listing by use of the
statement %end %of %list, which inhibits the listing until the end of
the program or the statement %list is encountered. The default is for
the listing to be generated.
The statements %end %of %list and %list may appear anywhere within an
IMP80 program.
Note that when listing is inhibited, incorrect statements and the
accompanying fault messages are still listed.
{IMP77: %end %of %list and %list are nested, so that two %end %of
%list statements require two matching %list statements to switch on
the listing again. This means that it is possible within an included
file (see above) to control the listing of the contents of the file,
without changing the listing status of the rest of the program.}