PASCAL on EMAS -------------- CONTENTS 1. Introduction 2. Compilation 2.1 Compilation Listings 2.2 Compiler Directives 3. Execution 3.1 Files for Input and Output 3.2 Connection of INPUT and OUTPUT 3.3 Error Action 4. EMAS 2900 PASCAL 4.1 Source program format 4.2 Language restrictions 4.3 Language extensins 4.4 The program heading and external files 4.5 Hardware representation 4.6 The standard procedure WRITE Appendix 1 Compilation error messages 1. Introduction THE PASCAL LIBRARY IS IN ERCS07.PASCALDIR The 2900 PASCAL Compiler is based on the "PASCAL User Manual and Report" (2nd Edition) by Kathleen Jensen and Nicklaus Wirth. The language implemented conforms to the standard defined in that work, subject to the restrictions, extensions and further specifications contained in subsequent sections of this note. 2. Compilation The command used to compile a PASCAL source program is PASCAL(source,object/.NULL,clist/.NULL) eg. PASCAL(PTEST,PTESTY,PTESTL) 2.1 Compilation Listings The source listing consists of each line of the source program, preceded by the following information: 1 The line number 2 The level of BEGIN-END, RECORD-END and CASE-END nesting. This is present only if it changes within the line. Any line of source that contains a compiler-detected error is followed by a line containing a circumflex (^) and a number, indicating the position and error number of the error. This line and the line containing the error is produced even when the source is set off. A list of compilation error numbers and their meanings is given in Appendix 1. 2.2 Compiler Directives - NOT IMPLEMENTED AT PRESENT 3. Execution The command used to load and execute a compiled PASCAL program is RUN(object) EG. RUN(PTESTY) 3.1 Files for Input and Output Before an object program can be executed, connections must be made between the PASCAL files named in the program heading and EMAS files. In general, these connections are made via channel numbers using the DEFINE command - see EMAS 2900 Users' Guide Chapter 7. Normally, the PASCAL file whose name occurs at position n in the program heading is connected via channel n. For example, if the program heading is PROGRAM TRANSFER(INPUT,OUTPUT,FILEA); the statement DEFINE(3,NEWRESULTS) connects FILEA to the EMAS file NEWRESULTS. 3.2 Connection of INPUT and OUTPUT The following default connections are made 1. The standard file parameter INPUT is assigned to .IN. 2. The standard file parameter OUTPUT is assigned to .OUT. Note that these default connections only occur if the PASCAL files INPUT and OUTPUT are not connected by DEFINE as described in 3.1. If INPUT is specified in the program heading, the PASCAL file INPUT is automaticallly initialised and thus input is expected from this file. Currently, when a PASCAL program terminates, the PASCAL library looks for EOF from INPUT. Thus, if INPUT is connected via the EMAS file .IN (by default or use of DEFINE), the EOF character, CTRL+Y, is required to return to command level. 3.3 Error Action In the event of an error occurring during execution of the program, execution is terminated and the following message is output on the user's terminal ERROR AT OR AFTER LINE NO. n where n is the number of the most recently executed line of the source program that was compiled with the trace option on (see section 2. This will be 0 if all the code so far executed was compiled with the trace option off or if the error occurred during program initialisation. 4. EMAS 2900 PASCAL This section defines the way in which EMAS 2900 PASCAL differs from the language defined by Jensen and Wirth in "PASCAL User Manual and Report". 4.1 Source program format 1 UP TO the first 96 characters are treated as significant by the compiler: subsequent characters in a line will appear in the source listing but will be otherwise ignored. 2 Lower-case letters are recognised by the compiler. EACH IS TAKEN TO BE THE SAME AS THE CORRESPONDING UPPER CASE LETTER (except in comments) 3 PASCAL special symbols which are words (for example mod, nil and in) must be represented by the corresponding upper/LOWER-case spelling without underlines, and not enclosed in quotes (for example MOD, NIL, IN). The user must not use identifiers whose spellings correspond to those of the PASCAL special SYMBOLS. 4 PASCAL special symbols should be separated from each other and from identifiers by at least one space or newline character. Space and newline characters may be inserted between symbols and identifiers in the source text as desired to improve layout, but must not be embedded within symbols or identifiers 5 Identifiers may be any length (up to the end of a line), but only the first 32 characters are treated as significant 6 The characters ^ or @ are used to represent the character 'up arrow' referred to in "PASCAL User Manual and Report" 7 Strings must not extend over more than one line 4.2 Language restrictions 1 Local file declarations are not permitted, that is, all files used by a program must be external files specified in the program heading 2 Components of FILE type may not appear in RECORD-TYPES, ARRAY-TYPES or (other) FILE types 3 Calls to the standard procedures READ and WRITE may not be made with a file of non-text type as the first parameter, so GET and PUT must be used for records of non-text files 4 If x and y are the first and last scalar values in the base type of a SET-type, then ord(x) must be greater than or equal to 0 and ord(y) must not be greater than 63 4.3 Language extensions The language implemented contains the following facilities not defined in Chapters 1 to 12 of the "PASCAL User Manual and Report": 1 There is an additional predefined type ALFA, with definition TYPE ALFA=PACKED ARRAY [1..32] OF CHAR; 2 THERE IS AN ADDITIONAL PREDEFINED TYPEALFA8, WITH DEFINITION TYPE ALFA8=PACKED ARRAY [1..8] OF CHAR; 3 A program may access external procedures and functions, that is, precompiled procedures and functions that exist outside the program and are declared but not defined within the program. External procedures and functions must be declared globally. The declaration for such a procedure or function consists of a standard procedure or function-declaration followed by the word EXTERN. For example FUNCTION SINH(X:REAL):REAL;EXTERN; 4 The following additional predefined procedures and function are available: HALT (S) Causes executions of the program to be terminated. The string S is written to the job journal DISPOSE(P) or Used to indicate that the storage space DISPOSE(P,T1,..Tn) occupied by the variable P (with tag fields T1,..Tn) is no longer required. The parameters to the call of DISPOSE should correspond to those for the call to NEW that was used to allocate the space CLOCK The value of this INTEGER function is the amount of OCP time in milliseconds used by the program since the start of execution DATE(D) This procedure assigns the character representation of the current date to the VAR parameter D (of type ALFA) in the form YY/MM/DD TIME(T) This procedure assigns the character representation of the current time to the VAR parameter T (of type ALFA) in the form HH MM SS PAGE(F) This procedure causes subsequent lines of output on the text file F to occur on a new page 4.4 The program heading and external files The formal parameters in the program heading must be formal FILE parameters; there must be one such parameter for each external file used by the program, that is, one for each file that exists outside the program before or after execution. These files, except INPUT and OUTPUT, must be declared as variables of FILE-type in the program block like any ordinary local variables. If used, the files INPUT and OUTPUT must be specified as formal parameters in the program heading; however they must not be declared in the program block as they are already assumed to be of type TEXT. The initialising statements RESET(INPUT) and REWRITE(INPUT) must not be specified, but before any other external file is read from or written to, reading or writing must be initiated by a call to the appropriate procedure RESET or REWRITE. 4.5 Hardware representation Values of type INTEGER are represented in ICL 2900 Series 32-bit fixed-point format (two's complement), which permits values in the range -2,147,483,648 to 2,147,483,647 (that is, -2@31 to 2@31-1). The constant MAXINT is predefined: CONST MAXINT = 2147483647 Integer constants in a PASCAL program must lie in the range -MAXINT to MAXINT. Values of type REAL are represented in ICL 2900 Series 64-bit floating-point format which permits values in the approximate range -7.2*10@75 to 7.2*10@75. Values in the approximate range -5.4*10@-79 to 5.4*10@-79 are represented as 0. All values are represented to a precision of 16 decimal digits. Note that the results of all arithmetic operations on real values are truncated not rounded. Values of type CHAR are held as 8-bit bytes. These values are represented internally according to one of THREE character codes. The required code is selected by the code directive as described in section 2.2. By default, ISO code is used. The user need not normally be concerned about the internal representation of values of type CHAR, except when using one of the following language constructs: 1 FILE OF RECORD...END where the record contains fields of type CHAR, or FILE OF ARRAY[...] OF CHAR 2 SET OF CHAR (in view of the restrictions on the base-type of a SET-type, specified in section 4.2) 4.6 The standard procedure WRITE If no minimum field width parameter is specified in a call to WRITE, then the following default values are assumed Type of value Default width INTEGER 12 BOOLEAN 5 CHAR 1 STRING Length of string REAL 24 Appendix 1 ---------- Compilation error messages 1 ERROR IN SIMPLE TYPE 2 SYMBOL EXPECTED WAS IDENTIFIER 4 SYMBOL EXPECTED WAS ')' 5 SYMBOL EXPECTED WAS ':' 6 UNEXPECTED SYMBOL 7 ERROR IN PARAMETER LIST 8 SYMBOL EXPECTED WAS 'OF' 9 SYMBOL EXPECTED WAS '(' 10 ERROR IN TYPE 11 SYMBOL EXPECTED WAS '[' 12 SYMBOL EXPECTED WAS ']' 13 SYMBOL EXPECTED WAS 'END' 14 SYMBOL EXPECTED WAS ';' 15 SYMBOL EXPECTED WAS INTEGER CONSTANT 16 SYMBOL EXPECTED WAS '=' 17 SYMBOL EXPECTED WAS 'BEGIN' 18 ERROR IN DECLARATION PART 19 ERROR IN FIELD-LIST 20 SYMBOL EXPECTED WAS '/' 21 MISORDERED DECLARATIONS? 22 ONLY GLOBAL VARIABLES CAN BE INITIALISED 50 ERROR IN CONSTANT 51 SYMBOL EXPECTED WAS ':=' 52 SYMBOL EXPECTED WAS 'THEN' 53 SYMBOL EXPECTED WAS 'UNTIL' 54 SYMBOL EXPECTED WAS 'DO' 55 SYMBOL EXPECTED WAS 'TO' OR 'DOWNTO' 56 SYMBOL EXPECTED WAS 'IF' 58 ERROR IN FACTOR 59 ERROR IN VARIABLE 90 MISSING 'END'S 101 IDENTIFIER DECLARED TWICE 102 LOW BOUND EXCEEDS HIGH BOUND 103 IDENTIFIER IS NOT OF APPROPRIATE CLASS 104 IDENTIFIER NOT DECLARED 105 SIGN NOT ALLOWED 105 NUMBER EXPECTED 107 INCOMPATIBLE SUBRANGE TYPES 108 FILE NOT ALLOWED HERE 109 TYPE MUST NOT BE REAL 110 TAGFIELD TYPE MUST BE SCALAR OR SUBRANGE 111 INCOMPATIBLE WITH TAGFIELD TYPE 112 INDEX TYPE MUST NOT BE REAL 113 INDEX TYPE MUST BE SCALAR OR SUBRANGE 114 BASE TYPE MUST NOT BE REAL 115 BASE TYPE MUST BE SCALAR OR SUBRANGE 116 ERROR IN TYPE OF STANDARD PROCEDURE PARAMETER 117 UNSATISFIED FORWARD REFERENCE 119 FORWARD DECLARED: REPETITION OF PARAMETER LIST NOT ALLOWED 120 FUNCTION RESULT TYPE MUST BE SCALAR, SUBRANGE OR POINTER 121 FILE VALUE PARAMETER NOT ALLOWED 122 FORWARD DECLARED FUNCTION; REPETITION OF RESULT TYPE NOT ALLOWED 123 MISSING RESULT TYPE IN FUNCTION DECLARATION 124 F - FORMAT FOR REAL ONLY 125 ERROR IN TYPE OF STANDARD FUNCTION PARAMETER 126 NUMBER OF PARAMETERS DOES NOT AGREE WITH DECLARATION 128 RESULT TYPE OF PARAMETER FUNCTION DOES NOT AGREE WITH DECLARATION 129 TYPE CONFLICT OF OPERANDS 130 EXPRESSION IS NOT OF SET TYPE 131 TESTS ON EQUALITY ALLOWED ONLY 132 STRICT INCLUSION NOT ALLOWED 133 FILE COMPARISON NOT ALLOWED 134 ILLEGAL TYPE OF OPERAND(S) 135 TYPE OF OPERAND MUST BE BOOLEAN 136 SET ELEMENT TYPE MUST BE SCALAR OR SUBRANGE 137 SET ELEMENT TYPES NOT COMPATIBLE 138 TYPE OF VARIABLE IS NOT ARRAY 139 INDEX TYPE IS NOT COMPATIBLE WITH DECLARATION 140 TYPE OF VARIABLE IS NOT RECORD 141 TYPE OF VARIABLE MUST BE FILE OR POINTER 142 ILLEGAL PARAMETER SUBSTITUTION 143 ILLEGAL TYPE OF LOOP CONTROL VARIABLE 144 ILLEGAL TYPE OF EXPRESSION 145 TYPE CONFLICT 146 ASSIGNMENT OF FILES NOT ALLOWED 147 LABEL TYPE INCOMPATIBLE WITH SELECTING EXPRESSION 148 SUBRANGE BOUNDS MUST BE SCALAR 149 INDEX TYPE MUST NOT BE INTEGER 150 ASSIGNMENT TO STANDARD FUNCTION IS NOT ALLOWED 151 ASSIGNMENT TO FORMAL FUNCTION IS NOT ALLOWED 152 NO SUCH FIELD IN THIS RECORD 154 ACTUAL PARAMETER MUST BE A VARIABLE 155 CONTROL VARIABLE MUST NOT BE FORMAL 156 MULTIDEFINED CASE LABEL 158 MISSING CORRESPONDING VARIANT DECLARATION 159 REAL OR STRING TAGFIELDS NOT ALLOWED 151 AGAIN FORWARD DECLARED 162 PARAMETER SIZE MUST BE CONSTANT 164 SUBSTITUTION OF STANDARD PROC/FUNC NOT ALLOWED 165 MULTIDEFINED LABEL 166 MULTIDECLARED LABEL 167 UNDECLARED LABEL 168 UNDEFINED LABEL IN BLOCK JUST ENDED 169 ERROR IN BASE SET 170 PROCEDURE OR FUNCTION WITH ONLY VALUE PARAMETERS EXPECTED 172 UNDECLARED EXTERNAL FILE 173 PACKED COMPONENT CANNOT BE PASSED AS VARIABLE PARAMETER 174 FORWARD PROCEDURE OR FUNCTION NOT FOUND IN BLOCK JUST ENDED 175 SUBRANGE BOUNDS CANNOT BE REAL 176 LABEL NOT DEFINED AT CORRECT LEVEL 177 PERMANENT FILE UNDECLARED 178 NO INPUT OR OUTPUT FILE SPECIFIED 201 ERROR IN REAL CONSTANT: DIGIT EXPECTED 202 STRING CONSTANT MUST NOT EXCEED SOURCE LINE 203 INTEGER CONSTANT EXCEEDS RANGE 204 8 OR 9 IN OCTAL NUMBER 205 STRING OF LENGTH ZERO NOT ALLOWED 250 TOO MANY NESTED SCOPES OF IDENTIFIERS 251 ERROR IN INITIALISATION OF GLOBAL VARIABLES 252 TOO MANY FORWARD REFERENCES OF PROCEDURE ENTRIES 253 PROCEDURE TOO LONG 255 TOO MANY ERRORS IN THIS SOURCE LINE 300 DIVISION BY ZERO 302 VALUE OUTSIDE EXPECTED RANGE 303 OVERFLOW OR DIVISION BY ZERO IN INTEGER ARITHMETIC 398 IMPLEMENTATION RESTRICTION R.Soutar 13.3.80