1 For the table of contents do: WRITEUP(PASCAL=CONTENT). This writeup uses the extended ASCII character set. To obtain a copy of this line-printer-only, upper-and-lower-case writeup do WRITEUP(PASCAL=*/PT=AS,L=LIST) ROUTE(LIST,DC=PR,EC=A9) PPPPPPP LLL PP PP LL PP PP AAAAA SSSSS CCCCC AAAAA LL PPPPPPP AA SS CC CC AA LL PP AAAAAA SSSSS CC AAAAAA LL PP AA AA SS CC CC AA AA LL PP AAAAAA SSSSS CCCCC AAAAAA LL 66666 00000 00000 00000 66 66 00 00 00 00 00 00 66 00 00 00 00 00 00 666666 00 00 00 00 00 00 66 66 00 00 00 00 00 00 66 66 00 00 00 00 00 00 66666 00000 00000 00000 Dave Bianchi Larry Daasch | Jim Miner Academic Computing Services and Systems | University of Minnesota Version 4.1 | May, 1986 | Differences from Version 4.0 are indicated by change bars in the right | margin. An asterisk indicates deleted text. | COPYRIGHT --------- Portions of Pascal-6000 Release 4 are copyright by the University of Minnesota. It is not to be sold or distributed without the express written permission of the University of Minnesota, Academic Computing | Services and Systems. All names and references are to be left intact. | The machine-retrievable documention on the release tape is under a limited copyright. That is, you are free to copy and distribute the writeups within your organization providing that it is not done for profit and that all names and references are left intact. 1 Pascal-6000 Version 4.1 27 May 86 Introduction ============ Pascal is a modern programming language designed for general-purpose applications. It was derived from ALGOL-60 (a block-structured programming language) and retains many ALGOL-like features of control structure (statements). Pascal has a rich collection of language features for data description, and its extensible data structuring allows data to be represented in a more direct manner than many other languages. Pascal has become an important vehicle for teaching programming and writing reliable, efficient, and portable software. The primary reference for Pascal is "Specification for Computer Programming Language Pascal" BS 6192: 1982 British Standards Institution This writeup provides programmers with a description of the differen- ces between standard Pascal and Pascal-6000. It describes both the implementation-defined features of the language Pascal as provided by Pascal-6000 and also several extensions to the language. You are warned that writing programs which rely on extensions and features peculiar to Pascal-6000 will hinder later attempts to transport these programs to other implementations of Pascal. In the main, this writeup applies equally well to versions of Pascal-6000 running on diverse hardware and under diverse operating systems. Thus the terms "hardware", "machine", and "computer" are used to refer to any of the various Control Data computers compatible with Pascal-6000. The term "operating system" is used to refer to any of the operating systems that are compatible with Pascal-6000. The syntax of statements in Pascal is described in this document through the use of EBNF (Extended Backus-Naur Form). The symbols used in EBNF are explained in the chapter SYNTAX. Other documents that describe aspects of Pascal-6000 are as follows. - "Pascal Library Information" describes the Pascal-6000 library; - "Internal Reference Manual" describes algorithms, data structures, and other details about the internal operation of Pascal-6000; and - "Installation Handbook" gives installation procedures and options for Pascal-6000. Acknowledgements ---------------- This document makes extensive use of the Pascal-6000 Release 3 documentation which was written by John P. Strait, Andrew B. Mickel, and John T. Easton. Parts of the version 4.0 documentation was | written by Dan Germann. The RM7600 chapter was provided by the | University of Manchester Regional Computing Centre. The original | version of the USERLIB chapter was written by Gordee Small at the | University of Minnesota - Duluth. This writeup was edited extensively | by Wendy Havir. Others who contributed to the production of this document are Sara K. Graffunder and Linda B. Merims. INTRO.i 1 Pascal-6000 Version 4.1 27 May 86 Table of Contents ================= Chapter Page Title ------- ---- ----- COVER - Title Page. INTRO i - Introduction. CONTENT ii - Table of Contents. ACCESS 1 - Accessing the Pascal Compiler. DIALECT 5 - Using the Standard Dialect Switch. | OPTIONS 6 - Compiler Options. LIMITS 15 - Compiler Limits in Pascal-6000. MEMORY 17 - Memory Management. CMM 21 - Using Common Memory Manager. | TYPES 22 - Predefined types. PROCS 23 - Nonstandard Predeclared Procedures and Functions. PRGHEAD 25 - Program Heading and External Files. FILES 27 - Representation of Files, Use of External Files. SEGFILE 29 - Segmented Files. READWRI 30 - The Standard Input and Output Procedures. TEXTIO 33 - Text Input and Output Made Easier. INTERIO 40 - Interactive Input and Output Made Easier. RM7600 43 - Record Manager Interface under SCOPE 2 (7600s). CASE 47 - Case-Statement and Variant-Record Extensions. | CONFORM 49 Conformant Array Parameters. INCLUDE 50 - Including External Text. VALUE 53 - The Initial-Value Declaration. HEAP 56 - Alternative Heap Management Extensions. HINTS 58 - Hints for Machine-Dependent Programming. EXTERN 59 - External Procedures and Functions. FORTRAN 61 - Fortran Subroutines and Functions. USERLIB 63 - Creating User Libraries. SYMBOLS 71 - Lexical Symbols. CHARSET 73 - Pascal-6000 Character Sets. SYNTAX 75 - Pascal-6000 Syntax Description. ERROR 84 - Pascal-6000 Compiler Error-Message Summary. HISTORY 89 - Facts About Pascal-6000. REFER 90 - References. CONTENT.ii 1 Pascal-6000 Version 4.1 27 May 86 At the University of Minnesota, this document is available as an indexed writeup organized in chapters of a few pages each. This allows the retrieval of selected chapters or the entire writeup. Any of the following commands may be used at the University of Minnesota. At other sites, the method to retrieve separate chapters may be different or impossible. WRITEUP(PASCAL=CONTENT) - Print this table of contents. WRITEUP(PASCAL=*) - Print the entire writeup. WRITEUP(PASCAL=C) - Print the chapter named "C". WRITEUP(PASCAL=C1+C2+ ... +Cn) - Print the selected chapters. Chapters can be selected by names chosen from the table of contents. Throughout this document, chapter names appear in upper case at the bottom of each page and also in references between chapters. CONTENT.iii 1 P-6000 - Accessing the Pascal Compiler 27 May 86 Accessing the Pascal Compiler ============================= At the University of Minnesota, Pascal is directly accessible by operating system control statements. It is easily useable from both remote job entry (batch) and interactive terminals. The Pascal Control Statement ---------------------------- The control statement call is PASCAL(I=sfn,L=lfn,B=bfn,E=efn,REW=rs,GO,PD=d,PS=n,PL=x,DS=ds/opts) | I=sfn Read Pascal source program from file sfn. The file sfn is | not rewound (see the REW parameter). I alone selects file | name COMPILE. Default if omitted - INPUT. L=lfn Write compilation listing to file lfn. The file lfn is not | rewound (see the REW parameter). L=0 turns off the compiler | listing, and inhibits the use of the L+ compiler option | within the program source. L alone selects file name LIST. | Default if omitted - OUTPUT. B=bfn Write relocatable binary to file bfn. B=0 inhibits creation | of the binary file. The file bfn is rewound before | compilation if REW=B or the GO parameter appears. | Default if omitted - LGO. E=efn Write compilation errors to file efn. Compilation errors | are also written to the listing file (specified by L=lfn), | unless L=0 is used. If both L=0 and E=0 are used, then no | report will be generated by the compiler. E alone selects | file name ERRS. | Default if omitted: OUTPUT. | REW=rs Select files to rewind before compilation. The parameter rs | is a string containing any combination of I (source), L | (listing), B (binary), and E (errors). REW alone selects | IB, which rewinds the source and binary files. Specifying | REW=ILBE rewinds all four files. Actual files INPUT and | OUTPUT are NEVER rewound. If the GO parameter is selected, | REW=B is assumed. | Default if omitted: No files are rewound. | GO Select automatic load and execute after compilation. Default if omitted - no execute. PD=d Select compiler-listing print density of d lines per inch. PD=6 selects 6 lines per inch; PD=8 selects 8. PD alone changes from the default, either 6 to 8 or 8 to 6. Default if omitted - Job Default. ACCESS.1 1 P-6000 - Accessing the Pascal Compiler 27 May 86 PS=n Select a compiler-listing page size of n lines. If (n = 0) or (n > 1000), page size is infinite. If (0 < n < 20), page size is set to 20. If PS is not selected but PD is selected, then PD sets the page size: PD=6 - 63, PD=8 - 84. Default if omitted - Job Default. PL=x Set print limit of x lines for program results. The PL=x option only applies to file variable OUTPUT of the program being compiled. To disable the line limit, use PL or PL=0. Default if omitted - 2000 lines. DS=ds Select "standard" dialect for compilation. Can enforce ANSI | or ISO standard, by disallowing extensions. (See Chapter | DIALECT.) DS=P6000 allows all extensions. DS=ISO or DS=ISO1 | selects level 1 of the ISO standard. DS=ISO0 selects level | 0 of the ISO standard. DS=ANSI selects the ANSI/IEEE | standard. | Default if omitted - P6000 (extensions allowed). | opts Pascal compiler option-sequence. (See Chapter OPTIONS.) These are switches or numeric parameters affecting the actual compilation. Format of Source File --------------------- The Pascal compiler allows (but does not require) the use of line numbers (sequence numbers) in the first one to five columns of the program source file. The first 150 columns of each line of the program source file are considered significant to the compiler. Interactive Access ------------------ A Pascal language subsystem is available under the University of Minnesota NOS timesharing system. The PASCAL command may be used to enter the Pascal subsystem where Pascal programs may be compiled and executed by use of the RUN (or RNH) command. First prepare and save the Pascal program in a permanent file, for example MYPROG. Then use the following sequence of commands to run that program. PASCAL,OLD,MYPROG. RNH -or- RUN The Pascal compiler may also be accessed through control statements under the BATCH interactive subsystem. The following command sequence may be used from this subsystem. :BATCH /OLD(MYPROG) /X,PASCAL(I=MYPROG, ... ) -or- $PASCAL(I=MYPROG, ... ) /LGO. ACCESS.2 1 P-6000 - Accessing the Pascal Compiler 27 May 86 Batch Deck Setup ---------------- A sample deck setup for remote batch (under NOS) follows. Jobname. USER(usernumber,password) PASCAL. or PASCAL(parameters) LGO. Pascal program text data (if any) An end-of-record mark is either: - a 7, 8, and 9 multi-punched in column one of a card at non-RBF remote batch stations, or - a /*EOR punched in columns 1 through 5 of a card at RBF remote batch stations. An end-of-information mark is either: - a 6, 7, 8, and 9 multi-punched in column one of a card at non-RBF remote batch stations or - a /*EOI punched in columns 1 through 5 of a card at RBF remote batch stations. See the University of Minnesota publication UCC CYBER GUIDE for details of these distinctions as they are applicable at the University of Minnesota. The LGO Statement and File Substitution --------------------------------------- Parameters on the LGO statement may be substituted for file names on the program heading as follows: If the program heading is PROGRAM EXAMPLE(DATA,INPUT,OUTPUT); executing the binary with LGO(X1,,X2) will substitute X1 for DATA and X2 for OUTPUT. The control statement is scanned for file names only up to a slash, period or right parenthesis. ACCESS.3 1 P-6000 - Accessing the Pascal Compiler 27 May 86 Saving and Retrieving the Binary File ------------------------------------- The binary file may be saved and executed at a later time. Once a correct binary is generated, the control statement(s) below may be used to make the binary a permanent file with the name "BINPROG". SAVE(LGO=BINPROG) for relocatable binaries, or LOAD(LGO) -or- LINK(B=BINPROG) NOGO(BINPROG) SAVE(BINPROG) SAVE(BINPROG) for absolute binaries. To use BINPROG later do GET(BINPROG) BINPROG. ACCESS.4 1 P-6000 - Using the Standard Dialect Switch 27 May 86 Using the Standard Dialect Switch | ================================= | | | The DS (Dialect Switch) parameter allows you to enforce a particular | "standard" dialect during compilation of your Pascal program. The | permissible DS parameter selections and the dialect enforced by each | follow. | | DS=P6000 | -------- | | All of the following extensions will be recognised. | | - Reserved words OTHERWISE, SEGMENTED, and VALUE. | - Underscore character in identifiers. | - Octal constants. | - Integer constants greater than MAXINT. | - Subranges in case constant lists. | - "EXTERN" or "FORTRAN" directives. | - Second parameter to REWRITE. | - String-compatible conformant-array-parameter as parameter to WRITE. | - Second parameter to TRUNC. | - Ord of real or pointer expression. | - Passing conformant-array as value parameter. | - Mixed-order of declarations. | - Program parameter characteristics "+" and "/". | - Compiler options specified in special comments. | - Nonstandard constants, types, procedures, and functions. See | chapter SYMBOLS for a list of nonstandard identifiers and reserved | words. | | DS=ISO or DS=ISO1 | ----------------- | | This DS parameter option selects Level 1 of the international standard | for the Pascal language as established by the ISO (International | Organization for Standardization). The use of any extension (see | above) will be flagged as an error. | | DS=ISO0 | ------- | | This option selects Level 0 of the ISO standard. The only difference | between this dialect and the one selected by ISO/ISO1 is that this | dialect also disallows the use of conformant array parameters. | | DS=ANSI | ------- | | This option selects the dialect defined by the ANSI/IEEE (American | National Standards Institute/Institute of Electrical and Electronics | Engineers) standard for Pascal. For purposes of the DS parameter, | this dialect is the same as the one selected by ISO0, and programs | compiled with either parameter option are treated identically. | DIALECT.5 1 P-6000 - Compiler Options 27 May 86 Compiler Options ================ The user may control the operation of the compiler through the use of various options specified on the Pascal compiler control statement (see ACCESS) or within special comments. Compiler options that are specified within comments are designated as such by a dollar sign as the first character of the comment: (*$option-sequence any-comment*) Example: (*$T-,P- COMPILE WITHOUT RUN-TIME TESTS OR PMD INFO. THIS SPEEDS EXECUTION AND SAVES SPACE. *) The option-sequence is a series of individual options separated by commas. Each option consists of one or two letters designating the option, followed by the new value of the option setting. The value may be a "+" or "-" which turns some options on and off like switches. Alternately the value may be a decimal or octal (indicated by a post radix "B") integer for numeric options, or a literal string for string options (see the E, I, and L options). The rules for these strings are the same as those for character strings appearing in a Pascal program. Finally, for all options except the I option, if the value is an "=", this sets the option to its previous value. However, only one previous value is remembered. The option-sequence is terminated by anything which is not an appropriate option letter or option value. Setting an option to an inappropriate value (e.g. setting a switch option to a numeric value) will cause option scanning to end. Warnings are issued when an invalid option syntax is found. Because compiler options may be written anywhere in the program, it is possible to activate the options selectively over specific parts of the program. The following options are presently available: A : Selects the character set recognized by the Pascal-6000 compiler. Both the CDC ASCII subset and the CDC scientific character sets are supported. A+ selects ASCII and A- selects scientific. See the chapter CHARSET for descriptions of the two character sets. The default value for A depends on the character set used at your computer center. The A option is best used on the first line of your Pascal source program. Default depends on the installation character set: A+ at ASCII subset sites, and A- at Scientific set sites. B : Determines the size of file buffers. If the value of the B option is less than 64, it is a buffer factor, and the actual buffer size (in words) is at least 128 times the buffer factor. If the value is larger than 64, it specifies the actual buffer size. The compiler adds one to the value selected by B, and then it adds enough to ensure that the buffer size is a multiple of the size of the basic file element. Buffer sizes must be adjusted to fit the requirements of peripheral hardware devices. Disk files only need at least B1 (or B128); tape files on the other hand need at least B4 (or B512). OPTIONS.6 1 P-6000 - Compiler Options 27 May 86 The buffer size for a file is bound to its type. For example PROGRAM P(XXX, YYY, OUTPUT); (*$B4 *) TYPE DATA = FILE OF INTEGER; (*$B6 *) VAR XXX : DATA; YYY : FILE OF INTEGER; ... The buffer size for XXX will be 513 words, and for YYY will be 769 words. The type TEXT is predefined at the time the PROGRAM header is scanned. Thus to change the buffer size for textfiles (including INPUT and OUTPUT), the B option must be set prior to the PROGRAM header. Default is B2. D : Selects the language in which to print any compiler error messages. The format for the D option is: (*$D'ENGLISH' PRINT ENGLISH ERROR MESSAGES *) The supported languages are ENGLISH, FRENCH, and GERMAN. Any identifier other than these three sets the language to ENGLISH and causes a compiler warning message. Default is D'ENGLISH'. E : Allows the programmer to control the entry-point names generated by the compiler for the main program, the main variables segment, procedures, functions, and labels. Entry points are required by the operating system loader, and so the E option is of special interest if you want to create a library of compiled, relocatable procedures and functions. The following describes the effect of the E option. a) Procedures and functions declared as "EXTERN" or "FORTRAN" get an entry-point name equal to the procedure or function name truncated to the first seven characters. Other routines get an entry-point name depending on the value of the E-option (at the moment of analyzing the routine name): E- A unique symbol of the form "PRCnnnn" (where nnnn is an octal number from 0001 to 7777) is generated by the compiler. E+ The first seven characters of the routine name are taken as the entry-point name. An extended form of E may be used to create an entry-point unrelated to the name of the procedure. The following example illustrates this form for procedures and functions: FUNCTION (*$E'P.FLR' *) FLOOR(X : REAL) : INTEGER; The entrypoint for function FLOOR is actually "P.FLR". This gives the ability to define any entry point accepted by the loader, even ones which include special characters (such as period). This form of the E option applies equally to "EXTERN", "FORTRAN", and local routines, but E must be OPTIONS.7 1 P-6000 - Compiler Options 27 May 86 specified between the word "FUNCTION" or "PROCEDURE" and the routine name itself. b) For the main program and main variables block, the E option has a similar effect. E- "P.MAIN" is used for the main program entry-point name, and "P.MAIN;" is used for the entry-point name of the main variables block. E+ The first seven characters of the program name are used for the entry-point name of the main program, and the first six followed by a semicolon are used for the entry-point name of the main variables block. The extended form of the E option may be used for the main program, but two names should be specified for the main program block and the main variables block: PROGRAM (*$E'P.MAIN'/'P.VARS' *) MYPROG(OUTPUT); c) Labels that are used by GOTO statements which exit a block are automatically assigned an entry-point name with the form "PASCL.x" (where x is a letter or digit). The entry-point name of any label may be explicitly assigned by using the extended E option. In this case, the E option must immediate- ly precede the declaration of the label: LABEL (*$E'L.1'*) 1, 2, (*$E'L.OOPS'*) 13; Whenever a truncated name is taken (under E-) it is your responsibility to avoid the occurrence of duplicate entry-point names. When you use the extended form of the E option, it is also your responsibility to avoid duplicate entry-point names and to be sure that the entry-point name is one which is accepted by the system loader. The extended form of the E option exists mainly for the Pascal library. It is potentially dangerous--use with care. Default is E-. I : Controls the inclusion of external text. See Chapter INCLUDE. L : Controls the listing of the program text. The L option can be used to turn the listing on and off during compilation. L+ turns the listing on and L- turns it off. Following the L by a character string sets the page title or subtitle. Example: (*$L'SAMPLE PAGE TITLE' *) The first such specification sets the main title, and all subsequent ones set the subtitle. The listing continues on a new page. To set the title on the first printed page, the L option must appear on the first line. The LT option can be used to reset the main title; see below. The program listing is a record of the Pascal compilation. It shows the time and date of compilation, the version of the Pascal compiler used (as well as the date it was last changed, and the operating system and installation name under which the compiler OPTIONS.8 1 P-6000 - Compiler Options 27 May 86 resided). Programming aids for cross-referencing, and pretty- printing Pascal program listings are described in the Pascal Software Tools (PTOOLS) writeup. Each line of the program source is numbered on the listing and can be used for post-mortem dump analysis (see P option below). The octal numbers given beside each source line are the values of the location counter for data within the declaration part of a block and the instruction counter for statements within the statement part of a block. These numbers give an indication of how much storage is being used in each part of your program. Default title is set by each site. Default is L+. LT : Reset main title for compiler-listing. LT replaces the main title with its character string and blanks out the subtitle. The listing continues on a new page. Example: (*$LT'NEW TITLE' *) MB : Specify initial amount of managed memory. The MB option setting specifies the minimum amount of memory that will be available for use at the beginning of execution. Its form is: (*$MB2000 START WITH 2000 WORDS OF MEMORY *) If MB0 is specified, the compiler will compute a value for MB. If MB setting is less than the compiler-calculated requirement, the compiler will increase the setting. Default is MB0. MD : Specify memory reduction parameters. The MD option has two forms, and specifies when unused managed memory should be released by decreasing your program's field length. The first form of the MD option specifies the minimum amount of memory that must be available before the Pascal Memory Manager (PMM) will try to reduce your field length. Its form is: (*$MD2000 REDUCE MEMORY WHEN 2000 WORDS AVAILABLE *) If MD0 is specified, memory will be released as soon as it becomes available. Default is MD1536 (MD3000B). The second form of the MD option controls whether or not available memory should be released: (*$MD+ RELEASE MEMORY IF ENOUGH BECOMES AVAILABLE *) (*$MD- DO NOT RELEASE AVAILABLE MEMORY *) Default is MD-. MF : Specify maximum field length. This option specifies the maximum amount of memory that will ever be assigned to your program, subject to the restrictions of your account validations or MFL(nnnnn) control-statement setting. If your program requires additional memory, an error condition will exist and your program will be terminated with the error message OPTIONS.9 1 P-6000 - Compiler Options 27 May 86 "MEMORY REQUIRED EXCEEDS SPECIFIED MFL." The MF option has the form: (*$MF80000 USE NO MORE THAN 80000 WORDS *) If MF131071 is specified, the maximum field length used by your program is limited only by a MFL(nnnnn) control-statement or your account validations. Default is MF131071 (MF377777B). MI : Specify memory allocation parameters. The MI option has two forms that specify how memory should be allocated by your program. The first form of the MI option specifies the minimum number of words of memory that will be requested if your program requires additional memory, subject to MFL restrictions: (*$MI5000 REQUEST AT LEAST 5000 WORDS AT A TIME *) If MI0 is specified, PMM will request only enough memory to satisfy the immediate needs of your program. This can be useful if your program requires an amount of memory that is very close to the maximum you may use, but this setting will cause your program to execute more slowly and may cause your program to roll out more often. Default is MD1024 (MD2000B). The second form of MI determines whether or not your program is allowed to request additional memory. It has the forms: (*$MI+ REQUEST ADDITIONAL MEMORY, IF NEEDED *) (*$MI- NEVER REQUEST ADDITIONAL MEMORY *) If MI- is specified and your program requires additional memory, an error condition will exist and your program will be terminated with the error message "MEMORY REQUIRED EXCEEDS SPECIFIED MFL." The default is MI+. MR : Select initial memory reduction. The MR option selects whether or not the initial amount of memory assigned to your program will be reduced to the amount specified by the MB option, if it exceeds that value. (*$MR+ REDUCE TO "MB" WORDS OF MANAGED MEMORY *) (*$MR- DO NOT REDUCE MEMORY AT STARTUP *) If MR- is specified, the initial amount of memory assigned to your program will be at least your current field length. If your current field length was not high enough to allow "MB" words of managed memory, additional memory will be requested. This option replaces the R option used by previous releases of Pascal-6000. It is recommended that the default setting be used. Default is MR+. OPTIONS.10 1 P-6000 - Compiler Options 27 May 86 MS : Specify initial stack chunk size. The MS option specifies the mimimum amount of memory that will allocated when the program starts for the first run-time stack chunk. (*$MS500 INITIAL STACK CHUNK IS AT LEAST 500 WORDS *) If MS0 is specified, every call made by the main program will cause a stack chunk to be allocated (with a size controlled by the MX option, below). Default is MS512 (MS1000B). MV : Specify minimum size for off-stack allocation. Any variable in a procedure or function that is at least as large as the latest setting of the MV option where the variable is declared is called "very large" and is allocated separately from the current stack chunk when the procedure or function is called. (*MV5 ALLOCATE VARIABLES OF 5 OR MORE WORDS SEPARATELY *) The smallest setting allowed for MV is 2. Default is MV64 (MV100B). MX : Specify minimum stack-extension chunk size. The MX option specifies the minimum size of any stack chunk allocated after the initial stack chunk. (*MX10 EACH STACK EXTENSION IS AT LEAST 10 WORDS *) Specifying MX0 will usually cause each stack-extension chunk to be only large enough for one procedure or function call; thus each call (after the initial chunk is full) would cause a new extension to be allocated. Ordinarily this would slow down a program. Default is MX256 (MX400B). MZ : Issue memory-change dayfile messages. If MZ+ is set, a dayfile message is issued before each request to the operating system to change the field length. If MZ- is set, these messages are not issued. Default is MZ-. O : Allow compiler options. The O compiler option switches on (O+) and off (O-) the processing of all compiler options specified in the source text of a program (options on the control statement are always allowed). Any Pascal-6000 user can import a program and see whether it conforms to the Standard by compiling it with S+,O- on the Pascal control statement. The effect of O- starts after the group of compiler options that contains the O-. Once O- has been set, O+ cannot have an effect. Default is O+. P : Control Post-Mortem Dump (PMD). P+ directs the compiler to generate the code necessary to write a complete PMD in the case of a run-time error. The PMD provides a description of each procedure or function that was active at the time of the error, including the line number of the statement which was currently being executed and the names and values of all unstructured local variables. Values of pointer variables are printed as 6-digit OPTIONS.11 1 P-6000 - Compiler Options 27 May 86 octal addresses, and values of ALFA variables as 10-character strings. P+ is recommended until you are sure that your program is correct. P- suppresses most of the PMD information and only includes enough information to list the name of the procedure in which the error occurred. P0 is an option setting designed especially for the Pascal compiler and library. Individual procedures compiled with P0 are transparent to PMD. Compiling an entire program with P0 (set before the program heading) deletes the minimal information (2 words per procedure) which includes the name of the procedure and the locations of the entry point and constants, and disables the use of REPRIEVE (EREXIT under KRONOS). P0 can be used for production programs to delete all unnecessary traceback information. Default is P+. PL : Set line limit for program parameter OUTPUT. The PL option functions like the PL compiler control-statement parameter. Example: (*$PL0 SET INFINITE LINE LIMIT FOR OUTPUT *) Default is determined by the PL parameter on the compiler control statement. See the ACCESS chapter. Q : Generate Quick Code. This option controls compiler optimization of object code. Q+ means the compiler should generate "quick" code at the expense of code or data space; Q- means the compiler should reduce space at the expense of speed. The Q option can be used to increase the speed of frequently executed procedures and to decrease the size of infrequently executed procedures. The Q option affects only the entry/exit code for procedure and function blocks. Q+ generates in-line code, while Q- generates calls to common entry/exit subroutines in the Pascal-6000 run- time system. Default is Q-. S : Flag nonstandard extensions. This option, S+, issues clear and unambiguous, nonfatal, warning messages indicating the use of nonstandard Pascal-6000 extensions. Extensions whose use cannot be detected except by executing the program are not controlled by the S option. For convenience, S may be switched on (S+) or off (S-) anywhere in a Pascal program with well-defined results in all cases. Default is S-. T : Control run-time tests. T+ directs the compiler to generate extra code to perform run-time tests that check a) All array-indexing operations to ensure that the index lies within the specified array bounds. b) All assignments to variables of subrange types to make certain that the assigned value lies within the specified range. This check is also performed when READing such variables. c) All divisions to ensure against zero divisors. d) All MOD operations to ensure a positive modulus. e) All automatic integer-to-real conversions to assure that the absolute value of the result is less than MAXINT. OPTIONS.12 1 P-6000 - Compiler Options 27 May 86 f) All real expressions to ensure that there was no overflow or underflow. g) All CASE statements to ensure that the selector corresponds to one of the specified CASE labels (unless OTHERWISE is used!). h) All references to pointers as P^ -or- DISPOSE(P) to ensure that P is a valid pointer. The T option must be selected (T+) both when the pointer type is declared and when the pointer is referenced. i) All assignments to SET variables to ensure that the set elements are within the declared range. j) All uses of EOLN(F) to ensure EOF(F) is false. T+ also causes the compiler to generate extra code to perform the following: a) Local variables are initialized to an unusual value when a procedure or function is called. b) A dynamic (heap) variable is initialized to an unusual value when it is allocated. c) A for-statement control variable is set to an unusual value when the for statement is exited normally. Such unusual values are selected to make it likely that uses of those values will be trapped by range tests or hardware. T+ is recommended even after you are sure that your program is correct. Default is T+. U : U+ restricts the number of characters scanned by the compiler in every source line to 72. This is convenient when using the default widths under the UPDATE or MODIFY text-maintenance programs. With U- the number of relevant characters is 150. U may also be set to any specific numeric value between 10 and 150. The remainder of the line (past the width specified by this option) is ignored. The U option is best used on the first line of the Pascal source program. Default is U-. X : Determines the number of X registers used for passing parameter descriptors. If the value of the X option is a number N (0 <= N <= 5), the first N parameter descriptors are passed in the registers X0 to X(N-1) (the first in X0, the second in X1, and so on). Extra parameters are passed through a table in memory. See EXTERN for a more complete description of the Pascal calling sequence. N>0 reduces the size of the code produced by the compiler and probably also slightly improves the code. However, the program- mer must be aware that for the Ith parameter and with N>0, the compiler cannot use registers X0 to XJ (where J is the minimum of (N-1) and (I-2)) for its computation. It is therefore possible that for N>0, the compiler gives the message "EXPRESSION TOO COMPLICATED" where for smaller N, it would not. Default is X4. OPTIONS.13 1 P-6000 - Compiler Options 27 May 86 Z : Issues Statistics messages. The Z option controls the printing of statistics messages issued by the run-time system. The three messages currently printed are the LOAD FL, START FL message, the HIGHEST FIELD LENGTH message, and the CP SECS, MAX CM USED message. Z- inhibits the printing of these messages; Z+ means that the messages will be issued. Z- can be used in conjunction with MESSAGE to issue other messages to the dayfile. Default is Z+. Note: The A, E, I, O, and U options can change the meaning of a program, and are flagged with warning messages when both the S and O options are on (S+ and O+). OPTIONS.14 1 P-6000 - Compiler Limits and Restrictions 27 May 86 Compiler Limits in Pascal-6000 ============================== Limits exists on various quantities within the Pascal compiler. Compile-time error messages are issued when these limits are exceeded, unless otherwise noted. Explanations of these limits follow. 1. The compiler reads at most 150 characters from a source line; any characters beyond 150 are ignored. The user is responsible for ensuring that the compiler-produced listing does not exceed the maximum line length for the printer to which the listing is routed. The compiler does not issue an error message about lines exceeding 150 characters. 2. The nesting of identifier scopes (procedure and function blocks, parameter lists, record types, and with statements) is limited to 20 levels. (Compiler error number 250.) 3. The number of identifier scopes created by procedure and function blocks, parameter lists, and record types, is limited to 131071. (Compiler error number 252.) 4. Procedure and function declarations may be nested to a maximum depth of nine (9). (Compiler error number 251.) 5. The maximum number of procedure and function declarations (includ- ing EXTERN and FORTRAN declarations) is 4095. (Compiler error number 264.) 6. The number of external objects (procedures, functions, and non- local labels) referenced by a statement-part plus one-half of the number of references to those objects by the statement-part is limited to 4095. (Compiler error number 256.) 7. The compiler will refuse to compile expressions that require more registers than are available. (Compiler error number 259.) 8. The number of parameters in a parameter list is limited to 1023. (Compiler error number 263.) 9. The maximum number of labels that are referenced non-locally by goto-statements anywhere in a program is 36. (Compiler error number 260.) 10. The maximum number of external files (files declared in the | program heading) is limited to 50. (Compiler error message 254.) | 11. No more than 10 errors and warnings will be issued on any one source line. (Compiler warning number 354.) 12. The difference between the ordinals of the smallest and largest case-constants in a case-statement must be less than 2001. (Compiler error number 157.) 13. The base-type of a set-type must be one of the following: (a) An enumerated-type with at most 59 values. (b) A subrange where the ordinal values of the smallest and largest values of the subrange are in the interval 0..58. LIMITS.15 1 P-6000 - Compiler Limits and Restrictions 27 May 86 (c) A subrange of CHAR with the largest value of the subrange less than or equal to chr(58) ("<"). (Compiler error number 163.) 14. The code space for a block (program, procedure, or function) includes the executable code for the statement-part of the block, the constants referred to by those statements, compiler-created initialization and finalization code, and (optionally -- see the "P" compiler option) tables used by PMD to describe the variables declared local to the block. The maximum number of words allowed for any one code space is 32768 (100000B). (Compiler error number 253.) 15. The data space for a block (program, procedure, or function) includes locations for the variables declared in the block, for value parameters declared in any associated procedure or function heading, and for some compiler-created temporaries. The maximum number of words allowed for any one data space is 131072 (400000B). (Compiler error number 261.) LIMITS.16 1 P-6000 - Memory Management 27 May 86 Memory Management ================= Pascal-6000 Memory Management ----------------------------- Pascal-6000 is designed to adapt dynamically to the memory require- ments of a Pascal program. That is, when a program requires more memory either due to procedure or function calls or due to allocation of dynamic ("heap") variables, the run-time system is able to request more memory from the operating system. Thus you need not know in advance how much memory your program will need, and you do not have to use an RFL control statement to allocate that memory. This capability is known as memory management. There are several compiler options that control memory management. The default values for these options are adequate for nearly all programs. This chapter gives an overview of the way in which memory is used and managed, and indicates some situations in which use of the memory- management compiler options might be appropriate. For information on | using the Common Memory Manager, see chapter CMM. | Static Space and Managed Space ------------------------------ A Pascal program is divided into two major kinds of memory space: the static memory and the managed memory. The static memory contains the machine code and global variables for the program, as well as the Pascal-6000 run-time system. This space is fixed by the system relocatable loader. The rest of the job's memory is available for dynamic management by Pascal-6000. In order to allow the managed space to expand and contract without affecting the static space, the static space exists at the lower end of the job's field length. The memory manager can obtain and relinquish memory for the Pascal program by increasing or decreasing the job's current field length (FL). FL can be increased up to the limit that we call the Maximum FL. The following diagram illustrates this. 0 |-----------------| | | | Static Space | | | Load FL |-----------------| | | | Managed Space | | | FL |-----------------| | | | Available Space | | | Maximum FL |-----------------| The available space can be considered part of the managed space in that the program may use it, if necessary. However, the available MEMORY.17 1 P-6000 - Memory Management 27 May 86 space can be used by the operating system for other jobs. A job tends to cost less and finish sooner if its FL is kept only as large as necessary. Thus, there is a practical distinction between managed space and available space. The Load FL is the lowest address of the managed memory space. The Maximum FL is the smallest of the following three quantities. a) The job's maximum validated field length. b) The setting of the most recent MFL control statement in the job. c) The setting of the MF compiler option when the executing program was compiled. The Start FL (FL when the program starts executing) is determined by the following formula. Let IWS (Initial Work Space) be the greater of (a) the MB compiler option setting and (b) a compiler-generated minimum value determined from the actual program. (The default value of MB is the compiler-generated minimum.) If the MR compiler option is turned on (MR+), as it is by default, then the Start FL is equal to Load FL + IWS. If the MR option is turned off (MR-), then the Start FL is the greater of Load FL + IWS and the job's running FL (set by the last RFL control statement). Allocation and Liberation of Nodes ---------------------------------- The executing Pascal program makes essentially two kinds of demands for memory management: the program can "allocate" a region (called a "chunk") of the managed memory space, and the program can "liberate" any chunk that it has allocated. The managed memory space is partitioned completely into areas called "nodes." Some nodes, called "non-free," contain the memory space that belongs to a chunk allocated by the program. The rest of the nodes are called "free" and contain space that is available for allocation. When the program allocates a chunk, the memory manager attempts to find a free node that is large enough to satisfy the program. If it cannot, then either the managed space must be expanded or else the program cannot continue. Suppose that the managed space must be expanded by a quantity K to satisfy the program. The following steps are used. 1) If the MI compiler-option switch is turned off (MI-), then no increase in FL can occur and the program is terminated; otherwise 2) If FL + K is greater than the Maximum FL, the program cannot be satisfied with the available space, and it is terminated; otherwise 3) If K is greater than the numeric setting of the MI compiler option, then FL is increased by K; otherwise 4) FL is increased either by the numeric setting of the MI option or else to Maximum FL, whichever is less. MEMORY.18 1 P-6000 - Memory Management 27 May 86 In short, the switch setting of the MI option controls whether an increase in FL is allowed, and the numeric setting of the MI option is the smallest increase that is allowed except where that would exceed Maximum FL. The default settings for MI are MI+ and MI2000B. Some programs liberate enough memory so that it would be useful for the managed space to contract by relinquishing memory to the operating system. This capability is controlled by the following steps which are invoked whenever a chunk is liberated near the high end of managed space. 1) If the MD compiler option is turned off (MD-), as it is by default, then no FL decrease can occur; otherwise 2) If the amount of memory occupied by the free nodes at the high end of managed space is greater than the numeric setting of the MD option, then FL is decreased so that there nearly all of that memory is placed in the available space. In short, the switch setting of the MD option determines whether a decrease in FL is allowed, and the numeric setting determines the smallest decrease that is allowed. The MD option is turned off by default to avoid frequent increases and decreases in FL that many programs might experience, because such behavior tends to increase the operating system overhead. Program Use of Managed Space ---------------------------- There are essentially three ways that a program might allocate or liberate managed memory. a) When the procedure NEW is called, a new chunk must be allocated to store the new variable that is created. When DISPOSE is called, the chunk that contains the variable is liberated. b) When a procedure or function is called, an object called an "activation record" is created; this contains information such as the place where the procedure or function was called and also often contains space for the variables that are declared in the procedure or function. c) Some variables declared in procedures or functions, and certain other objects needed by the program (such as file buffers) are allocated separately from the activation records in (b). Both (a) and (c) are handled simply by allocating a chunk for each object or variable as needed. However, if each procedure or function call had to allocate a new chunk for its activation record, and if the corresponding return had to liberate the chunk, the efficiency of calls would be degraded. Therefore the following scheme is employed. Activation records are created and destroyed in a stack discipline -- last created is first destroyed. The stack of activation records is broken into chunks called "stack chunks," each of which can contain one or more activation records. When a procedure or function is called, its activation record is placed in the "current" stack chunk MEMORY.19 1 P-6000 - Memory Management 27 May 86 if it will fit. If it will not fit, then a new chunk is allocated from managed memory and it becomes the current stack chunk. That stack chunk is liberated when that call is terminated (i.e., the procedure or function returns, or a non-local goto statement causes the procedure or function to terminate). The size of the first stack chunk is determined by the MS compiler option setting; the first chunk is allocated when the program starts executing and exists until the program terminates. Subsequent stack chunks are always at least as large as the numeric setting of the MX compiler option; a chunk can be larger if the first activation record in the chunk is larger than the MX option setting. For this scheme to be efficient, most activation records must be small relative to the size of the stack chunks. In order to make this more likely, the compiler will allocate a variable declared in the block of a procedure or function separately from the activation record for the block if the size of the variable exceeds the numeric setting of the MV compiler option at the point at which the variable is declared. Dayfile Messages ---------------- When the program is compiled with the Z compiler option turned on (Z+), as it is by default, the following dayfile messages are issued. Both the Load FL and the Start FL are displayed when the program starts executing in a dayfile message of the form nnnnnnB LOAD FL, nnnnnnB START FL. When the program completes execution normally, the messages nnnnnnB HIGHEST FIELD LENGTH. xxx.xxx CP SECS, nnnnnnB MAX CM USED. indicate the largest value attained by FL during execution (HIGHEST FIELD LENGTH) and the highest address in managed memory actually used during execution (MAX CM USED). The HIGHEST FIELD LENGTH is usually just slightly larger than MAX CM USED. When the program is compiled with the MZ compiler option turned on (MZ+) the following dayfile message is issued before each change in FL during the program execution. REQUESTING FL CHANGE TO nnnnnnB. The MZ option is turned off (MZ-) by default. MEMORY.20 1 P-6000 - Using Common Memory Manager 27 May 86 Using Common Memory Manager | =========================== | | Ordinarily, Pascal-6000 Release 4 does memory management with its own | internal routines, collectively called PMM (Pascal Memory Manager). | PMM is not compatible with the standard Control Data routines, called | CMM (Common Memory Manager). Several Control Data products (e.g., | Cyber Record Manager) require CMM (at least for some functions). As a | result, Pascal programs have not been able to make use of those | Control Data products. | | Pascal-6000 includes an optional interface allowing a program to use | CMM instead of PMM. Thus programs can make use of other Control Data | packages that also use CMM. | | Because CMM is larger and slower than PMM, however, we recommend that | programs not needing CMM simply use PMM. | | The Pascal-6000/CMM interface is called PASCMM (or sometimes P.CMM). | It is selected when your program is linked by including the following | loader control statement at the beginning of your "load sequence": | | LIBLOAD(PASCLIB,PASCMM) | | The term "load sequence" refers to the sequence of control statements | processed by the Cyber Loader that cause your program to be linked and | possibly executed. The most common load sequence is simply the "LGO." | statement, as in the following example: | | PASCAL(L=0) | LIBLOAD(PASCLIB,PASCMM) | LGO. | | Another common sequence is where you wish to create an absolute binary | (executable) file: | | PASCAL(L=0) | LIBLOAD(PASCLIB,PASCMM) | LOAD(LGO) | NOGO(ABS) | ABS. | | The above sequence creates and then executes the absolute file ABS. | | Note in each of the above examples that the LIBLOAD statement is the | first loader control statement in the load sequence. Failure to | observe this restriction could cause any of the following error | messages to be generated when the program is executed: | | PMM/CMM CONFLICT; P.CMM ALSO LOADED. | PMM/CMM CONFLICT; P.PMM ALSO LOADED. | PMM/CMM CONFLICT; P.AHM ALSO LOADED. | PMM/CMM CONFLICT; CMM ACTIVE. | | For additional information about load sequences and loader control | statements, see the Cyber Loader Reference Manual (CDC #60429800). | CMM.21 1 P-6000 - Predefined Types 27 May 86 Standard Predefined Types (INTEGER, REAL, CHAR) ----------------------------------------------- The standard identifier MAXINT is defined as CONST MAXINT = 281474976710655; (* MAXINT = (2 raised to the power 48) - 1 *) The hardware provides no indication of overflow for integers. It is the responsibility of the programmer to provide a check whenever this might occur. In actuality, it is possible to create a valid integer with absolute value larger than MAXINT, but then only the operations of addition, subtraction, absolute value, multiplication and division by powers of 2 (implemented as shifts), and comparisons are correctly executed in this range (as long as no overflow occurs). Integers larger than MAXINT may also be read and written. Literal integer constants may be expressed in octal form by appending a post-radix "B" (for example 37777B). The only value that cannot be expressed in this manner is negative zero (77777777777777777777B), a value to avoid anyway. The type REAL is defined according to the hardware. Approximately 14 significant digits are provided. The range of absolute magnitude is approximately 10 raised to the power -294 to 10 raised to the power 322. A value of type CHAR is an element of the CDC 63/64 character sets in display code order from 0 to 63 (see CHARSET). Two non-standard character constants are predefined in Pascal-6000 to alleviate the problems caused by the CDC 63/64 character sets: COL = CHR(0) PER = CHR(51) (* = CHR(63B) *) Nonstandard Predefined Types (ALFA, MARKER) ------------------------------------------- The type ALFA is a predefined string type with the definition TYPE ALFA = PACKED ARRAY [1..10] OF CHAR; ALFA constants are simply strings of exactly 10 characters. The type MARKER is used only with the predeclared procedures MARK and RELEASE. See chapter HEAP for details. TYPES.22 1 P-6000 - Nonstandard Predeclared Procedures and Functions 27 May 86 Nonstandard Predeclared Procedures ---------------------------------- DATE(A) - Assigns the current date to the ALFA variable A. The form of the date for KRONOS and NOS is ' YY/MM/DD.', and for SCOPE and NOS/BE it is ' MM/DD/YY.' GETFILE(F) -or- GETFILE(F,N) - are discussed in the chapter FILES. | GETSEG(F) -or- GETSEG(F,N) - are discussed in the chapter on segmented files (SEGFILE). HALT -or- HALT(S) - Terminates the execution of the program and displays a post-mortem dump. If the second form is used, the string S is written to the dayfile (and in the PMD) as an error message. S should contain no more than 80 characters. MARK(M) - is discussed in the chapter HEAP. MESSAGE(S) -or- MESSAGE(S,N) - writes the string S into the dayfile or to the control point. If N is not in the range 0..7, or if N is not specified, then N = 3 is assumed. N Message Destination - ------------------- 0 System dayfile, user dayfile, and line 1 of control point. 1 Line 1 of control point. 2 Line 2 of control point. 3 User dayfile and line 1 of control point. 4 Error log dayfile if SSJ= or system origin; user dayfile otherwise. 5 Account dayfile if SSJ= or system origin; user dayfile otherwise. 6 Same as n=0. 7 Same as n=3. MNEW(P) -or- MNEW(P,C1,...,Cn) - are discussed in the chapter HEAP. PUTFILE(F) - is discussed in the chapter FILES. | PUTSEG(F) - is discussed in the chapter on segmented files (SEGFILE). RELEASE(M) - is discussed in the chapter HEAP. REWRITE(F,N) - is a nonstandard, extended form of REWRITE(F) and is discussed in the chapter on segmented files (SEGFILE). TIME(A) - Assigns the current time to the ALFA variable A in the form ' HH.MM.SS.'. Nonstandard Predeclared Functions --------------------------------- CARD(S) - Returns the cardinality of the set expression S (the number of elements contained in the set). PROCS.23 1 P-6000 - Nonstandard Predeclared Procedures and Functions 27 May 86 CLOCK - Returns an integer value equal to the central processor time, expressed in milliseconds, already used by the job. CLOCK is a function without parameters. EOI(F) - is discussed in the chapter FILES. | EOS(F) - is discussed in the chapter on segmented files (SEGFILE). EXPO(X) - Yields an integer value equal to the exponent of the floating-point representation of the real expression X. RELVALUE(K,N) - Extended inverse ORD function. Given an ordinal | expression K and an integer expression N, RELVALUE returns a | value that has the same type as K and satisfies the following | condition: | ORD(RELVALUE(K,N)) = ORD(K) + N. | RELVALUE returns the Nth successor of K if N is positive, or the | -Nth predecessor if N is negative. | If: COLOR = (RED,ORANGE,YELLOW,GREEN,BLUE,INDIGO,VIOLET); | then: RELVALUE(RED,2) returns YELLOW. | RELVALUE(0,67) returns 67. | RELVALUE('0',4) returns '4'. | RELVALUE(VIOLET,1) is an error. | RELVALUE(VIOLET,-8) is an error. | ORD(NS) (nonstandard, extended usage) - Returns an integer representa- tion of the real or pointer expression NS. TRUNC(X,N) (a nonstandard, extended form of TRUNC) - Returns the integer part of the real expression X * K, where K is 2 raised to the power N. UNDEFINED(X) - Returns a boolean value which is true when the real expression X is out of range ("infinite" or "indefinite"). Notes: ------ See the PASCLIB writeup for descriptions of additional procedures and functions which are not predeclared in Pascal-6000. To access them, they must either be declared as EXTERNs (see EXTERN) or in some cases may be included with the I compiler option (see INCLUDE). Chapter SYMBOLS contains a complete list of names of all predeclared procedures and functions, both standard and nonstandard, as well as names of predefined constants and types. PROCS.24 1 P-6000 - The Program Heading and External Files 27 May 86 The Program Heading and External Files ====================================== A Pascal file variable is implemented as a file in the operating system. Internal files (those that exist only during the execution of the program) are allocated on disk store. This storage is allocated when the file is generated and automatically released when the block to which they are local is exited. Files that exist outside the program (external files) may be made available to the program if they are specified as formal parameters on the program heading, or given as actual parameters on the control statement which executes the program. Actual files specified on the control statement are substituted for the formal file names in the program heading. The heading has the form program-heading = "program" identifier [ program-parameter-list ] . program-parameter-list = "(" program-parameter { "," program-parameter } ")" . program-parameter = identifier { program-parameter-characteristics } . program-parameter-characteristics = "+" | "/" . Thus each file name in the program heading can be followed by a sequence of plus signs and slashes. + indicates that the file is a segmented textfile. The plus sign is ignored after any file other than INPUT or OUTPUT. See chapter SEGFILE. / indicates that the file is an interactive input file. See chapter INTERIO. The program parameters are formal file identifiers, but they must also be declared as file variables in the main program in exactly the same way as local file variables. Files denoted by the formal file parameters "INPUT" and "OUTPUT" have a special status. The following is a list of notes and exceptions. 1. The program heading need not contain the formal parameter OUTPUT. | If OUTPUT is omitted and the P compiler option is NOT set to zero | (P0) before the program heading, then a PMD file is created and | connected to OUTPUT. This allows the user to omit OUTPUT from the | program heading and still get a post-mortem dump to aid in | debugging. | 2. In contrast with all other external file identifiers, the two formal identifiers INPUT and OUTPUT must not be explicitly declared because their declaration is automatically assumed to be: VAR INPUT, OUTPUT : TEXT; or if followed by a plus sign on the program heading (see SEGFILE): PRGHEAD.25 1 P-6000 - The Program Heading and External Files 27 May 86 VAR INPUT, OUTPUT : SEGMENTED TEXT; 3. If no files are specified on the program heading, the load-and-go (LGO) control statement is not scanned for file names (see ACCESS). In this case, all parameters on the LGO control statement can be used for any purpose. 4. The procedures RESET and REWRITE have no effect if applied to the actual files INPUT and OUTPUT. If an actual parameter in the load-and-go (LGO) statement of the control statement record is left empty, the corresponding formal parameter in the program heading is then assumed as the actual file name. For example, when calling a program with the heading PROGRAM P(OUTPUT,F,CHICKENFEATHERS); the statement LGO(,X,) is equivalent to LGO(OUTPUT,X,CHICKEN) Note that if the formal file name is larger than seven characters, only the first seven are used for the assumed actual file name. PRGHEAD.26 1 P-6000 - Representation of Files, Use of External Files 27 May 86 Representation of Files ======================= It is sometimes important to know the representation of external files chosen by the Pascal compiler. Every component of a Pascal-6000 file occupies an integral number of 60-bit words, with the exception of textfiles (variables of type TEXT). Pascal-6000 uses the standard CDC representation for textfiles: 10 characters are packed into each word, implying that the procedures PUT and GET include packing and unpacking operations for textfiles. The end of a line is represented by at least 12 right-adjusted zero-bits in a word. The operating system requires that each line of a textfile contain an even number of characters; thus the procedure WRITELN will add a trailing blank when necessary to accomplish this. Files originating from card decks follow the same textfile conventions. Note that the operating system removes most (but not necessarily all) trailing blanks when reading cards, hence such files do not necessarily consist of full 80- character card images. Files that are not segmented consist of one or more logical files (in | operating system terminology). Pascal-6000 provides nonstandard pre- | declared procedures for reading and writing multi-file files (see | point 5 below). During reading, end-of-record marks on an unsegmented | external file are ignored (for an exception see point 3 below). In segmented files, each segment corresponds to a logical record (see SEGFILE). Use of External Files ===================== 1. If an external file is to be read, then in the case of non- segmented files, reading must be initiated by the statement RESET(X) and in the case of segmented files (see SEGFILE) by RESET(X) GETSEG(X,N) (This statement is automatically implied for the file denoted by the formal parameter INPUT, and need not be specified by the programmer.) 2. Every external file is automatically opened by the Pascal run-time system. If the file is intended for reading only (such as a direct-access permanent file or magnetic tape without write permis- sion), then it is the responsibility of the programmer to ensure that no write operations will be attempted on such a file. 3. The RESET procedure normally rewinds the file given as its parameter. In the case of the actual file INPUT, however, RESET will not reposition the file. Additionally, for the actual file INPUT, the end-of-file condition is true at an end-of-record mark rather than an end-of-file mark as with all other files unless INPUT is a segmented text file (i.e., it is followed by a "+" in the program heading). FILES.27 1 P-6000 - Representation of Files, Use of External Files 27 May 86 4. The REWRITE procedure normally rewinds the file given as its parameter. In the case of the actual file OUTPUT, however, REWRITE will not reposition the file. All files specified in the program heading (except INPUT) are initially ready for writing. No REWRITE is necessary unless you want to rewind the file, or you have already read from the file. (This is nonstandard. The standard requires REWRITE before writing on every file except OUTPUT.) 5. The following nonstandard predeclared procedures and function are | provided for reading and writing multi-file files: | | GETFILE(F) - Initiates the reading of the next file in a multi-file | file F. F^ becomes the first component, if any, of the new file. | If the new file is empty, or the current file is the last file in | F, then EOF(F) becomes true and F^ is undefined. | | GETFILE(F,N) - Initiates reading of the Nth file, counting from the | current position, in a multi-file file F. N > 0 implies counting | files in a forward direction. N = 0 repositions the file at the | beginning of the current file. (If already at the beginning of a | file, the file position is unaffected.) N < 0 skips backwards past | the beginning of the current file to the beginning of the Nth | previous file. Values of N that attempt to position the file past | the end-of-information or before the beginning-of-information leave | the file at the end- or beginning-of-information, respectively, and | cause no error. For values of N where abs(N) > 777776B, the | results are operating-system dependent. GETFILE(F,1) is equivalent | to GETFILE(F). | | PUTFILE(F) - Writes an end-of-file at the current position in F. | | EOI(F) - A boolean function indicating whether or not the end-of- | information has been reached while reading file F. When EOI(F) is | true, F^ is undefined. EOI(F) implies EOF(F) and, in the case of | segmented files, EOS(F). | 6. Magnetic tapes (except S and L format tapes) may be read and written with a Pascal program. However, it is necessary to have input-output buffers which are large enough to handle tapes. The buffers for external tape files must be at least 513 words long. Use the "B" compiler option (See Chapter OPTIONS) to change the length of these buffers. 7. Files declared local to procedures and functions are called internal files, but like external files, they use secondary storage external to the program. The external operating system file names SCR1 through SCR9999 are used by internal files which exist only during the activation of a procedure or function. You should avoid using these file names in a job running a Pascal program. FILES.28 1 P-6000 - Segmented Files 27 May 86 Segmented Files =============== The operating system allows a file to be subdivided into segments of varying lengths, where each segment is called a "logical record" in operating system terminology. Pascal-6000 offers a facility for declaring a file to be segmented. The declaration is VAR F1: SEGMENTED FILE OF T1; where T1 is the component type of the file or VAR F2: SEGMENTED T2; where T2 is some file type identifier. Segmented files are implemented with sequential (forward) file pro- cessing; they are not random access. Do not use them for random- access to a file. Doing so will result in very inefficient and costly processing. A number of operations are available to end a segment when generating a file and to recognize segment boundaries when reading a file -- regardless of the component type. Assume F is any segmented file variable. PUTSEG(F) - Completes the generation of the current segment when writing file F. EOS(F) - A boolean function indicating whether the end of a segment has been reached while reading the file F. When EOS(F) is true, F^ is undefined. EOF(F) implies EOS(F). GETSEG(F) - Initiates the reading of the next segment of the file F. F^ becomes the first component, if any, of the new segment. If the new segment is empty, EOS(F) becomes true and F^ is undefined. If there is no next segment, EOF(F) becomes true and F^ is undefined. An operating system end-of-file mark embedded within a file can be skipped over by using GETSEG. An advantage of segmented files is the possibility of positioning the reading and writing head to any segment in the file. For the purposes of reading and (re)writing a segmented file, the procedures GETSEG and REWRITE are extended to accept two parameters. The second parameter N is a "skip count" in the range -777777B..777777B. If ABS(N) = 777777B the action performed depends on the operating system; otherwise the following descriptions hold. GETSEG(F,N) - Initiates the reading at the beginning of the Nth segment counting from the current one. N>0 implies counting segments in the forward direction, N<0 means counting them backwards, and N=0 indicates the current segment. Note that GETSEG(F,1) is equivalent to GETSEG(F). REWRITE(F,N) - Initiates the (re)writing of F at the beginning of the Nth segment counting from the current position. Note that REWRITE(F,1) is NOT equivalent to REWRITE(F). The latter causes initiation of (re)writing at the beginning of the entire file. SEGFILE.29 1 P-6000 - The Standard Input and Output Procedures 27 May 86 The Standard Input and Output Procedures ======================================== The standard procedures READ and WRITE (READLN and WRITELN) may be applied to any textfile for a convenient means of performing input and output. They may be used to do free-format reading and writing of characters and numbers (integers and reals) expressed in character form. In addition, booleans and strings may be written. The form of a READ or WRITE call is READ(F,V1,V2, ... ,Vn) -or- WRITE(F,E1,E2, ... ,En) where F is a textfile and the Vi are variables of type INTEGER, REAL, or CHAR (or subrange thereof), and the Ei are expressions of type INTEGER, REAL, CHAR, BOOLEAN, or any string type. The first parameter (the textfile) may be omitted READ(V1,V2, ... ,Vn) -or- WRITE(E1,E2, ... ,En) for the default files INPUT (for READ) and OUTPUT (for WRITE). The free-format field widths for writing are: type width ---- ----- BOOLEAN 10 CHAR 1 INTEGER 10 REAL 21 (the exponent form is always: E+999) a string length of the string. Formatted writing may be done by following the expression which is to be written by a field specification. The field specification must be greater than zero. For example WRITE( SQR(N):5 , C:10 ) will write SQR(N) in a field of five characters and C in a field of ten. A field specification can in fact be any integer expression: WRITE( SUM : I+J ) Reals are written in exponential format unless two fields are given. WRITE( R:10:4 ) will write R in a field of ten characters with four digits following the decimal point. Field widths will be increased automatically by the Pascal WRITE routine if necessary for the printing of a large integer or real number. This feature may be useful to ensure the suppression of leading blanks. For example WRITE( '$':10, MONEY:1 ) would "protect" the integer dollar amount from alteration. READWRI.30 1 P-6000 - The Standard Input and Output Procedures 27 May 86 A string, however, is truncated at the right if its length is larger than the field specification. The procedure READLN(F) is used to skip to the first character of the next line in the file F, and the procedure WRITELN(F) is used to write the end of a line on file F. The conventions of the operating system regarding textfile representation are such that WRITELN(F) will add a blank at the end of a line if necessary to ensure an even number of characters. Hence, on a later reading, a textfile may contain a trailing blank that was never explicitly written. The procedures READLN(F,V1,V2, ... ,Vn) -and- WRITELN(F,E1,E2, ... ,En) are equivalent to READ(F,V1,V2, ... ,Vn); READLN(F) -and- WRITE(F,E1,E2, ... ,En); WRITELN(F) If a textfile is sent to an output device (such as a line printer) with a maximum width, you must ensure that no line is longer than that maximum, otherwise characters are lost upon overflowing the line. CDC line printers (and some operating system programs) by convention interpret the first character of each line as a "carriage control." The following characters in column 1 are interpreted to mean '+' no line feed (overprinting) ' ' (blank) single spacing '0' double spacing '1' skip to the top of a new page before printing In Pascal-6000, the standard procedure PAGE(F) performs a WRITELN(F) if needed to finish the current line, and then writes the character '1' in column 1. The default parameter to page is the standard file OUTPUT. Example: BEGIN REWRITE(F); PAGE(F); (* no WRITELN(F) is performed. *) WRITELN(F, ' STUFF'); PAGE(F); (* no WRITELN(F) is performed. *) WRITE(F, ' PARTIAL LINE '); PAGE(F) (* a WRITELN(F) is performed before the page-eject. *) END These statements write the following three lines on F: 1 STUFF 1 PARTIAL LINE 1 READ and WRITE can be used for non-character input and output. When applied to a non-text file, for example VAR I1,I2, ..., In : INTEGER; READWRI.31 1 P-6000 - The Standard Input and Output Procedures 27 May 86 F : FILE OF INTEGER; READ(F,I1,I2, ... ,In) -and- WRITE(F,I1,I2, ... In) are equivalent to I1 := F^; GET(F); I2 := F^; GET(F); ... ; In := F^; GET(F) -and- F^ := I1; PUT(F); F^ := I2; PUT(F); ... ; F^ := In; PUT(F) READLN and WRITELN are restricted for use with textfiles. READWRI.32 1 P-6000 - Text Input and Output Made Easier 27 May 86 Text Input and Output Made Easier ================================= This chapter describes how to read from a textfile in a relatively painless way. The chapter is organized in two sections. The first section presents guidelines for reading from textfiles, but does not attempt to justify those guidelines in any detail. For the more technically-minded and inquisitive reader, the second section tells in detail how text input-output works in Pascal and explains why the techniques given in the first section are necessary. How to read from a textfile --------------------------- Communication between computers and humans is almost always done through collections of characters which represent words or numbers. These collections of characters are usually structured into lines (just as this document is). The Pascal predefined type TEXT is a file type that represents fils structured as lines of characters. This does not mean that the file cannot contain numeric information. In fact, when you type a file of numbers, you are actually creating a file of characters which represent numbers. A file of any type other than TEXT, such as "FILE OF INTEGER", is a "binary" file and cannot be read or typed by a human. Thus the first guideline is: 1. For communication between humans and Pascal programs, use files of type TEXT. INPUT and OUTPUT are automatically declared to be textfiles when they appear in the program header. Reading numerical information from textfiles presents certain problems in Pascal, and a library package named IOAIDS (Input-Output Aids) is available to make text input-output somewhat easier. Thus, guideline two is: 2. Include the library package IOAIDS in your Pascal program by inserting the following compiler directive in your program immediately following the program heading. (*$I'IOAIDS' INPUT-OUTPUT AIDS. *) The IOAIDS package defines several names, including: EOLNS(F) a function which skips spaces and then tests for end-of-line. EOFS(F) a function which skips spaces and end-of-lines then tests for end-of-file. See chapter IOAIDS in the PASCLIB writeup for a more complete description of the IOAIDS package. A common problem encountered when doing text input in Pascal is caused by the inconsistent nature of blanks as separators and terminators. Consecutive numbers are separated by blanks, and it is uncertain how many blanks follow the last thing that is typed on a line. In character information, however, blanks may function as more than separators. Thus the last two guidelines: TEXTIO.33 1 P-6000 - Text Input and Output Made Easier 27 May 86 3. When reading information separated by blanks (e.g., integer or real numbers), use EOFS and EOLNS to test for end-of-file and end-of-line. 4. When reading information where blanks are significant (e.g., reading a file character-by-character), use EOF and EOLN to test for end-of-file and end-of-line. The following examples illustrate these guidelines: PROGRAM PRINTCHARS(INPUT, OUTPUT); (* READ AND PRINT A FILE OF CHARACTERS, *) (* PRESERVING THE LINE STRUCTURE. *) VAR I : INTEGER; C : CHAR; BEGIN (* PRINTCHARS *) I := 0; WHILE NOT EOF(INPUT) DO BEGIN I := I + 1; WRITE(' LINE ', I, ' IS - '); WHILE NOT EOLN(INPUT) DO BEGIN READ(INPUT, C); WRITE(OUTPUT, C) END; WRITELN(OUTPUT); READLN(INPUT) END END (* PRINTCHARS *). PROGRAM PRINTINTEGERS(INPUT, OUTPUT); (* READ AND PRINT A FILE OF INTEGER NUMBERS, *) (* PRESERVING THE LINE STRUCTURE. *) (*$I'IOAIDS' INPUT-OUTPUT AIDS. *) VAR I,N : INTEGER; BEGIN (* PRINTINTEGERS *) I := 0; WHILE NOT EOFS(INPUT) DO BEGIN I := I + 1; WRITE(' LINE ', I, ' IS - '); WHILE NOT EOLNS(INPUT) DO BEGIN READ(INPUT, N); WRITE(OUTPUT, N) END; WRITELN(OUTPUT); READLN(INPUT) END END (* PRINTINTEGERS *). TEXTIO.34 1 P-6000 - Text Input and Output Made Easier 27 May 86 PROGRAM PRINTMIXED(INPUT, OUTPUT); (* READ AND PRINT A FILE WHERE EACH LINE HAS TWO *) (* INTEGER NUMBERS AND TWO REAL NUMBERS. *) (*$I'IOAIDS' INPUT/OUTPUT AIDS. *) VAR I,N1,N2 : INTEGER; X1,X2 : REAL; BEGIN (* PRINTMIXED *) I := 0; WHILE NOT EOFS(INPUT) DO BEGIN I := I + 1; READ(INPUT, N1, N2, X1, X2); WRITELN(OUTPUT, ' LINE ', I, ' IS - ', N1, N2, X1, X2); READLN(INPUT) END END (* PRINTMIXED *). For the Inquisitive Reader ========================== This section first describes in depth how files are defined and what the standard file routines do. It then goes on to show, through another example, how to manipulate textfiles. It is important to note that this section describes how a Pascal program deals with files. The definition of a file in Pascal is a datatype abstraction and does not necessarily correspond exactly to the way files are manipulated by the computer's operating system. A certain amount of translation is done in the Pascal-6000 operating-system-interface routines, but this is transparent to you as a Pascal programmer. The definition of files in Pascal: ---------------------------------- In Pascal, a file is defined as a sequence of elements, all of which are the same type. Thus a FILE OF INTEGER is a sequence of internal binary integers and a FILE OF PACKED ARRAY [1..10] OF CHAR is a sequence of 10-character strings. Every textfile is a sequence of 6-bit, CDC display-code characters interspersed with end-of-line markers. Every file in Pascal is a finite sequence, and this implies that there is a first element and a last element. Following the last element is an indication of the end of the file. We will use the abbreviation "eof" to mean "end of file". As far as Pascal is concerned, a file has an inherently sequential structure. This means that only one element of the file may be examined at a time, and that after examining a certain element of the file, a program can only advance to the next element in the sequence. This current element of the file is examined or changed by using the file's buffer variable. The buffer variable is denoted by writing an up-arrow (^) after the name of the file variable, e.g., INPUT^. TEXTIO.35 1 P-6000 - Text Input and Output Made Easier 27 May 86 Procedures and functions that process files: -------------------------------------------- Using the definition of files, the following table describes the basic procedures and functions which operate on files in Pascal. RESET(F) A procedure which sets the buffer variable F^ of the file F to its first element and prepares it for reading the file. RESET(INPUT) is automatically done before a Pascal program begins execution. REWRITE(F) A procedure which makes the file F empty and prepares it for writing. While a file is being written on, the buffer variable F^ is always at end-of-file. Before a Pascal program begins execution, REWRITE(OUTPUT) is auto- matically done. GET(F) A procedure which advances the buffer variable F^ to the next element of the file F. This is valid only for reading a file. PUT(F) A procedure which writes the value of the buffer variable F^ to the file F and then advances past that element to the new end-of-file. EOF(F) A boolean function which returns true if the buffer variable F^ is at the end-of-file. EOF is always true while writing a file, and EOF is true after resetting an empty file. The definition of textfiles: ---------------------------- Communication between a Pascal program and a human is almost always done through textfiles. Any file that you can read or type is a textfile because it is built up from elements which are separate characters. When you type a file of integer numbers, you are not creating a FILE OF INTEGER because the basic elements are not internal binary integers, but rather characters which are most likely one of these: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, +, -, and blank. A textfile is more than just a sequence of characters. A textfile is a sequence of lines, and each line is a sequence of characters. Following the last character of each line is a special marker that indicates the end of the line. We will use the abbreviation "eol" to mean "end-of-line". When the file is positioned at this marker, the buffer variable is set to a blank and the end-of-line condition is true. Suppose you want to write a program which reads integer numbers, performs some computations, and then writes the results. You could write a program which skips spaces by using the GET procedure, examines one by one the characters which represent the numbers by using the buffer variable, and converts these characters to internal- binary integers. After doing the computations, you could have your program convert the results to an equivalent character form, and write these characters one by one onto the output file by using the PUT procedure. It would be quite tedious if you had to do this in every program you wrote. Pascal provides procedures to do the conversion involved in reading and writing numbers. The READ and WRITE proce- dures use the buffer variable to do an automatic character-by-charac- TEXTIO.36 1 P-6000 - Text Input and Output Made Easier 27 May 86 ter translation between textfiles and internal binary numbers. Textfile procedures and functions: ---------------------------------- The following table describes the basic procedures and functions which operate on textfiles. READLN(F) A procedure which skips to the first character of the next line of the file F. WRITELN(F) A procedure which writes an end-of-line on the file F. EOLN(F) A boolean function which returns true if the buffer variable F^ is at an eol (end-of-line). It is natural to assume that an eol immediately follows the last printing character of every line. This is not necessarily the case. For example, a punch card has 80 columns of characters, whether they are punched or not. Some card readers trim trailing blanks, but depending on the card reader, the line may be trimmed to the last character, an even-character boundary, or perhaps a 10-character boundary. Our computer system has the convention that all lines should have an even number of characters, and, when necessary, it will add a blank to achieve this. The point is that you must write your programs so that they will handle any number of trailing blanks correctly. A textfile example: ------------------- Suppose we want to write a program which reads numbers from a file and prints the sum of the numbers on each line. We might type the following three lines as data on file INPUT. 5 7 23 19 144 87 12 14 1 1 2 3 5 8 We can represent this file as a sequence of characters using the symbol slash (/) to denote an eol and the vertical bar (|) to denote the eof. We will use periods (.) to show the character positions more clearly, and an up-arrow (^) to represent the current character of the file. After RESET(INPUT), the file looks like: 5 7 23 19 144 /87 12 14/1 1 2 3 5 8 /| ^...................................... If we did GET(INPUT) 10 times, the file would look like: 5 7 23 19 144 /87 12 14/1 1 2 3 5 8 /| ..........^............................ After four more GET(INPUT)s: 5 7 23 19 144 /87 12 14/1 1 2 3 5 8 /| ..............^........................ TEXTIO.37 1 P-6000 - Text Input and Output Made Easier 27 May 86 At this point, the current character of input would be a blank, and EOLN(INPUT) would be true. We would like to write the example program this way: PROGRAM SUMMER(INPUT,OUTPUT); VAR NUM,SUM : INTEGER; BEGIN (* SUMMER *) WHILE NOT EOF(INPUT) DO BEGIN SUM := 0; WHILE NOT EOLN(INPUT) DO BEGIN READ(NUM); WRITE(NUM); SUM := SUM + NUM END; WRITELN(' THE SUM IS ',SUM); READLN END END (* SUMMER *). Unfortunately, this program will not work. After reading one number, the file looks like: 5 7 23 19 144 /87 12 14/1 1 2 3 5 8 /| .^..................................... After reading all five numbers on the first line: 5 7 23 19 144 /87 12 14/1 1 2 3 5 8 /| .............^......................... Because the current character of the file is actually a blank, EOLN(INPUT) is not true! Our program will continue to read numbers until: 5 7 23 19 144 /87 12 14/1 1 2 3 5 8 /| .........................^............. At this point, our program will print its first sum, and start on the second one. After reading 6 more numbers: 5 7 23 19 144 /87 12 14/1 1 2 3 5 8 /| .....................................^. Now, since EOLN(INPUT) is still false, the program will attempt to read another number. Since there are no more numbers, the buffer variable will advance past the last character of the file, and EOF(INPUT) will become true: 5 7 23 19 144 /87 12 14/1 1 2 3 5 8 /| .......................................^ This is an error, and the program will fail. TEXTIO.38 1 P-6000 - Text Input and Output Made Easier 27 May 86 To read the file in the manner that we want to, we will use the routines in IOAIDS. EOLNS and EOFS are defined in the following way: FUNCTION EOLNS( VAR F : SEGTEXT ) : BOOLEAN; BEGIN WHILE (F^ = ' ') AND NOT EOLN(F) DO GET(F); EOLNS := EOLN(F) END; FUNCTION EOFS( VAR F : SEGTEXT ) : BOOLEAN; BEGIN WHILE (F^ = ' ') AND NOT EOF(F) DO GET(F); EOFS := EOF(F) END; Both functions skip blanks just as the READ procedure does, but in addition, they test for an end condition (EOLN and EOF). Now we rewrite the program. PROGRAM SUMMER(INPUT,OUTPUT); (*$I'IOAIDS' INPUT-OUTPUT AIDS. *) VAR NUM,SUM : INTEGER; BEGIN (* SUMMER *) WHILE NOT EOFS(INPUT) DO BEGIN SUM := 0; WHILE NOT EOLNS(INPUT) DO BEGIN READ(NUM); WRITE(NUM); SUM := SUM + NUM END; WRITELN(' THE SUM IS ',SUM); READLN END END (* SUMMER *). With this program, after reading the five numbers on the first line, the file again looks like: 5 7 23 19 144 /87 12 14/1 1 2 3 5 8 /| .............^......................... Now the program uses the EOLNS test. EOLNS skips blanks, and then tests for the eol: 5 7 23 19 144 /87 12 14/1 1 2 3 5 8 /| ..............^........................ EOLN(INPUT) is true, and so the program prints the sum. The processing of the next two lines and the eof proceeds similarly. TEXTIO.39 1 P-6000 - Interactive Input and Output Made Easier 27 May 86 Interactive Input and Output Made Easier ======================================== Before reading this chapter, you should read TEXTIO, because this chapter assumes you have some basic familiarity with the techniques and terms discussed there. This chapter explains how to synchronize input and output in an interactive program. Pascal-6000 has some special problems when it comes to interactive input and output, and this chapter first explains how to write a program which will work the way you want. For the more technically-minded and inquisitive reader, the second part of this chapter describes the problems in depth, and explains why and how the solutions work. How to write an interactive program ----------------------------------- Writing an interactive program in Pascal (under KRONOS and NOS) is actually quite simple. All that you need to do is follow the guidelines that are listed here. (Note: These same ideas apply under SCOPE and NOS/BE, but there are some differences such as having to explicitly write your own prompt characters.) 1. Type a slash after the word INPUT on your program heading: PROGRAM INTERACTIVE( INPUT/ , OUTPUT ); This indicates that INPUT is an interactive input file, and ensures that the program will execute the same way if it is run in batch mode. 2. Whenever you want your program to ask for input by writing a question mark (?) as a prompt for input, use the READLN procedure with no parameters. 3. Never pass a list of variables to the READLN procedure. For example, suppose you want to write a program which will repeatedly ask for a line of integer numbers and then will print the sum of those numbers. The program will stop when an empty line is entered. Write the program this way: PROGRAM SUMMER( INPUT/ , OUTPUT ); (*$I'IOAIDS' INPUT-OUTPUT AIDS. *) VAR NUM,SUM : INTEGER; BEGIN (* SUMMER *) WRITELN(' PLEASE ENTER A LINE OF INTEGER NUMBERS'); READLN; (* THIS TYPES A PROMPT FOR INPUT *) WHILE NOT EOLNS(INPUT) DO BEGIN (* CONTINUE UNTIL A BLANK LINE IS ENTERED *) SUM := 0; REPEAT READ(NUM); SUM := SUM + NUM UNTIL EOLNS(INPUT); WRITELN(' THE SUM IS ',SUM); WRITELN(' PLEASE ENTER A LINE OF INTEGER NUMBERS'); READLN (* RE-ISSUE THE QUESTION AND THE PROMPT *) END END (* SUMMER *). INTERIO.40 1 P-6000 - Interactive Input and Output Made Easier 27 May 86 Why interactive input is special -------------------------------- As explained in the chapter TEXTIO, before your program begins execution, the Pascal system performs a RESET(INPUT). According to the definition of RESET, this sets the buffer variable INPUT^ to the first character of the file INPUT, and prepares for reading. To set the buffer variable to the first character of INPUT, the Pascal system (under KRONOS and NOS) requests this character by printing a question mark as an input prompt. Thus the first input prompt is printed before your program can write its first question. For example, suppose you wrote a program to read a number and print its square root in the following way: PROGRAM ROOT( INPUT , OUTPUT ); VAR X : REAL; BEGIN (* THERE IS AN IMPLICIT RESET(INPUT) HERE *) WRITELN(' PLEASE ENTER A NUMBER'); READLN(X); WRITELN(' THE ROOT OF ', X, ' IS ', SQRT(X)) END. The execution of this program would produce the following result: ? 3.14159 PLEASE ENTER A NUMBER ? 2.7183 THE ROOT OF 3.1415900000000E+000 IS 1.7724531023415E+000 Now, using the notation described in the chapter TEXTIO, let's find out why the program acted so strangely. Before the Pascal system did the implicit RESET(INPUT), the input file was in a state best described by this picture: ^ The file is empty, but it is really not at eof because there really is no end to an interactive input file. This file is actually a manifestation of the person sitting at an interactive terminal, and a person can always type another line of input. When the RESET(INPUT) is performed, an input prompt is printed (under KRONOS and NOS), and you respond by typing 3.14159. Now the input file looks like this: 3.14159 / ^........ The program now writes "PLEASE ENTER A NUMBER", but it is already too late. Next, the program does a READLN(X). READLN(X) is actually equivalent to READ(X); READLN. First, X is read: 3.14159 / .......^. Next, the READLN (according to its definition) skips to the first character of the next line. Again, to find the next line of input, the Pascal system prints an input prompt (under KRONOS and NOS) and you respond with 2.7183: INTERIO.41 1 P-6000 - Interactive Input and Output Made Easier 27 May 86 3.14159 /2.7183/ .........^...... Your program now writes the square root of 3.14159, and quits without reading the 2.7183. Now, suppose you revise this program according to the guidelines given in the first part of this chapter: PROGRAM ROOT( INPUT/ , OUTPUT ); VAR X : REAL; BEGIN (* THERE IS AN IMPLICIT RESET(INPUT) HERE *) WRITELN(' PLEASE ENTER A NUMBER'); READLN; READ(X); WRITELN(' THE ROOT OF ', X, ' IS ', SQRT(X)) END. Executing this program produces the results you want: PLEASE ENTER A NUMBER ? 3.14159 THE ROOT OF 3.1415900000000E+000 IS 1.7724531023415E+000 First, you place a slash after the name INPUT on the program heading to inform the Pascal system that INPUT is to be treated as an interactive input file. This modifies the effect of RESET(INPUT) to set the buffer variable to an eol. If you wish, you may think of this eol as immediately preceding the first character of input. The state of the file at this point: / ^ Your program is now able to type "PLEASE ENTER A NUMBER" before the first input prompt is printed. Next, you place a READLN following the WRITELN, because this is where you want an input prompt to be printed. This READLN skips to the first character of the next line of input, and the Pascal system prints the prompt to request the next line. Now the file looks like this: /3.14159 / .^........ Your program is able to read this as the value of X: /3.14159 / ........^. Lastly, you change the READLN(X) to READ(X), because you do not want another input prompt to be printed after reading the value of X. INTERIO.42 1 P-6000 - Record Manager Interface under SCOPE 2 (7600s) 27 May 86 Record Manager Interface under SCOPE 2 ====================================== On 7600 machines running the SCOPE 2 operating system all input and output operations are done by Record Manager. Record Manager allows specification of different formats for files and tapes by means of the FILE control statement. Record Types ------------ One of the formats that can be specified is the Record Type (RT). The record is the basic unit of data transferred by Record Manager between the file and program. Pascal allows the use of W, Z, S, F, and U type records, but superimposes its own structure onto some of these. The record type is selected by the RT parameter on the FILE statement before the file is used for the first time. For example, FILE(FRED,RT=U) declares that file FRED is to be formatted by Record Manager to contain U type records. The five record types allowed are described below. (a) RT=W - Control Word Record This is the default type. Record Manager prefixes the data comprising the record by a control word which describes the record. The control word is not seen by the program -- Record Manager adds it on writing, and removes it on reading. (b) RT=Z - Zero Byte Terminator The end of the record is marked in the file by a word containing at least 12 zero bits (or two colons -- a zero byte) at the end of the word (1 word = 10 characters). This is the structure used for textfiles on non-7600s. (c) RT=F - Fixed Length Record Each record is the same length (FL characters) as specified on the FILE statement. No other information is added to the file. For example, FILE(FIXED,RT=F,FL=80) 80 characters or 8 words per record (d) RT=U - Undefined Record Manager makes no assumptions about the structure of the file, and reads and writes the file character for character. Any number of characters may be transferred by each input or output request, as specified by the program. The file is considered to be one long record. (e) RT=S - System Logical RM7600.43 1 P-6000 - Record Manager Interface under SCOPE 2 (7600s) 27 May 86 This is the 'segmented' version of RT=U, where each record corresponds to one segment. Use of the Different Record Types for Binary Files -------------------------------------------------- A binary file is a file declared either as binaryfile = FILE OF component type; or else as segbinfile = SEGMENTED binaryfile ; where component type is the type of the file component. For example, TYPE sixthings = RECORD i,j,k : INTEGER ; x,y,z : REAL ; END ; binfile = FILE OF sixthings ; Here the file component is a record of type sixthings. A segmented file can only be constructed with W, S, and Z type records. Pascal constructs binary files according to record type as follows. (a) RT=W The length of the record is determined by the length of the buffer created by Pascal. This is controlled by the B compiler option, but the compiler forces it to be an integer number of whole record components in length. Thus for binfile above, option B2 (default) specifies 256 words which is extended to 264 in order to contain 44 whole components. For each write, Pascal places the 'written' component into the buffer. When the buffer is full (after the 44th write for binfile), Pascal requests Record Manager to write the entire buffer as a single W type record. The reverse occurs on reading. In many cases, it is necessary for the record to correspond directly to a Pascal file component - for example, if the file is to be sorted by SORTMRG. There are two ways of achieving this: (i) Use (*$B0 *) immediately before the declaration of the file type. This specifies a zero length buffer for the file, which Pascal extends to contain one component. Thus on every write, the buffer becomes full and is written as a single record. If the B0 option is in force when a text file is declared, then the previous value of the B option is used. This is because if B0 were applied to a text file, RM7600.44 1 P-6000 - Record Manager Interface under SCOPE 2 (7600s) 27 May 86 then each line could only contain ten or less characters. Do not, therefore, select B0 twice in succession (for example, on the PASCAL statement and in the program) without an intermediate B=. It is good practice to use the B0 option only if necessary on a file since it is more efficient to write a few long records than many short ones. (ii) Calulate the number of words required to contain the file component and specify 10 times that number as the MRL parameter on the FILE statement. For example, FILE(BIN,MRL=60) Maximum Record Length = 60 characters This can be calculated from the compilation listing by noting the change in the location counter (left-hand column) caused by the declaration of one variable of the component type. For example, 00423 12 element : componenttype ; 00431 13 i, j, k : integer ; 00434 14 Here the location counter increased by 431-423 (octal) = 7. Thus the component requires 7 words = 70 characters. (b) RT=Z - not recommended for binary Each file component will be written followed by a word full of zeros. This format is unsuitable for non-character data because a value of zero in the twelve least significant bits of any word will be treated as an end-of-record mark. Thus, for example, if a component contains say (12, 18, 4096, 14.7,3.14,2.71828) then this is treated as two separate records on input, because 4096 = 10000 (octal) - the last 12 bits are zero. (c) RT=F and RT=U These are treated identically by Pascal. The length of the file component is used as the length of the record. A message is written to the dayfile reporting the value of FL used. If FL is specified on the FILE statement, then it is ignored. (d) RT=S This is the equivalent format to that produced on non-7600s. An S type end-of-record mark, which corresponds to an end-of- segment, is written to the file by RESET, PUTSEG, CLOSE, and at the end of the program. Use of the Different Record Types for Textfiles ----------------------------------------------- A textfile is one of type TEXT or SEGMENTED TEXT. A SEGMENTED TEXT file can only be constructed in W, S, or Z type records. Because Pascal-6000 was originally developed on a non-7600 machine, RM7600.45 1 P-6000 - Record Manager Interface under SCOPE 2 (7600s) 27 May 86 where all textfiles are composed of Z type records, textfiles of all allowed types are made to 'look like' Z type records to the Pascal run-time system. This has the unfortunate side effect that a legitimate 7600 line of text which contains two or more adjacent colons before the (n*10+1)th character position will have an end-of- line marker in place of these colons. Pascal constructs textfiles according to record type as follows. (a) RT=W This is the default record type. Each W type record corresponds to one single line of text terminated by a WRITELN. (b) RT=Z On output, each line is filled out with spaces to a multiple of 10 characters. The last two characters are then replaced by colons, and this forms the record. On input, the line is space filled up to FL characters. FL is either specified on the FILE statement, or defaults to the buffer size. Because the buffer is large (min b64 = 640 characters, default = 2560 characters), omitting the FL parameter from the FILE statement may cause the program to use an inordinate amount of time. (c) RT=F On output, each line is filled out with spaces to FL characters, and FL characters are written to the file. On input, FL characters are read and a Pascal end-of-line marker is appended. FL is as for RT=Z. (d) RT=S and RT=U On output, a space is added to a line containing an odd number of characters. Two spaces are added to a line containing an even number of characters if the last character was a colon. The line is then filled out to a multiple of 10 characters with colons to indicate the end of the line. On input, the trailing colons are removed, but all lines contain an even number of characters. It is not possible to write a segmented file with RT=U. One S type record is equivalent to one segment in a segmented file. An end-of-segment is written (to S type records) by RESET, PUTSEG, CLOSE, and at the end of the program. RM7600.46 1 P-6000 - Case-Statement and Variant-Record Extensions 27 May 86 Case-Statement and Variant-Record Extensions | ============================================ | Two nonstandard extensions to the CASE-statement notation have been | added to Pascal-6000. One allows the use of an OTHERWISE clause in | both case statements and variant record definitions, and the other | allows subrange notation in case constant lists. The OTHERWISE clause | allows the capturing of all cases which are not explicitly covered by | case constant lists. OTHERWISE is a reserved word. Allowing subrange | notation in case constant lists makes it convenient to enter a range | of constants which would otherwise have to be individually entered. | | For example: | | TYPE | VARIANTREC = | RECORD | CASE CH : CHAR OF | 'A'..'Z' : (VOWEL : BOOLEAN); | '0'..'9' : (DIGIT : INTEGER); | OTHERWISE () | END; | | and: | | CASE CH OF | 'A'..'Z' : | BEGIN LETTERS := LETTERS + 1; | WRITELN(' A LETTER.') | END; | '0'..'9' : | BEGIN DIGITS := DIGITS + 1; | WRITELN(' A DIGIT.') | END; | ' ' : | BEGIN BLANKS := BLANKS + 1; | WRITELN(' A BLANK.') | END; | OTHERWISE OTHERS := OTHERS + 1; | WRITELN(' NOT A LETTER, DIGIT, OR BLANK.') | END; | Syntax Changes -------------- The syntax for case-constant is modified to allow subranges in both | case statements and variant records: | | case-constant = constant | constant ".." constant . | The syntax of the case statement has been revised in the following way: case-statement = "case" expression "of" case-list-element { ";" case-list-element } [ [ ";" ] "otherwise" statement-sequence ] | [ ";" ] "end" . | CASE.47 1 P-6000 - Case-Statement and Variant-Record Extensions 27 May 86 The syntax of variant-part is changed to: | | variant-part = "case" variant-selector "of" | variant { ";" variant } [ ";" ] | [ "otherwise" "(" field-list ")" [ ";" ] ] . | Warning ------- The OTHERWISE clause is designed to capture all cases which are not specifically in the list of case labels. It is important to realize, however, that there are two kinds of cases that will be captured by this clause. There are the default cases that you want your program to process, but you do not wish to type them all explicitly. However, there are also the cases which represent errors in your program or in the input to your program. You would probably prefer that these cases produce a run-time error such as "case expression out of range". By using the OTHERWISE clause, however, you have lost the ability to have the compiler check for these erroneous cases. The OTHERWISE clause groups the defaults and the errors together, and you, as a programmer, must be aware of this. In standard Pascal the capabilities of OTHERWISE are usually achieved by IF expression IN [ set of case labels ] THEN CASE expression OF . . . END (*CASE*) ELSE ... CASE.48 1 P-6000 - Conformant Array Parameters 27 May 86 Conformant Array Parameters =========================== Conformant array parameters are implemented in Pascal-6000 according to the ISO standard with two exceptions. | 1. Formal conformant-array parameters can be passed as actual conform- ant-array value parameters. This is an extension. Example: PROCEDURE OUTER( A: ARRAY [LO1..HI1: INTEGER; LO2..HI2: INTEGER] OF REAL); PROCEDURE INNER(X: ARRAY [LO .. HI: INTEGER] OF REAL); BEGIN END (* INNER *); BEGIN (* OUTER *) INNER(A[LO1]) END (* OUTER *); 2. Packed conformant-arrays of char with integer-compatible index types are treated as strings in that they may be passed to the | standard predeclared procedure WRITE and the nonstandard procedures | HALT and MESSAGE. This is an extension. | * CONFORM.49 1 P-6000 - Including External Text 27 May 86 Including External Text ======================= Source library versus binary library ------------------------------------ The Pascal-6000 library, PASCLIB, contains many packages of procedures and functions. We expect that the library will continue to grow as more routines are written. Two major approaches are used in constructing such a library. 1. A source library contains the Pascal source text of the library routines and their associated declarations. An editing program, or the compiler itself, combines the text of the library routines with your program, and the result is compiled as a whole. 2. A binary library contains the pre-compiled binaries of the library routines. Once your program has been compiled, the operating system loader completes your program by adding binaries from the library. Unless the routines are prede- fined in the Pascal-6000 compiler (like READ and WRITE), you must declare them to be external to your program. Both methods have their advantages and disadvantages. The source library approach allows better type checking, and it ensures compati- bility between your program and the library routines. Because your program source is increased by the sources of the library routines, the compile time may also be increased substantially. The binary library method does not require every user to re-compile the routines, and it allows the inclusion of assembly language routines. You must, however, declare each routine as external to your program, and for a large package, there may be several pages of declarations. The Pascal-6000 approach ------------------------ The approach taken in Pascal-6000 is a hybrid of the two. Pascal's library consists of the binaries of the library routines and the sources of the external declarations. Thus to use a certain package, you direct the compiler to include the declarations for that package. For example, if you wanted to use the printer-plotting package PRNTPLT, you would add the following compiler directive to your program. (*$I'PRNTPLT'/'PASCLIB' *) [for KRONOS or NOS] -or- (*$I'PRNTPLT'/'PSRCLIB' *) [for SCOPE or NOS/BE] This asks the compiler to include the source library entry PRNTPLT from PASCLIB or PSRCLIB. This entry has all the declarations which are necessary for using PRNTPLT. Since PRNTPLT defines both types and procedures, you should place this compiler directive immediately following the program heading. INCLUDE.50 1 P-6000 - Including External Text 27 May 86 The I compiler option --------------------- The I compiler option is used to Include source from an external file. This directive has two forms: (*$I'package'/'file' *) (*$I'package' *) The first form attempts to find an entry named "package" on the file named "file", and the second form attempts to find the entry named "package" on the default file which is PASCLIB for KRONOS or NOS and PSRCLIB for SCOPE or NOS/BE. The included text is not restricted to declarations - it may also contain full procedures and functions. Since the text entry is simply inserted into the text of your program, this Include facility may be used to create full source libraries. In PASCLIB/PSRCLIB, however, we have tried to take advantage of the best features of both source and binary approaches, and so most entries in PASCLIB/PSRCLIB consist solely of declarations. The included text is written on the program listing (if L+) so that there is an accurate record of exactly what was compiled. To list included text explicitly is also in the interests of portability when the listing is used later to aid transporting the program to another implementation of Pascal. Compiler options embedded within included text will change previous option settings unless they are explicitly restored with an "=" value in the text itself. Syntactic changes ----------------- Since the different packages in PASCLIB/PSRCLIB may consist of CONST, TYPE, PROCEDURE, and FUNCTION definitions, the strict ordering of declarations (LABEL, CONST, TYPE, VAR, PROCEDURE/FUNCTION) has been relaxed. The syntax of a block has been revised to allow repetition of the declaration sections in any order: block = { label-declaration-part constant-definition-part type-definition-part variable-declaration-part value-initialization-part procedure-and-function-declaration-part } statement-part . The I compiler option can actually appear anywhere in a Pascal program, but in practice there are places which are more appropriate than others. Most packages in PASCLIB/PSRCLIB consist of CONST, TYPE, PROCEDURE and FUNCTION definitions, and contain those reserved words to mark the beginning of the sections. For this reason, you should include the package in your program just after or just before one of the declaration sections. If, for instance, the package contains type definitions that you want to use, you should probably include it before the type definitions in your program. In most instances, the best place is just after the program heading. The packages may be made local to a procedure or function, in which case the best place is INCLUDE.51 1 P-6000 - Including External Text 27 May 86 just after the procedure or function heading. Structure of a source library ----------------------------- Each text entry in a source library is a single logical record. The name of the entry must be one to seven alphanumeric characters, and must be by itself on the first line of the record. The remainder of the record is the text of the entry itself. Many entries may be together in a single file in any order. The entries may be part of a user library (created under KRONOS or NOS using the LIBGEN control statement). In this case the compiler will use the user-library index to search for the desired text entry. Under SCOPE and NOS/BE, however, text records must be on a separate file. Restrictions ------------ Only one included text may be active at a time. Thus an included text cannot include another. The changeover between your program and the included text is made at the end of the line containing the I compiler option, and so only one I option may appear on a single line. INCLUDE.52 1 P-6000 - The Initial-Value Declaration 27 May 86 The Initial-Value Declaration ============================= Note: The initial value declaration is nonstandard. Use of this feature in a program makes the program less portable. In Pascal-6000, initializing variables with assignment statements requires extra storage for the constants to which variables are initialized, and execution time and code space to move the values of the constants into the variables. Several programming languages have an alternate facility which allows variables to be initialized at compile time. The advantages are that the executable part of the program is shorter, fewer constants are needed in the program, and the compiled program does not have to spend time initializing variables when execution begins. In Pascal-6000, it is advantageous to provide such an ability to initialize main program variables (global variables) because they exist in a static environment throughout the execution of a program. This is not advantageous for procedures and functions because their data areas are allocated dynamically and do not exist until they are called. An extension to Pascal-6000 provides an initial-value declaration facility for global variables. This extension allows the initializa- tion of simple and structured variables of all types except files. Initializing packed variables is identical to initializing unpacked variables, and type checking is applied to the values being assigned. Variables which are integers, reals, characters, enumerated scalars, or subranges may be initialized with constants expressed either as literals or as constant identifiers of the correct type. For pointers, the only possible value is NIL. Structured variables (arrays, records, and sets) must be initialized with structured constants. Two kinds of structured constants exist in standard Pascal. These are character strings enclosed by quotation marks, and set constants enclosed by square brackets. Thus, character strings (packed character arrays) and sets are initialized with these structured constants. New kinds of structured constants have been introduced for arrays in general and for records. These are called array constructors and record constructors, and are based on the article "Notes on Data Structuring", by C. A. R. Hoare and the book "Algorithms + Data Structures = Programs" by Niklaus Wirth. A constructor consists of all the component values of a structure in order within parentheses. Ordinarily a type name precedes the left parenthesis. Array and record structures may, however, be declared without being assigned an explicit type name. In order to allow initializing such anonymously-typed arrays and records, the type name preceding the left parenthesis is not required. If a type name is given, it must match the type of the variable (or component) being initialized. A constructor specifies the values of all the components of an array or record. This provides a certain amount of security, because partial initialization is not allowed. To aid in initializing many VALUE.53 1 P-6000 - The Initial-Value Declaration 27 May 86 array elements to the same value, repetition factors are allowed within array constructors. A repetition factor consists of an integer constant followed by the word "of", preceding the constant value to be repeated. Records or arrays with components that are also records or arrays are initialized by nesting constructors within constructors. In Pascal, multidimensional arrays are considered to be arrays of arrays, and so they are initialized by constructors of constructors. Variant records may be initialized, and the tagfield value determines which variant is followed. Only the fields in that variant may be initialized. If the record is a non-discriminated variant record (i.e. one in which the tagfield type was declared without a tagfield name) the tagfield value is still specified to select a variant. An Example ---------- CONST N = 10; ROWS = 6; TYPE SEX = (MALE, FEMALE); PERSON = RECORD AGE : 0..100; CASE SEX OF MALE : (BEARD : (NONE, SHAGGY, TRIMMED)); FEMALE : (PREGNANT : BOOLEAN); END; VECTOR = ARRAY[1..N] OF INTEGER; LETTERS = SET OF 'A'..'Z'; NAME = PACKED ARRAY[1..20] OF CHAR; DATE = PACKED RECORD YEAR : 0..4000; MONTH : 1..12; | DAY : 1..31 | END; NODE = RECORD IDENT: PACKED ARRAY[1..8] OF CHAR; NEXT: ^NODE END; DAYSOFWEEK = (SUN,MON,TUE,WED,THU,FRI,SAT); MONTHSOFYEAR = (JAN,FEB,MAR,APR,MAY,JUN, JUL,AUG,SEP,OCT,NOV,DEC); WEEK = ARRAY[DAYSOFWEEK] OF 0..31; MONTH = ARRAY[1..ROWS] OF WEEK; YEAR = ARRAY[MONTHSOFYEAR] OF MONTH; LIMITS = ARRAY[MONTHSOFYEAR] OF 28..31; VAR X,Y,Z : VECTOR; STRING1, STRING2: PACKED ARRAY[1..8] OF CHAR; CONSONANT: LETTERS; TODAY: DATE; NEXTCH: CHAR; TEAMNAME: NAME; ELEMENT: NODE; FIRSTDAYOFYEAR: DAYSOFWEEK; VALUE.54 1 P-6000 - The Initial-Value Declaration 27 May 86 CALENDAR: YEAR; DAYSPERMONTH: LIMITS; CITIZEN : PERSON; VALUE X = VECTOR(1, 1, 2, 3, 5, 8, 13, 21, 34, 55); Y = (N OF 0); Z = VECTOR(N OF 1); CITIZEN = (25, MALE, NONE); STRING1 = 'HI THERE'; STRING2 = ('P','A','S','C','A','L',2 OF ' '); TODAY = DATE(1978, 6, 27); NEXTCH = ' '; TEAMNAME = 'U.C.C. PUNCH '; ELEMENT = NODE('DUMMY ',NIL); FIRSTDAYOFYEAR = THU; CALENDAR = YEAR(12 OF MONTH(ROWS OF WEEK(7 OF 0))); DAYSPERMONTH = (31,28,31,30,31,30,2 OF 31,30,31,30,31); CONSONANT = ['B'..'D', 'F'..'H', 'J'..'N', 'P'..'T', 'V'..'Z']; Syntax Changes -------------- This initial-value declaration part may be included only in the main program, and so the syntax of Pascal is affected in the following way: program-block = { label-declaration part constant-definition-part type-definition-part variable-declaration-part initial-value-declaration-part procedure-and-function-declaration-part } statement-part . initial-value-declaration-part = [ "value" initial-value-declaration { ";" initial-value-declaration } ";" ] . initial-value-declaration = variable-identifier "=" value-specification . value-specification = basic-value | multiple-value . basic-value = constant | "nil" | "[" set-value-element-list "]" . set-value-element-list = [ set-value-elements { "," set-value-elements } ] . set-value-elements = constant [ ".." constant ] . multiple-value = [ type-identifier ] "(" value-list ")" . value-list = [ repetition value-specification { "," repetition value-specification } ] . repetition = [ constant "of" ] . VALUE.55 1 P-6000 - Alternative Heap Management Extensions 27 May 86 Alternative Heap Management Extensions ====================================== Standard Pascal provides for the creation and destruction of "dynamic" or "heap" variables using the predeclared procedures NEW and DISPOSE. DISPOSE is the only way that a variable created by NEW can be destroyed (other than the program terminating). Pascal-6000 Release 4 introduces a new extension to allow heap management. The function of the standard procedures NEW and DISPOSE is totally unaffected by this extension. The extension is supported by three predeclared procedures (MARK, MNEW, and RELEASE) and one predefined type (MARKER) having the form: TYPE MARKER = RECORD END; PROCEDURE MNEW( ... same as NEW ... ); PROCEDURE MARK(VAR M: MARKER); PROCEDURE RELEASE(M: MARKER); Conceptually there is a stack of heaps that initially contains one empty heap; each time MARK is called, a new (empty) heap is pushed onto the stack and a MARKER value that identifies that heap is returned in the single variable parameter of type MARKER. The procedure MNEW is called just like the standard procedure NEW; the parameter list syntax and semantics is the same for both. MNEW creates a new variable in the heap that is at the top of the heap stack. That variable works just like any other heap variable, except that it and all other variables in that heap are subject to destruction by procedure RELEASE. In particular, RELEASE is called with a value of type MARKER, and has the effect of destroying all heaps on the heap stack that were created since that MARKER value was returned by MARK. When a heap is destroyed, every variable in that heap is destroyed and the heap is removed from the stack. The depth of the stack of heaps is limited to 32. The type MARKER is actually a record type that has no field names. Values of type MARKER can be assigned to MARKER variables, and they can be passed as parameters. However, MARK is the only way in which MARKER values can legitimately be created. The first parameter of MNEW must be a pointer-variable, and the domain-type of the pointer type must neither be nor contain a file type. Warnings -------- This extension is highly nonstandard. It is unlikely to be available on any other implementation of Pascal, and is also unlikely to be standardized in the future. Future versions of Pascal-6000 may not support this extension. Its use is not recommended. HEAP.56 1 P-6000 - Alternative Heap Management Extensions 27 May 86 Error Messages -------------- Exceeding the limit on the depth of the stack of heaps results in program termination with the message MAXIMUM MARK LEVEL EXCEEDED. If the marker value passed to RELEASE is invalid (undefined or already released), the program is terminated with the message INCORRECT VALUE PASSED TO RELEASE. History ------- Releases 1, 2, and 3 of Pascal-6000 provided a variation on NEW and DISPOSE for manipulating collections of heap variables: the entire heap was structured as a stack, and a nonstandard predeclared procedure, RELEASE, would cause all heap variables created since a certain point to be destroyed. This facility was provided originally because DISPOSE was not implemented; its use in the Pascal compiler helped it to survive the implementation of DISPOSE. This scheme was adopted in Release 4 so that library packages could safely use NEW and DISPOSE even when the program uses RELEASE. The name MNEW was chosen because of its similarity to NEW and in honor of the Greek goddess of memory, Mnemosyne (pronounced knee-MOSS-y-knee). HEAP.57 1 P-6000 - Hints for Machine-Dependent Programming 27 May 86 Hints for Machine-Dependent Programming ======================================= This chapter briefly explains some of the information needed to do machine-dependent programming in Pascal. The Pascal compiler is one example, because it is written as an 10,000-line Pascal program. To be able to exist within the computer system (particularly the operating system), the Pascal compiler uses a number of interface routines which are called the "run-time system" and are written in assembly language (COMPASS). Most of the information necessary to write machine-dependent programs involves the representation of data in storage, and the ability to communicate with the operating system (make system requests). The storage requirements of data types are: INTEGER 60 bits BOOLEAN 1 bit CHAR 6 bits POINTER 36 bits (tests on) REAL 60 bits POINTER 17 bits (tests off) User-defined scalar types take as many bits as necessary to represent the total number of elements. Subrange types of integers and user-defined scalar types take as many bits necessary to represent the largest element as well as the range. For example 1..100 requires 7 bits, while -31..31 requires 6 bits. The use of subranges is good not only to economize on storage, but also to enable the compiler to generate code to do bounds checking. Sets require n+1 bits where n is the ordinal of the maximum element. For example, SET OF 10..20 uses 21 bits. The use of PACKED records, arrays, and files, reduces storage requirements. For example: VAR ITEM : RECORD COUNT: 0 .. 9999; COLOR: (RED, YELLOW, BLUE, GREEN); LINK : ^ ITEM END; would take three 60-bit words whereas a PACKED RECORD would take only one 60-bit word. The control statement is scanned for file names only up to a slash, period or right parenthesis. Thus user-defined parameters may follow a slash: LGO(files/userparams) The compiler uses this feature to allow compiler options on the control statement call. The control statement is not scanned at all, however, if the program heading has no parameters. In this case the entire control-statement can be used for special parameters. The control-statement image may be obtained by using the library procedure CSIMAGE. User-defined parameters may also be accessed by using the library function OPTION. See the chapters CSIMAGE and OPTION in the PASCLIB writeup for details. HINTS.58 1 P-6000 - External Procedures and Functions 27 May 86 External Procedures and Functions ================================= In Pascal it is possible to call external, separately-compiled procedures and functions. A group of such routines could be in the form of a library created with the LIBGEN or EDITLIB control statements. While this can be extremely useful, caution is necessary since the compiler no longer has the opportunity to check the correspondence between actual and formal parameters. An external procedure or function is declared as any other local routine, the only difference being that its block (refer to SYNTAX) has to be replaced by the word "EXTERN". For example PROCEDURE P(I: INTEGER; VAR R: REAL); EXTERN; Such a declaration implies the generation of the Pascal calling sequence for each use of P. Since this calling sequence depends on the X option (see OPTIONS), it is absolutely necessary that the external routine is both compiled and used with the same value for the X option. When compiling a procedure or function which will be used later as an EXTERN, it is absolutely essential to use the E+ compiler option. Another use for EXTERNs is to access a routine written in assembly language (COMPASS) for the purpose of achieving faster code, or for doing things that cannot be done in Pascal, such as using Extended Core Storage (ECS). The rest of this section provides a minimal description of the Pascal calling sequence which is oriented toward writing such a COMPASS external procedure or function. Pascal routines are called with the COMPASS return jump instruction. This is a change from Pascal-6000 Release 2 which passed the return address in X7. The major change you must make to a COMPASS routine which was written for Pascal-6000 Release 2 is to place an entry/exit word at the entry point and return by jumping to that word. Up to 5 parameters may be passed in X registers. This is based on the value of the X compiler option setting at the time of the EXTERN declaration. If the X option was set to N, the first N parameters are passed in registers X0 to X(N-1). If there are more than N parameters, the rest are passed through memory starting at the location with address (B6)+N+2. This is a change from Release 2 which used (B6)+N+3. Thus if the compiler option setting X0 is used, all parameters are passed through memory starting at (B6)+2. The parame- ters are always one word and may be a value or an address. The following list describes the various kinds of parameters. a) For a VAR parameter, the address is always passed. b) For a value parameter which is less than or equal to one word in size, the value itself is passed. c) For a value parameter which is larger than one word, the address of the actual parameter is passed and it is your responsibility to either copy the value or be sure not to change it. d) For a procedure or function parameter (see FORMAL), the entry- point address and static link are passed as EXTERN.59 1 P-6000 - External Procedures and Functions 27 May 86 VFD 24/0,18/SL,18/EP The static link is a pointer to the variables for the procedure which immediately surrounds the actual procedure or function parameter. To call this procedure, you should load the descrip- tor into X5 and return jump to the external symbol 'P.VPE' which is in the Pascal library PASCLIB. e) For a conformant array parameter, if it is the first in a parameter group, the address of the array and the address of a descriptor are passed as VFD 24/0, 18/DESCRIPTOR, 18/ARRAY If the parameter is not the first, then the address of the array is passed. The descriptor contains a three-word block for each dynamic subscript which has the form DATA SIZE DATA HIGH SUBSCRIPT DATA LOW SUBSCRIPT For the first subscript, SIZE is the size of the whole array. For the rest of the subscripts, SIZE is the size of the sub-arrays. On entry to the external COMPASS routine, several registers have values which should be saved and restored or not changed at all. A0 contains the line number of the call, providing the P+ option was used. If your COMPASS routine does not change A0, it will have no effect on any post-mortem dump which may be printed. If an error such as an arithmetic mode error occurs in the COMPASS routine, the PMD will list the line with the call to the procedure as the location of the error. You may change the value of A0 without restoring it, but the PMD will list the value of A0 as if it were the line number of any error that occurs in your routine. B1 = 1 and must be restored if it is changed. B4 contains the last word address plus one (LWA+1) of the current stack chunk. B4 may be used providing it is saved and restored. B5 points to the stack segment of the procedure or function that called your COMPASS routine. B5 must not be changed. B6 points to the top of the caller's parameter stack stack and must not be changed. If your COMPASS routine is a function, you should place the function result in X6 before returning. EXTERN.60 1 P-6000 - Fortran Subroutines and Functions 27 May 86 Fortran Subroutines and Functions ================================= Just as some routines can be declared to be EXTERN, other routines can be declared as FORTRAN, causing the generation of an FTN (CDC FORTRAN Extended compiler) calling sequence, for example FUNCTION F(I : INTEGER; VAR R : REAL) : REAL; FORTRAN; Routines written in COMPASS may be declared as either EXTERN or FORTRAN. Those declared as FORTRAN are written just as you would write an external routine for a FORTRAN program. FORTRAN routines are called with the return jump instruction, and the parameters are passed in the following manner. For every call to a FORTRAN procedure, a table containing the addresses of the parameters is created. The address of this table is passed in register A1, and so the address of the first parameter is passed in X1. The last address in the parameter table is followed by a zero word. The necessary saving and reloading of the relevant B-registers is done by the compiled code. Value parameters to FORTRAN procedures (those parameters which are not preceded by "VAR" in the FORTRAN procedure declaration) are allowed, and they are copied (to effect pass by value) prior to calling the FORTRAN procedure. If a normal FORTRAN calling sequence is desired, however, all parameters should be declared as VAR. WARNING--- There are several problems which may arise if the routine which is declared as FORTRAN is actually written in FORTRAN. For this reason, we do not guarantee that the FORTRAN interface will work well all the time, and we do not recommend its use. You should carefully consider the following incompatibilities between Pascal and FORTRAN before using this interface. a) FORTRAN input-output routines are not compatible with the Pascal ones, and so if the FORTRAN routine attempts to read or write a file, the results are unpredictable. b) Arrays are stored in column-major form in FORTRAN and in row-major form in Pascal. Further, the low subscript of a FORTRAN array must always be 1. Thus passing multi-dimensional arrays or arrays with a low subscript not equal to 1 will lead to confusion. For example, an array which was declared as VAR A : ARRAY[ 0..10 , 1..20 ] OF INTEGER; will be interpereted by the FORTRAN routine as INTEGER A( 20 , 11 ) Pascal-style conformant-array parameters do not exist in FORTRAN, and so you should not attempt to pass one to a FORTRAN routine. c) Integer expressions in Pascal will never yield the value negative zero (-0). In fact, such a value will cause certain operations to fail. FORTRAN routines, however, generate negative zero values under some circumstances. Negative zeroes can be elimi- FORTRAN.61 1 P-6000 - Fortran Subroutines and Functions 27 May 86 nated by adding zero to all values returned by a FORTRAN routine. d) The representation of LOGICAL values in FORTRAN differs from that of BOOLEAN values in Pascal. In Pascal, the internal representa- tion of FALSE is zero and TRUE is one. In FORTRAN, one is used for FALSE and minus one for TRUE. Thus a LOGICAL parameter to a FORTRAN procedure should be declared as INTEGER. e) The FORTRAN types DOUBLE and COMPLEX can be declared as records with two REAL fields. The result of a FORTRAN function cannot be DOUBLE or COMPLEX since RECORD-valued functions are not allowed in Pascal. f) EXTERNAL SUBROUTINE and FUNCTION parameters to FORTRAN routines may be declared as PROCEDURE and FUNCTION parameters in the procedure or function declaration. However, it is only possible to pass a FORTRAN procedure or function as the parameter. g) CHARACTER variables in FORTRAN 77 are represented differently | than strings in Pascal-6000. Do not attempt to use FORTRAN | CHARACTER variables. | Integer, real, complex, double, array, procedure, and function are the only parameter types which make sense if the routine is really written in FORTRAN; the compiler does not test for inappropriate parameter types. As in FORTRAN, trailing parameters may be omitted. The multiple, alternate returns of the FTN compiler should not be used. FORTRAN.62 1 P-6000 - Creating User Libraries 27 May 86 Creating User Libraries ======================= Note: This chapter describes user libraries as they are implemented under NOS. Users of other systems can adapt the information given here to their own use. This chapter describes methods and restrictions for creating, using, and updating user libraries containing precompiled Pascal routines for Pascal-6000. A user library satisfies the need to maintain frequently executed routines in a form that is efficient and easy to use. User libraries normally contain compiled relocatable binary routines, which can be declared as EXTERNs from a Pascal program. Normally, EXTERN routines are assumed to be on PASCLIB (the Pascal system library). You can alter this assumption by using loader directives to specify other files that contain routines that do not reside on PASCLIB. Under the KRONOS, NOS, and SCOPE 2 operating systems, a Pascal user library can contain both source texts (INCLUDE packages) and binary texts (compiled, relocatable procedures and functions). A user library is created by combining INCLUDE texts and compiled routines onto a file, and then using LIBGEN to generate the library file. Once a library has been generated, the user can access these external routines from a Pascal program by specifying the user library in loader directives (using the LIBRARY or LDSET control statements). The user must also declare (explicitly or by means of an INCLUDE package) the necessary procedures and functions in the calling program. This writeup has several examples of control statements used in the NOS operating system. The names used for files in the examples designate the contents or purposes of the files. In creating your own user libraries, you should choose different file names that describe your own applications. Creating New Libraries ---------------------- To create a new library of Pascal procedures you must first compile the procedures as part of a Pascal program. The program must contain: 1. A PROGRAM heading. 2. Type declarations, if your procedures will be using variables that are not pre-defined Pascal types. 3. The text of the routines that will be part of the user library. 4. The main program itself, which should consist of only BEGIN END. Compiling procedures for a library requires the use of either the E+ option (so that the system will use the first seven characters of the procedure name to identify it), or the version of the E option that allows you to assign another name to the procedure entry-point. All procedures in the library that will be called from a Pascal program (by declaring them as EXTERNs) should use the E+ option. Any USERLIB.63 1 P-6000 - Creating User Libraries 27 May 86 other procedures in the library should use the alternate entry-point form of the E option (see function INRANGE below). These other procedures are any routines which are not called directly by the user program (you don't declare them as EXTERNs). Refer to the OPTIONS chapter for further explanation of the E compiler option. Example of library source program (on file LIBPROG): (*$E+ USE ACTUAL ROUTINE NAMES AS ENTRY POINTS *) PROGRAM DUMMY; TYPE TABLE = ARRAY [1 .. 100] OF INTEGER; FUNCTION (*$E'IN.RNGE'*) INRANGE(SIZE : INTEGER) : BOOLEAN; BEGIN (* INRANGE *) INRANGE := (SIZE <= 100) AND (SIZE > 0) END (* INRANGE *); PROCEDURE ADD(A, B : TABLE; VAR C : TABLE; N : INTEGER); VAR I : INTEGER; BEGIN (* ADD *) IF INRANGE(N) THEN FOR I := 1 TO N DO C[I] := A[I] + B[I] END (* ADD *); PROCEDURE SUB(A, B : TABLE; VAR C : TABLE; N : INTEGER); VAR I : INTEGER; BEGIN (* SUB *) IF INRANGE(N) THEN FOR I := 1 TO N DO C[I] := A[I] - B[I] END (* SUB *); BEGIN (* DUMMY *) END. In the example above, the E+ option is in effect for all procedures. The compiled procedures will have entry-points of ADD and SUB. The INRANGE function will have an entry-point of IN.RNGE. The user would declare only ADD and SUB as EXTERNs in the calling program. The program containing the library routines above (on file LIBPROG) can be compiled with the command: PASCAL,I=LIBPROG,L=LISTING,B=BINARY. The program source is on LIBPROG, the compiler listing is written onto LISTING, and the compiled routines are written to BINARY. At this point, each procedure will be a separate logical record on file BINARY. Additionally, there will be a record containing the compiled main program, and a record containing main program variables. In our example, the main program (which does nothing) is called DUMMY, and the main program variables section (which is empty) is called DUMMY;. USERLIB.64 1 P-6000 - Creating User Libraries 27 May 86 If we want to know what procedures are on BINARY, we can enter the command: CATALOG,BINARY,R. For our example program, we would get the following output: CATALOG OF BINARY FILE 1 REC NAME TYPE LENGTH CKSUM DATE 1 IN.RNGE REL 46 7323 84/03/09. IN.RNGE 2 ADD REL 110 4743 84/03/09. ADD 3 SUB REL 110 5231 84/03/09. SUB 4 DUMMY REL 47 3540 84/03/09. DUMMY P.PIT 5 DUMMY; REL 17 5413 84/03/09. DUMMY; * EOI * SUM = 354 The above output is a typical example of CATALOG. Each record on the file is numbered, and has the record name and type following it. The record types you might encounter are: REL Compiled relocatable binary ABS Compiled absolute binary TEXT Character data record ULIB user library program OPLD old program library directory An OPLD type record contains a table used to find other records quickly on the file (see the CATALOG example below). REL type records have entry-point definitions listed after the record name. In the example above, the entry-points are the same as the record names. For more information on record types and CATALOG, see the NOS 1 Reference Manual, Volume 1 (or NOS 2, Volumes 2 and 3). Before we can generate a user library, we must remove the record containing the main program. If there are global variables declared in the library source program that are to be maintained during the execution of the user program, we must use the E option to change the entry-point of the main program variables section of our library source program. In the example above, the E+ option was used to change the entry-point of the main program variables section to DUMMY;. If there are no global variables declared, we can remove the two records containing the main program and main program variables. You normally will not need to declare global variables in the user library source. Any data that the user is to provide will be passed by parameter. You only need global variables in the user library if USERLIB.65 1 P-6000 - Creating User Libraries 27 May 86 you want to store data which should only be accessed by the procedures in the user library. WARNING: Do not declare files as global variables in a user library source program. Global file variables are initialized by the main program, and in a user library the main program is never executed. If our example program contained global variables, the following sequence of commands would be necessary to remove the main program and keep the main program variables section: SKIPEI,BINARY. BKSP,BINARY,1. REWIND,TEMP. COPYBR,BINARY,TEMP. BKSP,BINARY,2. REWIND,TEMP. COPYBR,TEMP,BINARY. In our example, since there are no global variables declared, we remove the records containing the main program and global variables by using these commands: SKIPEI,BINARY. BKSP,BINARY,2. WRITEF,BINARY. These commands delete the last two logical records on the file BINARY. Using the previous CATALOG command, we get an updated listing of the contents of BINARY: CATALOG OF BINARY FILE 1 REC NAME TYPE LENGTH CKSUM DATE 1 IN.RNGE REL 46 7323 84/03/09. IN.RNGE 2 ADD REL 110 4743 84/03/09. ADD 3 SUB REL 110 5231 84/03/09. SUB 4 * EOF * SUM = 266 Now, to create the user library from the compiled file, we use the LIBGEN statement: LIBGEN,F=BINARY,P=USERLIB. The file USERLIB is a user library containing our compiled procedures. To list the contents of a user library, we must add an additional parameter to the CATALOG command: CATALOG,USERLIB,R,U. Using this command with our example, we get the following list: USERLIB.66 1 P-6000 - Creating User Libraries 27 May 86 CATALOG OF USERLIB FILE 1 REC NAME TYPE LENGTH CKSUM DATE 1 USERLIB ULIB 11 2472 84/03/09. 2 IN.RNGE REL 46 7323 84/03/09. IN.RNGE 3 ADD REL 110 4743 84/03/09. ADD 4 SUB REL 110 5231 84/03/09. SUB 5 USERLIB OPLD 11 4757 84/03/09. 6 * EOF * SUM = 310 Having created our user library, we now wish to use the procedures in a Pascal program. For this purpose, we may use an example program which calls our procedures as EXTERN routines. Example of calling program (on file PROG): PROGRAM COMPUTE(INPUT, OUTPUT); TYPE TABLE = ARRAY [1 .. 100] OF INTEGER; VAR A, B, SUM, DIF : TABLE; NUM, I : INTEGER; PROCEDURE ADD(A, B : TABLE; VAR C : TABLE; N : INTEGER); EXTERN; PROCEDURE SUB(A, B : TABLE; VAR C : TABLE; N : INTEGER); EXTERN; BEGIN (* COMPUTE *) READLN(INPUT, NUM); FOR I := 1 TO NUM DO READLN(INPUT, A[I], B[I]); ADD(A, B, SUM, NUM); SUB(A, B, DIF, NUM) END (* COMPUTE *). First, we compile the program: PASCAL,I=PROG,L=LIST,B=LGO. The source is on PROG, the compiler listing is written on LIST, and LGO is the binary file. Assuming USERLIB is local, we use the LIBRARY command to declare the file as a user library: LIBRARY,USERLIB. To execute the program, we can enter: LGO. USERLIB.67 1 P-6000 - Creating User Libraries 27 May 86 or to make an absolute binary, we can use: LOAD,LGO. NOGO,ABSOLUT. The file ABSOLUT will contain the absolute binary, including all the library routines that it calls. The LIBRARY command informs the loader to search USERLIB for any procedures missing in LGO. To find out more information about the LIBRARY command, see the Cyber Loader Reference Manual. Using INCLUDE Texts in Libraries -------------------------------- You can create an INCLUDE package to allow easier access to your user library routines. In our example, we might have an INCLUDE package to declare the type TABLE and the procedures ADD and SUB. It would be convenient for the user if the INCLUDE package resides on the same file as the library routines. For our example, suppose we have a file (called INCLUDE) which contains the following text: PROCS (* PROCS - USERLIB INCLUDE PACKAGE *) TYPE TABLE = ARRAY [1 .. 100] OF INTEGER; PROCEDURE ADD(A, B : TABLE; VAR C : TABLE; N : INTEGER); EXTERN; PROCEDURE SUB(A, B : TABLE; VAR C : TABLE; N : INTEGER); EXTERN; This file is an INCLUDE package called PROCS. To put this text on the user library, we modify the original compilation procedure as follows: REWIND,LIBPROG,BINARY,INCLUDE. COPYBR,INCLUDE,BINARY. PASCAL,I=LIBPROG,L=LISTING,B=BINARY. This procedure puts the include record as the first record on the file BINARY. We then continue the previous procedure to delete the last two records on BINARY, and call LIBGEN. SKIPEI,BINARY. BKSP,BINARY,2. WRITEF,BINARY. LIBGEN,F=BINARY,P=USERLIB. Now, if we use the CATALOG command which is appropriate for user libraries (see above), we should get the following output: USERLIB.68 1 P-6000 - Creating User Libraries 27 May 86 CATALOG OF USERLIB FILE 1 REC NAME TYPE LENGTH CKSUM DATE 1 USERLIB ULIB 11 3401 84/03/09. 2 PROCS TEXT 34 7227 3 IN.RNGE REL 46 7323 84/03/09. IN.RNGE 4 ADD REL 110 4743 84/03/09. ADD 5 SUB REL 110 5231 84/03/09. SUB 6 USERLIB OPLD 13 7551 84/03/09. 7 * EOF * SUM = 346 We can modify our user program (which is on the file PROG) to use the INCLUDE package: PROGRAM COMPUTE(INPUT, OUTPUT); (*$I'PROCS'/'USERLIB' INCLUDE THE PROCEDURES ON USERLIB *) VAR A, B, SUM, DIF : TABLE; NUM, I : INTEGER; BEGIN (* COMPUTE *) READLN(INPUT, NUM); FOR I := 1 TO NUM DO READLN(INPUT, A[I], B[I]); ADD(A, B, SUM, NUM); SUB(A, B, DIF, NUM) END (* COMPUTE *). We can compile and run this program, assuming USERLIB and PROG are local files, by entering these commands: LIBRARY,USERLIB. PASCAL,I=PROG,L=LIST,B=LGO. LGO. For more information on INCLUDE, see chapter INCLUDE. Updating Old Libraries ---------------------- It is possible to add procedures to an existing user library or to substitute new versions of procedures on a library without recompiling all the procedures. This can be done by compiling only the procedures which will change and then using a program called LIBEDIT to edit in the new routines. The first step is to compile the new procedures. Assuming we have a file (called NEWPROG) which has a user library source program which contains the text of the new procedures, we can compile them by using: USERLIB.69 1 P-6000 - Creating User Libraries 27 May 86 PASCAL,I=NEWPROG,L=LISTING,B=NEWBIN. NEWBIN will be the file containing the compiled routines. The next step is to copy all the old routines (REL records) and INCLUDE texts (TEXT records) out of USERLIB. This is done by using the GTR command: GTR,USERLIB,OLDLIB.TEXT/*,REL/* The GTR command above will copy all TEXT and REL records from USERLIB onto OLDLIB. Since the new compiled routines are on NEWBIN, we can edit OLDLIB using LIBEDIT to create a new user library: LIBEDIT,P=OLDLIB,I=LIBDIR,B=NEWBIN,N=NEWLIB. The file denoted by LIBDIR is a text file containing LIBEDIT directives. NEWLIB is the file containing the edited records. The last step is to generate a new user library from the records on NEWLIB: REWIND,USERLIB,NEWLIB. LIBGEN,F=NEWLIB,P=USERLIB. The file USERLIB will now contain the updated routines. For information on using LIBEDIT and GTR, see the NOS 1 Reference Manual, Volume 1. USERLIB.70 1 P-6000 - Lexical Symbols 27 May 86 Lexical Symbols =============== Alternative symbols recognized by Pascal-6000 are: Traditional Alternative ----------- ----------- ^ @ (only if A+, required by standard) [ (. (required by standard) ] .) (required by standard) : : (64-character set only) The only comment delimiters supported are (* and *); that is, curly braces { and } are not supported. Nested comments are not allowed. The number of characters treated as significant in an identifier is limited only by the maximum length of a source program line (see chapter LIMITS). Thus the following two identifiers will be recog- nized by the compiler as distinct. AVERYLONGIDENTIFIERALAS AVERYLONGIDENTIFIERALSO However, PMD (the Post-Mortem Display) provides only the first ten characters of an identifier. Also, names passed to the Control Data loaders, such as when the "E" compiler option is used, are still restricted to seven characters. The underscore character may be used in an identifier as a separator | to improve the readability of Pascal source code. Therefore, the | following identifiers are valid: | | LINE_VOLTAGE ENTRY_KEY ACCOUNT_TOTAL | | The syntax for identifier is replaced by | | identifier = letter { [ underscore ] ( letter | digit ) } . | underscore = "_" . | | Note that an underscore in an identifier is a separator. It can only | appear between letters and digits. An identifier cannot begin or end | with an underscore nor can two underscores be adjacent. | | An underscore is significant to the spelling of an identifier. For | example, the two following identifiers are NOT equivalent: | | INIT IN_IT | | NOTE: Using underscores in identifiers is an extension. | SYMBOLS.71 1 P-6000 - Lexical Symbols 27 May 86 Predefined and predeclared identifiers recognized by Pascal-6000 are: CONSTs - *COL, FALSE, MAXINT, *PER, TRUE TYPEs - *ALFA, BOOLEAN, CHAR, INTEGER, *MARKER, REAL, TEXT VARs - INPUT, OUTPUT FUNCTIONs - ABS, ARCTAN, *CARD, CHR, *CLOCK, COS, EOF, *EOI, | EOLN, *EOS, EXP, *EXPO, LN, ODD, ORD, PRED, *RELVALUE, ROUND, SIN, SQR, SQRT, SUCC, TRUNC, | *UNDEFINED PROCEDUREs - *DATE, DISPOSE, GET, *GETFILE, *GETSEG, *HALT, | *MARK, *MNEW, *MESSAGE, NEW, PACK, PAGE, PUT, | *PUTFILE, *PUTSEG, READ, READLN, *RELEASE, RESET, | REWRITE, *TIME, UNPACK, WRITE, WRITELN Reserved words recognized by Pascal-6000 are: AND, ARRAY, BEGIN, CASE, CONST, DIV, DO, DOWNTO, ELSE, END, FILE, FOR, FUNCTION, GOTO, IF, IN, LABEL, MOD, NIL, NOT, OF, OR, *OTHERWISE, PACKED, PROCEDURE, PROGRAM, RECORD, REPEAT, *SEGMENTED, SET, THEN, TO, TYPE, UNTIL, *VALUE, VAR, WHILE, WITH Directives recognized by Pascal-6000 are: | *EXTERN, *FORTRAN, FORWARD | * means nonstandard, Pascal-6000 only. SYMBOLS.72 1 P-6000 - Character Set Tables 27 May 86 Character Set Tables ==================== Representation of Standard Pascal Characters in Programs -------------------------------------------------------- The following chart shows the character codes that the compiler accepts in a program source file for each standard Pascal character. Some of these codes depend on the setting of the A compiler option. For example, an apostrophe is represented by code 70B when A+ is set, and is represented by code 60B when A- is set. The Pascal characters "up arrow" and "colon" have more than one accepted character code. Thus, for example, when A+ is set either code 74B or 76B is accepted to represent an up arrow. The chart also shows the CDC ASCII graphics assigned to the codes in the "A+ Code" column and the CDC Scientific graphics assigned to the codes in the "A- Code" column. The codes 00B and 63B are handled differently in the 63-character sets and 64-character sets. The graphic assigned to code 00B is undefined in the 63-character sets and is a colon in the 64-character sets. The graphic assigned to code 63B is a colon in the 63-character sets and a percent in the 64-character sets. Pascal ASCII A+ Scientific A- Character Graphic Code Graphic Code letters A-Z 01B-32B A-Z 01B-32B digits 0-9 33B-44B 0-9 33B-44B plus + 45B + 45B minus - 46B - 46B asterisk * 47B * 47B slash / 50B / 50B left parenthesis ( 51B ( 51B right parenthesis ) 52B ) 52B dollar sign $ 53B $ 53B equal sign = 54B = 54B space 55B 55B comma , 56B , 56B period . 57B . 57B left bracket [ 61B [ 61B right bracket ] 62B ] 62B less than < 72B < 72B greater than > 73B > 73B semicolon ; 77B ; 77B apostrophe apostrophe 70B equivalence 60B up arrow circumflex 76B up arrow 70B at sign 74B colon undefined / colon 00B undefined / colon 00B colon / percent 63B colon / percent 63B underscore underscore 65B bent right arrow 65B | CHARSET.73 1 P-6000 - Character Set Tables 27 May 86 Character codes and graphics for type CHAR ------------------------------------------ The following chart shows the graphic that is assigned to each character code under the CDC ASCII subset and the CDC Scientific character set. The graphics for codes 00B and 63B depend on whether the site is running the 63-character set or the 64-character set; for these codes, both graphics are shown with the 63-character set graphic preceding the 64-character set graphic (e.g., colon / percent). An asterisk in one of the "Restricted" columns indicates that the character code is special and is allowed in Pascal programs only within comments and character-strings. Note that whether a character code is restricted depends in some cases on the setting of the A compiler option. Character Restricted ASCII Scientific Code A+ A- Graphic Graphic 00B undefined / colon undefined / colon 01B-32B A-Z A-Z 33B-44B 0-9 0-9 45B + + 46B - - 47B * * 50B / / 51B ( ( 52B ) ) 53B * * $ $ 54B = = 55B 56B , , 57B . . 60B * pound sign (hash) equivalence 61B [ [ 62B ] ] 63B colon / percent colon / percent 64B * * double quote not equals 65B underscore bent right arrow | 66B * * exclamation logical or 67B * * ampersand logical and 70B apostrophe up arrow 71B * * question mark down arrow 72B < < 73B > > 74B * at sign less or equals 75B * * back slash greater or equals 76B * circumflex logical not 77B ; ; CHARSET.74 1 P-6000 - Pascal-6000 Syntax 27 May 86 Pascal-6000 Syntax ================== The Extended Backus-Naur Form (EBNF) metalanguage is summarized. EBNF is then used to specify the "lexical" rules by which symbols and symbol separators are formed from characters, and the "syntactic" rules for forming programs from symbols and separators. EBNF Summary ------------ An EBNF specification of a language consists of a collection of rules or productions that describe the formation of sentences in the language. Each production consists of a non-terminal symbol and an EBNF expression separated by an equal sign and terminated by a period. The non-terminal symbol is a "meta-identifier" and the EBNF expression is its definition. The EBNF expression is composed of zero or more terminal symbols, non-terminal symbols (meta-identifiers), and other metasymbols as summarized in the following table. Metasymbol Meaning ---------- ------- = is defined to be | alternatively . end of definition [ x ] 0 or 1 instances of x { x } 0 or more instances of x ( x | y ) grouping: either of x or y "xyz" the terminal symbol xyz meta-identifier the non-terminal symbol meta-identifier As an example, the following EBNF rules specify the syntax for an EBNF "specification". They assume the meta-identifiers "non-terminal" and "terminal", which are discussed below. specification = rule { rule } . rule = non-terminal "=" expression "." . expression = alternative { "|" alternative } . alternative = element { element } . element = group | option | sequence | symbol . group = "(" expresson ")" . option = "[" expression "]" . sequence = "{" expression "}" . symbol = non-terminal | terminal . A terminal symbol is one that is not defined by the specification. A non-terminal symbol is defined by a rule in the specification. SYNTAX.75 1 P-6000 - Pascal-6000 Syntax 27 May 86 A meta-identifier is a sequence of letters and hyphens beginning with a letter. A literal terminal symbol is always enclosed in quotes ("); thus, for example, the metasymbols "[" and "]" represent left and right brackets in a Pascal program, whereas [ and ] are metabrackets in an EBNF expression that specify zero or one occurrences of whatever appears between them. In the following sections, rules that begin with an asterisk differ from the standard, due to either an extension or a restriction. Symbols and Symbol Separators ----------------------------- This section defines several symbols for use in the subsequent section. These symbols are: character-string, directive, identifier, label, sign, and unsigned-number. The meta-identifier symbol-separator is also defined, and is referred to in the subsequent section. The non-terminals signed-number and signed-integer define the form of real and integer representations that are accepted by the predeclared procedure READ. The other rules specified here are not used elsewhere. Adjacent terminal symbols in a text derived from a rule in this section cannot be separated by any characters and must occur on the same text line. For example, all characters of an identifier must occur together on one line and with no embedded spaces. apostrophe-image = "''" . character-string = "'" string-element { string-element } "'" . * comment = "(*" { comment-element } "*)" . comment-element = end-of-line | any-character-sequence-not-containing-asterisk-right-parenthesis . digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" . digit-sequence = digit { digit } . directive = letter { letter | digit } . * extended-integer = digit-sequence "b" . fractional-part = digit-sequence . * identifier = letter { [ underscore ] ( letter | digit ) } . | * label = unsigned-integer | extended-integer . letter = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" . SYNTAX.76 1 P-6000 - Pascal-6000 Syntax 27 May 86 scale-factor = signed-integer . sign = "+" | "-" . signed-integer = [ sign ] unsigned-integer . signed-number = signed-integer | signed-real . signed-real = [ sign ] unsigned-real . special-symbol = "+" | "-" | "*" | "/" | "=" | "<" | ">" | "[" | "]" | "." | "," | ":" | ";" | "^" | "(" | ")" | "<>" | "<=" | ">=" | ":=" | ".." | word-symbol . string-character = one-of-a-set-implementation-defined-characters . string-element = apostrophe-image | string-character . symbol-separator = end-of-line | " " | comment . * underscore = "_" . | unsigned-integer = digit-sequence . * unsigned-number = unsigned-integer | extended-integer | unsigned-real . unsigned-real = unsigned-integer "e" scale-factor | unsigned-integer "." fractional-part [ "e" scale-factor ] . * word-symbol = "and" | "array" | "begin" | "case" | "const" | "div" | "do" | "downto" | "else" | "end" | "file" | "for" | "function" | "goto" | "if" | "in" | "label" | "mod" | "nil" | "not" | "of" | "or" | "packed" | "procedure" | "program" | "record" | "repeat" | "set" | "then" | "to" | "type" | "until" | "var" | "while" | "with" | "otherwise" | "segmented" | "value" . Syntactic Specification of Program ---------------------------------- Adjacent symbols in a text derived from a rule in this section may be separated by zero or more symbol-separators; adjacent symbols must be separated by one or more symbol-separators if the symbols are numbers, word-symbols, or identifiers. actual-parameter = expression | variable-access | procedure-identifier | function-identifier . actual-parameter-list = "(" actual-parameter { "," actual-parameter } ")" . adding-operator = "+" | "-" | "or" . array-type = "array" "[" index-type { "," index-type } "]" "of" component-type . SYNTAX.77 1 P-6000 - Pascal-6000 Syntax 27 May 86 array-variable = variable-access . assignment-statement = ( variable-access | function identifier ) ":=" expression. base-type = ordinal-type . * basic-value = constant | "nil" | "[" set-value-element-list "]" . * block = { label-declaration-part constant-definition-part type-definition-part variable-declaration-part initial-value-declaration-part procedure-and-function-declaration-part } statement-part . Boolean-expression = expression . bound-identifier = identifier . buffer-variable = file-variable "^" . * case-constant = constant | constant ".." constant . | case-constant-list = case-constant { "," case-constant } . case-index = expression . case-list-element = case-constant-list ":" statement . * case-statement = "case" case-index "of" case-list-element { ";" case-list-element } | [ [ ";" ] "otherwise" statement-sequence ] | [ ";" ] "end" . | component-type = type-denoter . component-variable = indexed-variable | field-designator . compound-statement = "begin" statement-sequence "end" . conditional-statement = if-statement | case-statement . conformant-array-parameter-specification = value-conformant-array-specification | variable-conformant-array-specification . conformant-array-schema = packed-array-conformant-schema | unpacked-conformant-array-schema. constant = [ sign ] ( unsigned-number | constant-identifier ) | character-string . constant-definition = identifier "=" constant . constant-definition-part = [ "const" constant-definition ";" SYNTAX.78 1 P-6000 - Pascal-6000 Syntax 27 May 86 { constant-definition ";" } ] . constant-identifier = identifier . control-variable = entire-variable . domain-type = type-identifier . else-part = "else" statement . empty-statement = . entire-variable = variable-identifier . enumerated-type = "(" identifier-list ")" . expression = simple-expression [ relational-operator simple-expression ] . factor = variable-access | unsigned-constant | bound-identifier | function-designator | set-constructor | "(" expression ")" | "not" factor . field-designator = record-variable "." field-specifier | field-designator-identifier . field-designator-identifier = identifier . field-identifier = identifier . field-list = [ ( fixed-part [ ";" variant-part ] | variant-part ) [ ";" ] ] . field-specifier = field-identifier . file-type = "file" "of" component-type . file-variable = variable-access . final-value = expression . fixed-part = record-section { ";" record-section } . for-statement = "for" control-variable ":=" initial-value ( "to" | "downto" ) final-value "do" statement . formal-parameter-list = "(" formal-parameter-section { ";" formal-parameter-section } ")" . formal-parameter-section = value-parameter-specification | variable-parameter-specification | procedural-parameter-specification | functional-parameter-specification | conformant-array-parameter-specification . function-block = block . function-declaration = function-heading ";" directive | SYNTAX.79 1 P-6000 - Pascal-6000 Syntax 27 May 86 function-identification ";" function-block | function-heading ";" function-block . function-designator = function-identifier [ actual-parameter-list ] . function-heading = "function" identifier [ formal-parameter-list ] ":" result-type . function-identification = "function" function-identifier . function-identifier = identifier . functional-parameter-specification = function-heading . goto-statement = "goto" label . identified-variable = pointer-variable "^" . identifier-list = identifier { "," identifier } . if-statement = "if" Boolean-expression "then" statement [ else-part ] . index-expression = expression . index-type = ordinal-type . index-type-specification = identifier ".." identifier ":" ordinal-type-identifier . indexed-variable = array-variable "[" index-expression { "," index-expression } "]" . initial-value = expression . * initial-value-declaration = variable-identifier "=" value-specification . * initial-value-declaration-part = [ "value" initial-value-declaration ";" { initial-value-declaration ";" } ] . label-declaration-part = [ "label" label { "," label } ";" ] . member-designator = expression [ ".." expression ] . * multiple-value = [ type-identifier ] "(" value-list ")" . multiplying-operator = "*" | "/" | "div" | "mod" | "and" . new-ordinal-type = enumerated-type | subrange-type . new-pointer-type = "^" domain-type . new-structured-type = [ "packed" ] unpacked-structured-type . new-type = new-ordinal-type | new-structured-type | new-pointer-type . SYNTAX.80 1 P-6000 - Pascal-6000 Syntax 27 May 86 ordinal-type = new-ordinal-type | ordinal-type-identifier . ordinal-type-identifier = type-identifier . packed-conformant-array-schema = "packed" "array" "[" index-type-specification "]" "of" type-identifier . pointer-type-identifier = type-identifier . pointer-variable = variable-access . procedural-parameter-specification = procedure-heading . procedure-and-function-declaration-part = { ( procedure-declaration | function-declaration ) ";" } . procedure-block = block . procedure-declaration = procedure-heading ";" directive | procedure-identification ";" procedure-block | procedure-heading ";" procedure-block . procedure-heading = "procedure" identifier [ formal-parameter-list ] . procedure-identification = "procedure" procedure-identifier . procedure-identifier = identifier . procedure-statement = procedure-identifier [ actual-parameter-list | read-parameter-list | readln-parameter-list | write-parameter-list | writeln-parameter-list ] . program = program-heading ";" program-block "." program-block = block . program-heading = "program" identifier [ program-parameter-list ] . * program-parameter = identifier { program-parameter-characteristics } . * program-parameter-characteristics = "+" | "/" . * program-parameter-list = "(" program-parameter { "," program-parameter } ")" . read-parameter-list = "(" [ file-variable "," ] variable-access { "," variable-access } ")" . readln-parameter-list = [ "(" (file-variable | variable-access ) { "," variable-access } ")" ] . record-section = identifier-list ":" type-denoter . record-type = "record" field-list "end" . record-variable = variable-access . SYNTAX.81 1 P-6000 - Pascal-6000 Syntax 27 May 86 record-variable-list = record-variable { "," record-variable } . relational-operator = "=" | "<>" | "<" | ">" | "<=" | ">=" | "in" . repeat-statement = "repeat" statement-sequence "until" Boolean-expression . * repetition = [ constant "of" ] . repetitive-statement = repeat-statement | while-statement | for-statement . result-type = simple-type-identifier | pointer-type-identifier . set-constructor = "[" [ member-designator { "," member-designator } ] "]" . set-type = "set" "of" base-type . * set-value-element-list = [ set-value-elements { "," set-value-elements } ] . * set-value-elements = constant [ ".." constant ] . simple-expression = [ sign ] term { adding-operator term } . simple-statement = empty-statement | assignment-statement | procedure-statement | goto-statement . simple-type-identifier = type-identifier . statement = [ label ":" ] ( simple-statement | structured-statement ) . statement-part = compound-statement . statement-sequence = statement { ";" statement } . structured-statement = compound-statement | conditional-statement | repetitive-statement | with-statement . subrange-type = constant ".." constant . tag-field = identifier . tag-type = ordinal-type-identifier . term = factor { multiplying-operator factor } . type-definition = identifier "=" type-denoter . type-definition-part = [ "type" type-definition ";" { type-definition ";" } ] . * type-denoter = [ "segmented" ] ( type-identifier | new-type ) . type-identifier = identifier . SYNTAX.82 1 P-6000 - Pascal-6000 Syntax 27 May 86 unpacked-conformant-array-schema = "array" "[" index-type-specification { ";" index-type-specification } "]" "of" ( type-identifier | conformant-array-schema ) . unpacked-structured-type = array-type | record-type | set-type | file-type . unsigned-constant = unsigned-number | character-string | constant-identifier | "nil" . value-conformant-array-specification = identifier-list ":" conformant-array-schema . * value-list = [ repetition value-specification { "," repetition value-specification } ] . value-parameter-specification = identifier-list ":" type-identifier . * value-specification = basic-value | multiple-value . variable-access = entire-variable | component-variable | identified-variable | buffer-variable . variable-conformant-array-specification = "var" identifier-list ":" conformant-array-schema . variable-declaration = identifier-list ":" type-denoter . variable-declaration-part = [ "var" variable-declaration ";" { variable-declaration ";" } ] . variable-identifier = identifier . variable-parameter-specification = "var" identifier-list ":" type-identifier . variant = case-constant-list ":" "(" field-list ")" . * variant-part = "case" variant-selector "of" | variant { ";" variant } [ ";" ] | [ "otherwise" "(" field-list ")" [ ";" ] ] . | variant-selector = [ tag-field ":" ] tag-type . while-statement = "while" Boolean-expression "do" statement . with-statement = "with" record-variable-list "do" statement . write-parameter = expression [ ":" expression [ ":" expression ] ] . write-parameter-list = "(" [ file-variable "," ] write-parameter { "," write-parameter } ")" . writeln-parameter-list = [ "(" (file-variable | write-parameter ) { "," write-parameter } ")" ] . SYNTAX.83 1 P-6000 - Compiler Error-Message Summary 27 May 86 Compiler Error-Message Summary ============================== There are several compiler messages that are not identified by numbers. "Empty Source Input File." | | The file specified by the I parameter was positioned at end-of-record. | The file is empty or was not rewound before compilation, or the file | is not assigned (local) to the job. | Four provide specific information from the program: "Undefined type: xxx" "Undeclared procedure: xxx" "Undefined label: xxx" "Undeclared file: xxx" The next two messages perhaps require some explanation: "Incomplete program." This can be caused by mismatched "BEGIN-END" pairs, extra procedure or function headings, failure to close a comment, an extra open comment, a missing "." after the last END, or encountering an operating system end-of-logical-record on the program source file. "Lines following end of program ignored." Extra text was found after the "." following the last END. This error is not fatal. The numbered messages are as follows. 1: Error in simple type. 2: Identifier expected. 3: "PROGRAM" expected. 4: ")" expected. 5: ":" expected. 6: Unexpected symbol. 7: Error in parameter list. 8: "OF" expected. 9: "(" expected. 10: Error in type. 11: "[" expected. 12: "]" expected. 13: "END" expected. 14: ";" expected. 15: Integer constant expected. 16: "=" expected. 17: "BEGIN" expected. 18: Error in declaration part. 19: Error in field-list. 20: "," expected. 21: ".." expected. 22: Mixed order of declarations. | ERROR.84 1 P-6000 - Compiler Error-Message Summary 27 May 86 23: Improper use of underscore in identifier. | 24: Underscore in identifier not allowed. | 40: Value initialization part allowed only in program block. 41: Too few values specified. 42: Too many values specified. 43: Variable initialized twice. 44: Type is neither array nor record. 45: Repetition factor must be greater than zero. 50: Error in constant. 51: ":=" expected. 52: "THEN" expected. 53: "UNTIL" expected. 54: "DO" expected. 55: "TO" or "DOWNTO" expected. 57: "FILE" expected. 58: Error in factor. 59: Error in variable. 60: File type identifier expected. 101: Identifier declared twice. 102: Lowbound exceeds highbound. 103: Identifier is not of appropriate class. 104: Identifier not declared. 105: Sign not allowed. 106: Number expected. 107: Incompatible subrange types. 108: File not allowed here. 109: Type must be ordinal (integer/char/boolean/subrange/enumerated). 110: Tagfield type must be ordinal. 111: Case constant is out of range. | 113: Index type must be ordinal. 115: Base type must be ordinal. 116: Error in type of predeclared procedure parameter. 117: Unsatisfied forward reference. 119: Forward declared; repetition of parameter list not allowed. 120: Function result type must be simple 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: Fixed-point formatting allowed for reals only. 125: Error in type of predeclared function parameter. 126: Number of parameters does not agree with declaration. 127: All parameters in a group must have the same type. 128: Parameter procedure/function is not compatible with declaration. 129: Type conflict of operands. 130: Expression is not of set type. 131: Only equality tests allowed. 132: "<" and ">" not allowed for set operands. 133: File comparison not allowed. 134: Incorrect type of operand(s). 135: Type of operand must be boolean. 136: Set element must be ordinal. 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. ERROR.85 1 P-6000 - Compiler Error-Message Summary 27 May 86 141: Type of variable must be file or pointer. 142: Incorrect parameter substitution. 143: Control-variable type must be ordinal. 144: Incorrect type of expression. 145: Type conflict. 146: Assignment of files not allowed. 147: Incorrect type of case constant. 148: Subrange bounds must be ordinal. 149: Index type must not be integer. 150: Assignment to this function is not allowed. 151: Assignment to formal function is not allowed. 152: No such field in this record. 155: Control variable must be local. 156: Case value specified twice. | 157: Range of case constants is too large (max = 2001). 158: Missing corresponding variant declaration. 159: Real or string tagfields not allowed. 160: Previous declaration was not forward. 161: Multiple forward declaration. 162: Misspelled reserved word or unrecognized directive. 163: Value of label is too large (>9999). 164: Predeclared procedure/function substitution not allowed. 165: Multidefined label. 166: Multideclared label. 167: Undeclared label. 168: Undefined label in the previous block. 169: Error in base set. 170: Value parameter expected. 171: Program parameter must possess a file type. 172: Undeclared program parameter. 173: Fortran procedure or function expected. 174: Pascal procedure or function expected. 175: Missing file "INPUT" in program heading. 176: Missing file "OUTPUT" in program heading. 177: Assignment to function allowed only in function block. 178: Multidefined record variant. 179: X-option of actual procedure/function does not match formal declaration. 180: Control variable must not be a formal parameter. 184: Incorrect use of for-statement control variable. 185: Function must be assigned somewhere in its block. 186: One or more tag values are not specified. 187: Tag field is not allowed as actual variable parameter. 188: Label is not accessible from here. 189: Label is not accessible to previous goto(s) that used it. 190: Identifier being defined was used already in this scope. 191: Type identifier expected. 192: Control variable is threatened by a nested procedure or function. 193: Already a control variable for an encompassing for-statement. 194: Invalid use of function identifier. | 195: There are no others. | 198: Alternate input not found. 199: Only one alternate input may be active. 201: Error in real constant: digit expected. 202: String constant must be contained on a single line. 203: Integer constant exceeds range. ERROR.86 1 P-6000 - Compiler Error-Message Summary 27 May 86 204: 8 or 9 in octal number. 205: Strings of length zero are not allowed. 206: Integer part of real constant exceeds range. 207: Real constant exceeds range. 220: Only the last dimension may be packed. 221: Type-identifier or conformant-array schema expected. 222: Bound-identifier expected. 223: Ordinal-type identifier expected. 224: Actual value parameter must not be conformant array. | 225: Comparison of conformant array parameters is not allowed. | 240: Multi-word value parameters for fortran routines must be by var due to implementation restriction. 250: Identifier scopes too deeply nested (max = 20). 251: Too many nested procedures and/or functions (max = 10) 252: Too many identifier scopes (max = 131071). 253: Code space for block exceeds limit (32768 words). 254: Too many external files (max = 50). | 256: Too many external references (max = 4095). 259: Expression too complicated. 260: Too many exit labels (max = 36). 261: Too many large variables. 262: Node to be allocated is too large. 263: Too many parameters. 264: Too many procedures and functions (max = 4095). 300: Division by zero. 301: Mod by negative modulo. 302: Index expression out of bounds. 303: Value to be assigned is out of bounds. 304: Element expression out of range. 305: Field width must be greater than zero. 306: Actual parameter value is out of range. 307: Packed array must not be larger than unpacked array. | 320: Warning--this predeclared identifier is nonstandard. 321: Warning--octal representation is nonstandard. 322: Warning--integer > maxint is nonstandard. 323: Warning--segmented file is nonstandard. 324: Warning--initial-value declaration part is nonstandard. 325: Warning--external or Fortran procedure is nonstandard. 326: Warning--second parameter is nonstandard. 327: Warning--ord of real or pointer is nonstandard. 328: Warning--otherwise is nonstandard. 329: Warning--"+" or "/" in program heading is nonstandard. 330: Warning--mixed order of declarations is nonstandard. 331: Warning--this option may alter the meaning of the program. 332: Warning--conformant-array as actual value parameter is nonstandard. 333: Warning--treating a conformant-array parameter as a string is nonstandard. 334: Warning--subrange in case constant list is nonstandard. | 335: Warning--underscore in identifier is nonstandard. | 350: Warning--diagnostic language selected is not available: English will be used. ERROR.87 1 P-6000 - Compiler Error-Message Summary 27 May 86 351: Warning--comment within a comment. 352: Warning--missing or invalid compiler-option name. 353: Warning--missing or invalid compiler-option setting. 354: Warning--additional warnings or errors on this line are not indicated. 355: Warning--the following statement cannot be executed. 356: Warning--case constant is outside range of case-index | expression. | 357: Warning--value is outside range of control-variable. | ERROR.88 1 P-6000 - Facts About Pascal-6000 27 May 86 Facts About Pascal-6000 ======================= The Pascal-6000 compiler was implemented at E. T. H. (the Federal Institute of Technology) in Zurich, Switzerland in 1974 as a rewrite of an earlier series of compilers for Control Data machines. Release 2 of Pascal-6000 followed in 1976. Release 3 of Pascal-6000 was developed at the University of Minnesota and released in 1979. Pascal-6000 Release 4 is designed to run on Control Data 6000, Cyber 70, and Cyber 170 series computer systems with operating systems such as KRONOS 2.1, NOS 1, SCOPE 3.4, AND NOS/BE 1. The Pascal-6000 compiler is itself an 10,000-line Pascal program. It was designed to be a fast, one-pass compiler which performs many local optimizations in the generation of object code. This strategy is correct for computing environments where the compiler will be used hundreds or thousands of times a day, and so there is much less need for an optimizing compiler to perform global optimization. The design philosophy behind the language Pascal permits one-pass compilation by limiting the use of forward references to pointer types. HISTORY.89 1 P-6000 - References 27 May 86 REFERENCES ========== This annotated list of references for Pascal may be useful for finding information on the language, the ideas behind its design, and programming methodology. Several introductory texts are given first. Textbooks --------- (1) "Systematic Programming: An Introduction" by Niklaus Wirth. Prentice Hall, 1973, 169 pages. [A concise description of the programming process based on the Pascal programming language. The reader is taught how to con- struct programs which can be proved correct. Most of Pascal's control structures are covered plus the array and file data structures. See the companion book: "Algorithms + Data Struc- tures = Programs".] (2) "A Practical Introduction to Pascal" by Ian Wilson and Tony Addyman. MacMillan and Springer-Verlag, 1978, 140 pages. [A concise description of Pascal giving balanced treatment to both control and data structures. Annotated example programs are presented. Intended to be a replacement for the book "Pascal User Manual and Report" as a rigorous tutorial about Pascal.] (3) "Programming in Pascal" by Peter Grogono. Addison-Wesley, 1978, 350 pages. [A full introduction to Pascal for beginners with emphasis on Pascal syntax and data structures. Numerous practical examples are given for common programming algorithms. A guide to CDC-6000 Pascal is in an appendix.] (4) "PASCAL: An Introduction to Methodical Programming" by Bill Findlay and David Watt. Pitman and Computer Science Press, 1978, 306 pages. [A complete introduction to the art of programming using Pascal. Each fundamental programming concept is presented as well as its representation in Pascal. The book emphasizes proper program development right from the start.] (5) "An Introduction to Programming and Problem Solving with Pascal" by Mike Schneider, Steve Weingart, and David Perlman. John Wiley, 1978, 394 pages. [A complete coverage of the practical programming process from problem specification through debugging and maintenance with emphasis on good programming style. A full description of Pascal is given concentrating on control structures.] (6) "Advanced Programming and Problem Solving With Pascal" by G. Michael Schneider and Steven C. Bruell. John Wiley, 1981, 506 pages. [A more advanced version of #5.] REFER.90 1 P-6000 - References 27 May 86 (7) "Algorithms + Data Structures = Programs" by Niklaus Wirth. Prentice Hall, 1976, 366 pages. [An extremely readable book on advanced programming concepts. Emphasis is given on Pascal's data structuring facilities and their effective use in practical problems: sorting, searching, recursive algorithms, dynamic data, language processing, and compiling.] Pascal - The Programming Language --------------------------------- (1) "Specification for Computer Programming Language Pascal" - BS | 6192:1982, British Standards Institution, 2 Park Street, London, | W1A 2BS. | [The English version of the ISO standard.] | (2) "Pascal User Manual and Report", Third Edition, by Kathleen Jensen | and Niklaus Wirth, revised for the ISO Standard by Andrew | B. Mickel and James F. Miner. | Springer-Verlag, 1974, 1975, 1976, 1978, 1985, 266 pages. | [The standard tutorial and reference manual for Pascal in two | parts: a complete user's manual with examples, followed by a | concise definition of Pascal syntax and with informal descriptions | of Pascal semantics. Largely rewritten for the third edition.] | (3) "An Axiomatic Definition of the Programming Language Pascal" by C. A. R. Hoare and Niklaus Wirth. "ACTA Informatica", (2:4), 1973, pp. 335-355. [Specifies a formal semantics definition of most constructs in the standard (revised) definition of Pascal. Used as a guide to users and compiler implementors.] (4) "The Programming Language Pascal" by Niklaus Wirth. "ACTA Informatica", (1:1), 1971, pp. 36-61. [Contains the original language definition of Pascal--which was subsequently revised and published in the book "Pascal User Manual and Report".] (5) "An Assessment of the Programming Language Pascal" by Niklaus Wirth. "SIGPLAN Notices", (10:6), July, 1975, pp. 23-30. (Also in "IEEE" "Transactions on Software Engineering", (1:2), 1975. [A look back on 5-year's experience with the programming language Pascal. Remaining problems are discussed as well as design flaws. Certain data-structuring facilities are distinguished for their aid in the production of reliable software.] (6) "Ambiguities and Insecurities in Pascal" by Jim Welsh, W. J. Sneeringer, and C. A. R. Hoare. "Software Practice and Experience", Vol 7, 1977, pp. 685-696. [The best critique of Pascal to have appeared. The ambiguities discussed are equivalence of types (name vs. structure), scope rules and one-pass compilation, and set constructors. The insecu- rities covered are language features whose implementation either risks undetected violation of rules or incur intolerable run-time checking overhead.] REFER.91 1 P-6000 - References 27 May 86 * Pascal Philosophy - Programming Language Design ----------------------------------------------- (1) "Structured Programming" by O. J. Dahl, E. W. Dijkstra, and C. A. R. Hoare. Academic Press, 1972, 220 pages. [This is the revolutionary book which made the programming world aware of the principles of structured programming. It consists of three papers; the Dijkstra paper is entitled "Notes on Structured Programming", and provides the theoretical basis for Pascal's control structures. Some simple axioms are explained for proving program correctness in the course of covering the process of program development utilizing good control structures. The Hoare paper is entitled: "Notes on Data Structuring", and provides the theoretical basis for Pascal's data structures. Each data- structuring method is derived from well-grounded mathematical concepts--the array: a mapping; the set: a powerset; the file: a sequence; the record: a cartesian product; and the variant record: a discriminated union.] (2) "The Programming Language Pascal and its Design Criteria" by Niklaus Wirth. "Infotech State of the Art Report No. 7: High Level Langua- ges", 1972, pp. 451-473. [An examination of the problems incurred in the design of a general-purpose, procedure-oriented programming language. Because some of the design criteria appear to conflict with one another, language design has become an art of finding a balance among them.] (3) "Hints on Programming Language Design" by C. A. R. Hoare. Stanford University Computer Science Dept. Report No. 403, October, 1973. (Also in "SIGACT/SIGPLAN Symposium on the Princi- ples of Programming Languages" proceedings, December, 1973.) [Hoare, a language "feature" designer gives insights into the evaluation of programming languages. They are viewed as having to help programmers perform their work. A revealing assessment is given for each of the various major programming languages includ- ing Pascal.] (4) "On the Design of Programming Languages" by Niklaus Wirth. "North Holland Information Processing: Programming Methodolo- gy", 1974, 8 pages. [Past experiences of a programming language designer are reported. The view is presented that a language should be simple, and that its simplicity must be achieved by transparence and clarity of its features and by a regular structure rather than by utmost conciseness and unwanted generality.] (5) "Programming Languages: What to Demand and How to Assess Them" and "Professor Cleverbyte's Visit to Heaven" by Niklaus Wirth. "E. T. H., Institut fuer Informatik Technical Report No. 17", March 1976, 32 pages. [Some hints on how adequate system-development languages should be REFER.92 1 P-6000 - References 27 May 86 designed are presented. A clear distinction must be made between a language and its implementation. Quantitative measurements about the CDC-6000 Pascal implementation are given to establish a guideline for objective evaluation.] [A satire based on Mark Twain's "Captain Stormfield's Visit to Heaven" in which past and present hardware and software trends are extrapolated "grotesquely" into the future. It is shown that perhaps these trends do not signify real progress and that there may exist sensible limits to growth.] Structured Programming ---------------------- (1) "Program Development by Stepwise Refinement" by Niklaus Wirth. "Communications of the ACM", (14:4), April, 1971. [The 8-Queens Problem is used as an example to illustrate a structured method of creating programs. This is a landmark article using an elaborate example to explain structured-program- ming techniques.] (2) "The Humble Programmer" by Edsger Dijkstra. "Communications of the ACM", (15:10), October, 1972. [The 1972 ACM Turing Award lecture appearing as an article containing personal reflections on the software crisis. The message to programmers emphasizes the need for the widespread knowledge of structured-programming methods.] (3) "A Review of Structured Programming" by Donald Knuth. Stanford University, Computer Science Dept. Report No. 371, June, 1973. [A paper giving a detailed review of the book: "Structured Programming" in the form of open letters to the authors.] (4) "Structured Programming with GOTO Statements" by Donald Knuth. "Computing Surveys", (6:4), December, 1974. [A controversial view of structured programming which considers new designs for program control structures and methods for developing programs. One is taught to introduce the unrestricted GOTO only through a process of well-defined transformations on a possibly inefficient, but readable program.] (5) "Structured Programming, Program Teaching, and the Programming Language Pascal" by Olivier Lecarme. "SIGPLAN Notices", (9:6), July, 1974. [All three topics are considered in various combinations with the resulting conclusion that Pascal is good for teaching structured programming.] (6) "On the Composition of Well-Structured Programs" by Niklaus Wirth. "Computing Surveys", (6:4), December, 1974. [Describes the development of programming methods useful in conjunction with today's structured languages such as Pascal. Examples are given illustrating systematic programming in a variety of applications.] REFER.93 1 P-6000 - References 27 May 86 (7) "The Design of Well-Structured and Correct Programs" by S. Alagic and M. Arbib. "Springer-Verlag", 1978, 292 pages. [Numerous actual programming situations are analyzed using struc- tured-programming techniques and the language Pascal.] REFER.94