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 b