[go: up one dir, main page]

0% found this document useful (0 votes)
119 views154 pages

Pascal MT+ Language Manual Feb83

Uploaded by

gottes villain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
119 views154 pages

Pascal MT+ Language Manual Feb83

Uploaded by

gottes villain
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 154

Pascal/MT + ™

Language
Reference Manual

Copyright © 1983

Digital Research
P.O. Box 579
801 Lighthouse Avenue
Pacific Grove, CA 93950
(408) 649-3896
TWX 910 360 5001

All Rights Reserved


COPYRIGHT

Copyright © 1983 by Digital Research. All rights


r e served. No pa r t of this publica tion may be
reproduced, transmitted, transcribed, stored in a
retrieval system, or translated into any language or
compu ter language, i'n any form or by any means,
electron ic, mechan ical, magnetic, optical, chemical,
manual or otherwise, without the prior written
permission of Digital Research, Post Office Box 579,
Pacific Grove, California, 93950.

This manual is, however, tutorial in nature. Thus,


the reader is gran ted permiss ion to include the
example programs, either in whole or in part, in his
or her own programs.

DISCLAIMER

Digital Research makes no representations or


warranties with respect to the contents hereof and
spec if ically discla ims any implied war ran ties of
me r chan ta bi 1 i ty or fitness for any particular
purpose. Further, Dig i tal Research reserves the
right to revise this publication and to make changes
from time to time in the content hereof without
obliga tion of Dig i tal Research to no-tify any person
of such revision or changes.

TRADEMARKS

CP/M and CP/M-86 are reg is tered trademarks of


Dig i tal Research. Pascal/MT+ is a trademark of
Dig~tal Research.

The Pascal/MT+ Language Reference Manual was


prepared using the Digital Research TEX Text
Formatter, and printed in the United States of
America.

***********************************
* First Edition: February 1983 *
***********************************
Table of Contents

1 Pasca1/MT+ Programs
1.1 Program Stiucture 1-1

1.1.1 Program Heading . • • • • • • • . • • 0 1-2


1.1.2 Declarations ~nd Definitions . . . • • 1-2
1.1.3 Statement Body . . . • . • • . 1-4
1.1.4 Modules . . . . . . . . . . 1-4

1.2 Scope 1-5


1.3 Comments . 1-6

2 Identifiers and Constants


2.1 Identifiers 2-1
2.2 Constants 2-2
2.2.1 Numeric Literals 2-2
2.2.2 String Literals 2-3
I 2.2.3 Named Constants 2-3

3 Variables and Data. Types

3.1 Type Definition 3-1


3.2 Variable Declaration • . 3-1
3.3 Simple Types • 3-2
3.3.1 BOOLEAN • • 0 •• • • • • • 3-3
3.3.2 CHAR .••. 3-3
3.3.3 INTEGER and LONGINT 0 • • • • • • •. 0 • 3-4
3.3.4 REAL • • •. . 0 • • • • • • 3-4
3.3.5 BYTE and WORD . . . •••. • • • . 3-5
3.3.6 User-defined Ordinal Types . • . 0 3-5
3.3.7 Pointers . • • • . • • • . • • • • . . 3=6
3.4 Structured Types • 3-6
3.4.1 Arrays . • • .. 3~7
3.4.2 Strings . • • • • • • • •• 3- 8
3.4.3 Sets • • • . • • •. 3-9
3.4.4 Records • . 3-10

v
Table- of Contents
( continued)

4 Operators and Expressions _


4.1 Arithmetic Expressions -4-3
4.2 Boolean Expressions 4-3
4.3 Logical Expressions 4-4
4.4 Set Expressions 4-5

5 Statements
5.1 The Assignment Statement 5-1
5.2 The CASE Statement •• 5-2
5.3 The Empty Statement
·..···· ··· 5-3
5.4 The FOR Statement
· ··· 5-3
5.5 The GOTO Statement
· 5-5
IF Statement .
5.6 The
···· 5-6
5.7 The REPEAT Statement
· · ··· 5-7
5.8 The WHILE Statement
···· · 5-8
WITH Statement . . .
5.9 The
· ···· ·· 5-8

6 Procedures and Functions

6.1 Procedur~ Definitions • • • • • • 6-2


6.2 Parameters • • • • • 6-3
6.3 Conformant Arrays • • 6-5
6~4 Predefined Functions and Procedures • • • 6-8
ABS Function • e. • 6-11
ADDR Function • • • • 6-12
ARCTAN Funct ion • • • • 6-13
ASSIGN Function. • • • • • • • • • 6-14
BLOCKREAD, BLOCKWRITE Function. 6-16
CHAIN Function. • • • • • • 6-17
CHR Function. • •• • • • • • • 6-18

vi
Table of Contents
(continued)

CLOSE Function 6-19


CONCAT FUnction • . 6-20
COpy Function • 6-21
COS Func tion 6-22
DELETE Function • 6-23
DISPOSE Function 6-24
EOLN, EOF Function . • • • 6-25
EXIT Function • • 6-27
EXP Function • • • . • • • • 6--28
FILLCHAR Function . • •••••••• • 6-29
GET Function . • • • 6-30
HI, LO, SWAP Function 6-31
INLINE Function .
INSERT Function •
.. .
". 6-32
6-33
IORESULT Function . . • 6-34
LENGTH Function . • . 6-35
LN Function . • • • . 6-36
MAXAVAIL, MEMAVAIL Function 6-37
MOVE, MOVERIGHT, MOVELEFT Function 6-38
NEW Function . • • • • 6-40
ODD Function • • • . 6-41
OPEN Function . • . • . 6-42
ORO Function • . • . 6-43
PAC'K, UNPACK Function • . • • • • • • . • • 6-44
PAGE Function • 6-45
POS Function 6-46
PRED Function • 6-47
PURGE Function 6-48
PUT Function • • • • 6-49
READ, READLN Function • . 6-50
READHEX, WRITEHEX, LWWRITEHEX Function. 6-51
RESET Func tion • . ., 6-52
REWRITE Function • • • . • . • • • . 6-53
RIM85, SIM85 Function . • • • . 6-54
ROUND Func tion • • • . • • 6-55
SEEKREAD, SEEKWRITE Function • • • • 6-56
SHL, SHR Function • 6-57
SIN Function • 0 • 0 6-58
SIZEOF Function • 6-59
SQR Function . • • • 6~60
SQRT Function . 6-61
SUCC FUDC tion • 6-62
TRUNCFunction 6-63
TSTBIT, SETBIT, CLRBIT Function 6-64
-WAIT Func tion . • • • . • . 6-65
WNB; GNB Function • • . 6-66
WRITE,WRITELN Function . • • 6-67

vii
Table of Contents
(continued)

@BDOS Function • • • • 6-69


@BDOS86 Function • • • • • • 6-70
@CMD Function • 6-71
@ERR Function • • 6-72
@HLT Function • 6-73
@HERR Function 6-74
@MRK Function • . • . • 6-75
@RLS Function 6-76

.7 Input and Output 7-1


7.1 Fundamentals of Pascal/MT+ I/O • 7-1
7.2 Regular I/O 7-2
7.3 INP and OUT Arrays
· ··.. 7-5
7.4 Redirected I/O . 7-5
7.5 Sequential I/O .. . .' . 7-9
7.5.1
7.5.2
TEXT Files
· .··
Writing tq the pr inter
7-9
7-12
7.6 Random Access I/O
· .··. 7-12

viii
Foreword

The Pascal/MT~· language is a full implementation of standard


Pascal as set forth in the International Standards Organization
(ISO) standard DPS/7185. The Pascal/MT+ language also has several
additions to standard Pascal. These addi tions make P'ascal/M~~+ more
su i table for commerc ial prog'ramming, and increase its power to
develop high-quality, efficiently maintainable software. The
additions fall into four categories:
• enhanced I/O
• additional data types
• access to the run-time system
• modules and overlays
Pascal/MT+ is useful for both data processing applications and
for real-time control applications.
The Pascal/MT+ system, which includes a compiler, linker, and
programming tools, is implemented on a variety of operating systems
and microprocessors. Because the language is consistent an,ong the
various implementations, Pascal/MT+ programs are easily
transportable between target processors and operating systems. The
Pascal/MT+ system can also generate software for use in a ROM-based
environment, to operate with or without an operating syst~m.
This manual describes the Pascal/MT+ language with emphasis on
those features that are unique to Pascal/MT+. Information in this
manual ,cover s all language-related topics independent of the'
implementation.
Information about the compiler, linker, the Pascal/MT+
programming tools, and topics related to the operating system are
contained in the version of the Pascal/MT+ Language Programmer's
~ pertinent to your specific implementation.

This manual assumes you are already familiar with the Pascal
language in general. If you are not familiar with Pascal, refer to
Appendix C for a bibliography of textbookf~.
This manual uses Backus-Naur Form (BNF) notation to formally
describe the syntax of Pascal statements. If you are not familiar
with BNF notation, see Appendix B.

iii
Appendixes

A Reserved Words and Predefined Identifiers • • • • • • • • A-l

B BNF Notation • • • • • • • • • • • • • • • • • • • eo • • B-1

c Differences from ISO Standard C-l

o Bibliography 0-1

ix
Figures,Tables and Listings

Figures
1-1 Block Structure in Pascal/MT+ 1-1
7-1 Lines in a TEXT File • • •• 7-9
7-2 Records in a File . • • • • • • • . • • • 7-14

Tables
3-1 Predefined Data Types • 3-2
4-1 Summary of Pascal/MT+ Operators • . • • • 4-1
4-2 Boolean Operations • • • • • • · . • • 4-4
4-3 Logical Ope~ators • . • • • • • • • • 4-5

6-1 Predefined Functions and Procedures . • • • • 6-8


6-2 Device ·Names . • • • • • • • • • • . .6-13
6-3 EOLN, EOF Valuses for a TEXT File • . · • • • 6-26
6-4 EOF Values fora Non-TEXT File . . • • .6-26
A-I Pascal/MT+ Reserved Words • • • • • . · A-I
A-2 Pascal/MT+ Predefined Identifiers • . · • . . A-I

Listings
1-1 Simple Pascal/MT+ Program • • • · 1-2
1-2 Declarations and Definitions • • • . · 1-4
'1:-3 Example of Scope Rules • 1-6
1-4 Example Program with Comments 1-7
3-1 Program Using Sets 3-10
4-1 Set Expressions . • • • 4-7
6-1 FORWARD Declarations • • • • • • . • . 6-3
6-2a Parameter Passing • •• • • • . • 6-4
6-2b Output from VALVAR Program • 6-4
6-3 Procedural Parameters • • • · . • • 6-5
6-4 Conformant Array Example · .6-7
7-1 File Input ~nd Output • • . . . . . • . . • 7-4
7-2 Red irec ted I/O • • • • . . . • • • 7-8
7-3 TEXT File Processing 7-11
7-4 Writing to a Printer and Number Formatting 7-12
7-5 Random File I/O • . . • • • _. • • • • . • • 7-15

x
Section 1
Pascal/MT+ Programs

1.1 Program Structure


Pascal/MT+ is a block-structured language. That is, you group
one or more statements into logically related units called blc~ks.
Every block has a heading, an optional declaration and definition
section, and a set of statements. In every Pascal/MT+ program, the
outermost ~lock is the main ~rogram.
You can nest blocks inside your program. That is, you can put
one block inside another block, but not overlap them. Inside
blocks, you can also nest procedures and functions (see Section 6)e
Figure 1-1 illustrates the typical block-structure of Pascal/MT+.

PROGRAM
VAR _

PROCEDURE _
BEGIN .

[
END

PROCEDURE _ .
VAR_

BEGIN

[
END

BEGIN

BEG'"

[
B~~
[
END:
END:

END.

Pigure 1-1. Block-st.ructure in Pasca1/1ft+

1-1
Pascal/MT+ Reference Manual 1.1 Program Structure

Listing 1-1 shows a small Pascal/MT+ program containing a


nested block.

CONST
LIMIT = lO~
MESSAGE = 'TESTING PASCAL/MT+'~

VAR
NAME : STRING~

PROCEDURE RESPOND (ST STRING) ~

VAR
I INTEGER~

BEGIN
FOR I :~ 1 TO LIMIT DO
BEGIN
WRITELN (ST) ~
ST : = CONCAT (' I, ST) (* SHIFTS NAME TO RIGHT *)
END
END~

BEGIN
WRITELN (MESSAGE)~
WRITELN (' WHAT IS YOUR NAME? I ) ;

READLN (NAME)~
RESPOND ( NAME) ;
WRITELN' ('FINISHED I , MESSAGE)
END •.

Listing 1-1. SiJlpl.e Pascal./m.'+ Prograa

1.1.1 Prograa Beading


A program heading has the following form:
PROGRAM <program name> {(<program paramet~rs»};
The <program name> has no significance inside the program, but you
should not use the name for any other data item in the program. The'
optional <program parameters> have no special meaning in Pascal/MT+,
as they do in some"other versions of Pascal. '
Pascal/MT+ Reference Manual 1.1 Program Structure

1.1.2 Declarations and Definitions


You must define an identifier before you use it in a program,
unless the identifier is predefined by the language (see Appendix
A). Listing 1-2 shows an example of the declaration and definition
part of a program illustrating each of the major kinds of
declarations as shown in the following list.

1) LABEL declarations
2) CONSTANT declarations
3) TYPE definitions
4) VAR declarations
5) PROCEDURE and FUNCTION definitions

Note that LABEL, CONSTANT, TYPE, and VAR declarations can be in


any order, and there can be multiple occurrences of each type in a
module. PROCEDURE and FUNCTION declarations must appear last, and
there can be only one section of these per module.
Section 3 descr ibes the var ious kinds of data type defini tions ..

1-3
Pascal/MT+ Reference Manual 1.1 Program Structure

LABEL
34, 356, 755, 1000;

CONST
TOP = lOa:
BOTTOM = -TOP;
LIMIT = 1.OE-16:
MESSAGE = 'THANK YOU FOR NOT SMOKING":

TYPE
COLOR = (RED, YELLOW, BLUE, GREEN, ORANGE) ;
INDEX = BOTTOM •• TOP;
PERPt = "PERSON;
PERSON RECORD
NAME,
ADDRESS STRING;
PHONE S~RING [8]
END;

VAR
COLR COLOR:
I, J INTEGER;
LIST ARRAY [ INDEX] OF PERPT;

PROCEDURE ECHO (ST : STRING):


BEGIN
WRITELN (ST, , " ST)
END:

Listing 1-2. Declarations and Definitions

1.1.3 Stateaent Body

The words BEGIN and END surround tpe body of statements in a


block, which can contain zero or more statements. I·f the block is
the main program block, you must put a period after the word END.
Within the statement body, separate each statement with a semicolon =

1 •. 1.4 Modules

A module is a portion of a program that you compile separately,


and then link to the main program. The general form of a module is
the same as a program, except that a module does not have a main
statement body. The only executable code in a module is contained
in procedures and functions. The following example illustrates a
simple single-procedure module. .

1-4
Pascal/MT+ Reference Manual 1.1 Program Structure

MODULE SIMPLE~

PROCEDURE MARK (CALL_NUM : INTEGER);


BEGIN
WRITELN ('IN MODULE SIMPLE, CALLED FROM: " CALL_NUM)
END;
MODEND.

Notice that the word MODULE replaces the word PROGRAM and that the
word MODEND replaces the main statement body.
Refer to the Pascal/MT+ Language Programmer's Guide for your
implementation for more information about modules and modular
programs.

1.2 Scope
Every identifier in a Pascal/MT+ program has a scope. The
scope of an identifier is the set of all blocks where you can make a
valid reference to the identif ier. The normal scope of an
identifier is anywhere inside its defining block, starting from its
actual definition.
However, when a nested block redefines. the same identifier, the
outer variable is inaccessible from the inner block. When the same
identifier has multiple definitions, the innermost definition is the
one that applies.
This manual uses the terms global and local. The declarations
at the outermost level in the program are the global declarations.
Declarations in a block are local to that block. A variable is
local to a block if its declaration is in that same block. Inside a
nested block, a variable declared in a containing block 'is usable,
but it is not local to that nested .block. Wi thin a contained block,
a reference to a variable in a containing block is called an "up-
level reference".
Listing 1-3 Shows a program containing nested blocks with
multiple definitions for the same identifiers. The comments in the
program
. explain which definitions apply at various points.
.

1-5
Pascal/MT+ Reference Manual 1.2 Scope

PROGRAM SHOWSCOPE;
VAR
X, Y, Z : INTEGER; (* X,Y,Z ARE GLOBAL *)
PROCEDURE PROC1;
VAR
BEGIN
X := Y / Z (* Y & Z FROM MAIN BLOCK *)
END;
PROCEDURE PROC2;
VAR
W : INTEGER; (* W LOCAL TO PROC2 *)
Y : STRING; (* Y LOCAL TO· PROC2 *)
BEGIN
y := 'ABCDEFG' ;
W := X; (* X FROM MAIN BLOCK *)
Z := X DIV 3 (* X FROM MAIN BLOCK *)
END;
BEGIN
Y : = 35; (* X, Y, & Z ARE ALL INTEGERS *)
Z : = 12; (* IN THIS BLOCK *)
PROC1; (* CHANGES X *)
PROC2; (* CHANGES Z *)
WRITELN (X, Y, Z)
END.

Listing 1-3. Exa.ple of Scope Rules

1.3 Comaents
You can put a comment anywhere in a program that you can put a
blank space; the compiler ignores comments. There are two ways to
write a comment in a Pascal/MT+ program:
• Surround the comment with the characters { and } .
• Surround the couent with the character pairs. (* and *).
The compiler differentiates between the two sets of comment
delim.iters, so you can nest comments •. You can use one set of
delimiters for regular comments in your program, and use the other
set of delimiters to comment out sections of code for debugging or
development, as shown in the following program fragment.

1-6
Pascal/MT+'Reference Manual 1.3 Comments

PROCEDURE WALKTREE (TREE TREEPT);


BEGIN
WITH TREE'" DO
BEGIN
WALKTREE (LEFTREE); {PRE-ORDER WALK OF TREE}
WRITELN (INFO.NAME);
(* **** REMOVE THIS LINE FOR DIAGNOS"TICS
WRITELN ('**** IN WALKTREE ****');
IF MARKED(NODE) THEN { LOOK FOR LOOPS IN TREE}
BEGIN
WRITELN (' LINK ERROR IN TREE');
TREE DUMP (TREE) { WILL NOT RETURN
END
ELSE
MARK (NODE); { TREE OK SO FAR}
****** REMOVE THIS LINE FOR DIAGNOSTICS *)
WALKTREE (RIGHTREE)
END
END;

Listing 1-4. Ezallple Prograll with Comaents

End of Section 1

1-7
Section 2
Identifiers and Constants

This section describes Pascal/MT+ identifiers, and the rules


for forming literal constants. It also describes how to define
named constants.

2.1 Identifiers
A Pascal/MT+ identifier can represent a variable,· a type, a
constant, a procedure or function, or an entire program. The same
rules apply to all Pascal/MT+ identifiers, regardless of what kind
of objects they represent.
A Pascal/MT+ identifier can be any length, as long as it fits
on one line. However, the compiler uses only the first eight
characters to distinguish one identifier from another. Only the
first seven characters are significant in external identifiers.
Identifiers can contain,any combination of letters, digits, and
underscores. They must begin with a letter, and they cannot contail'l
any blank spaces. The compiler ignores underscores and typecase.
For example,

is the same as
abc
You can also use an @ as the first character in an identifier#
as long as you do not use the @ compiler option. You cannot use the
@ inside an identifier. The .compiler allows the @character, so you
can access the run-time routines whos~ name begin~ with @.
However, if you use the @ compiler option, then the compiler
interprets the @character as the standard pointer character, A, and
does not allow the @ as part of an identifier.
The followin9 are examples of valid Pascal/MT+ identifiers:
X
@CPMRD
file name
LA225prefix
Thisfile
Thisfile_for~91803_zip-only

The last two examples are indistinguishable to the compiler.,

2-1
Pascal/MT+ Reference Manual 2.1 Identifiers

The following are examples of invalid identifiers:

X!2 Contains an illegal character


l23x Begins with a digit
program Reserved word
STY@HM @ not first character
X 22 Contains a blank space

You cannot use reserved words, such as BEGIN and IF, as


identifiers. However, you can use predefined identifiers such as
WRITELN and BOOLEAN, to name any object in your program. Predefined
identifiers are defined one level above the global level in your
program, so changing the definition of a predefined identifier makes
the old object inaccessible from wi thin the scope of the new
definition.
Appendix A lists the Pascal/MT+ reserved words and predefined
identifiers. The Pascal MT+ Language Programmer's Guide for your
implementation contains the list of the run-time entry-point names,
as well as information about external identifiers.
Note: if you inadvertently use a run-time entry-point name as an
external identifier, your program might not link properly.

2.2 Constants
You can express a constant as a literal value, or you can give
the constant a name and then use the name anywhere you need that
value. Pascal/MT+constants can be str ings, integers, real numbers,
or scalar types.

2.2.1 No.eric Literals


A numeric literal can be a decimal integer, a hexadecimal
integer, a long integer, or a real number. The form of the constant
determines its type.
Bote: long integers are not .available with the 8-bit versions of
pascal/MT+"
An integer literal is.any whole number in the range -32768 to
32767. An integer literal cannot have a decimal point or any
canmas. To write an integer in hexadecimal, start it with a $. The
following are examples of valid integer literals:
-3456
$FFOO
32767
$EFFF

2-2
Pascal/MT+ Reference Manual 2.2 Constants

A long-integer constant 'must start with a pound sign, I. For


negative numbers, put the minus sign before the I. The following
are examples of long-integer literals:
'6234343
'0
-1678988

A real-number literal can 'be either in fixed- or floating-point


format. In fixed-point format, at least one digit must proceed and
follow the decimal point. The form for a floating-point literal is
a number with or without a decimal point, followed'by an E, fOllowed
by an optionally signed integer. Neither format can contain any
blanks or commas. .The following are examples of valid real-number
literals: '
64.78E-13
-65.3
-33.677E+lO

In floating-point format, the E is interpreted as "times 10 to


, the power of." For example,
6.3E5

is 6.3 times ten to the power of five (10 5), or 630000.

2.2.2 String Literals


A str ing literal can' contain any number of printable
charac~ers, as long as the string fits on one line. You write a
string'literal by enclosing it in single apostrophes. Everything
between the apostrophes, including blanks, is part of the string.
Use two single apostrophes to represent one single apostrophe inside
a str ing. Ins ide str ings upper- and lower-case letters are
distinct. The following are examples of valid string literals:
'*** INVALID EDIT COMMAND ***'
'Steve"s Program'
If you need to define a string that is longer than you can fit
on one line, or if you need to put control characters in a string,
use the string functions described in Section 6.

2-3
Pascal/MT+ Reference Manual 2.2 Constants

2.2.3 R..ad Constants


A constant definition defines 'an identifier as a synonym for a
constant value. You can use a named constant anywhere that you can
use a li teral. The following is an example <:>f a constant definition
section:
CONST
message 'VERSION 3.3';
size 100;
limit -size;
esc =' $lB;
conv fact 3.27E-3;
null=str = " ;
Notice that Pascal/MT+ allows the null string.

End of Section 2

~-4
Section 3
Variables and Data Types

This section describes the data types supported by


Pascal/MT+. There are two general categor ies of data types: simple
and structured. Simple data types, also called scalar types, have
only one element per data item. Integers, characters, and pointers
are examples of simple types.
Structurea types contain more than one element within a data
item. Records, str ings, and arrays are examples of str.uctured
types.
This section does not discuss files; see Section 7 for
information about files.

3.1 'rype Definition

The compiler uses a type definition to determine how to


allocate space for a variable. .The type definition section of a
block associates names with specific type definitions, as in the
following example:

TYPE
NUMBERS = ARRAY [1 •• 10} OF INTEGER~
STRPT ='" STR ING ;
LETTER I AI •• I ZI ;

3G2 Variable Declaration


A variable declaration establishes the type of a variable,
and determines its scope. You must declare all variables before you
can use them in a program. The following is an example of a
variable declaration section in a block.

VAR
X, Y, Z INTEGER;
NAMES LIST;
NUMl Oeo200;
NUM2 0.e200;

Notice in the example above how you can group more than one
name w.ith a particular type definition, and that you can use an
explicit type definition instead of just a type name.
If the compiler is using strong type checking, you must
declare variables with the same type name if you want the variables
to be compatible. Strong type checking requires that compatible

3-1
Pascal/MT+ Reference Manual 3.2 Var iable Dec la ration

var iables have exactly the same type, not just the same internal
structure. In the above example, NUMl and NUM2 are not compatible
under strong type checking. To make them compatible, you could use
the declaration,
NUMl,NUM2 : O•• 200;

See the programmer's guide for more information about how the
compiler performs type checking.

Pascal/MT+ supports absolute variables. That is, you can


force a variable to be stored at a specific location using an
absolute variable declaration. See the Programmer's, Guide for
details.
Pascal/MT+ also suppor ts external var iables. That is, you
can declare var iables in one .module and reference them in other
modules.

3.3 Simple Types


Pascal/MT+ has several predefined simple data types,
summar ized in Table 3-1. All of the Simple da ta types, except the
re als, are ord ina 1 types. An ord ina I type is one in wh ich each
possible value is countable with integers. The ASCII character set
is an example of an ordinal type.

You can define your own enumerated or subrange data types.


An enumerated type is an ordinal type whose complete set of values
you explicitly specify. A subrange type is a contiguous portion of
some other ordinal type.

Table 3-1. Predefined Data Types

Data type I Size I Range

CHAR 1 8-bit-byte a to 2·55


BOOLEAN 1 8-bit-byte true or false
INTEGER 2 8-bit-bytes -32768 to 32767
LONGINT 4 8-bit-bytes 2 32 _1 to 2 -32
BYTE 1 8-bit-byte 0 to 255
WORD 2 8-bit-bytes 0 to 65535

BCD REAL 10 8-bit-bytes see Prog ramme r' s


FLOATING REAL 8 8'- bit - by te s Guide

Pascal/MT+ provides four "pseudo-functions" or type


conversion operators to convert from one simple type to another.
These pseudo-functions do not generate any code, but simply direct
the compiler to treat the following 8- or l6-bit item as a different
type. The four pseudo-functions are

3-2
Pascal/MT+ Reference Manual 3.3 Simple Types

• CHR(x) returns the character whose ASCII value is the specifi~d


expression.
• ORO (x) returns the ordinal value of the expression. The
ordinal value of a character is its ASCII numeric
representation.
• OOO(x) returns the BOOLEAN value TRUE if the expression is odd,
otherwise it returns the BOOLEAN value FALSE.
• WORD (x) directs the compiler to treat the specified e'xpression
as a native machine word.

3.3.1 BOOLEAN
The BOOLEAN type has two values: TRUE and FALSE. The ordinal
value of FALSE is 0, and the ordinal value of TRUE is 1.
A BOOLEAN variable uses one byte, even in a packed structure
(see Section 3.4). Within the byte, only the least-significant bit
matters in determining the value. If the bit is set, the value of
the variable is TRUE, if not, the value is FALSE. However, logical
operations use the whole byte.

3.3.2 CHAR
Variables of type CHAR use one byte. The internal
representation of a character is the ASCII value of the character.
The range for CHAR variables is CH~(O) to CHR(255).
To express a CHAR value in a program, enclose the character in
single apostrophes if it is a print'able character, or use the CHR
pseudo-function. Use two single apostrophes to represent the single
apostrophe character.
The following example program demonstrates the CHR and ORO
pseudo-functions.

PROGRAM CHR_ORO;
VAR
I, J INTEGER;
C, 0 CHARi
BELL CHAR;
BEGIN
I : = 7;
C := '8';
o := CHR(I + ORD('O'»; (* ASCII VALUE OF '0' IS 48*)
J : = ORO (C) - oRo ( , 0 ' );
BELL := CHR(7)
END.

3-3
Pascal/MT+ Reference Manual 3.3 Simple Types

3.3.3 IftBGBR and LORGIft

INTEGER variables are 2 bytes long. Integers can range from -


32768 to +32767. An integer literal iri the range 0 to 255 takes up
only one byte in the code.
LONGINT var iables are 4 bytes long. The range for long
integers is 2- 32 to 2 32 _1. You can write a LONGINT literal only in
decimal; write it like a regular integer literal, but start the
number with the t character. For example,
#6234343
You can define LONGINT subranges, but you cannot use them as indexes
for arrays.
There are three functions for converting between the LONGINT
and other data types:
FUNCTION SHORT(L: LONGINT): INTEGER 1
FUNCTION LONG (S: SHORT ): LONGINTi
FUNCTION XLONG(Sr SHORT ): LONGINT1
A short data type is any 8- or 16-bit type, such as CHAR,
BOOLEAN, INTEGER, or WORD. The function LONG pads the short value
with zeros. The function XLONG sign-extends the short value into
the high-order word.
See your programmer's guide for specific information about the
internal representation of the INTEGER and LONGINT data types.
Rote: the LONGINT type is not available in the 8-bit versions of
Pascal/MT+.

3.3.4 REAL

Pascal/MT+ handles real numbers in two ways to support


different applications:
• BCD for business applications
• Binary floating· point fors·cientific and engineering
. applications.
A command-line option tells the compiler which format to use.
The internal representation and range of real numbers depends
on the processor. See your programDier' s guide for details about the
internal representation of real numbers.

3-4
Pascal/MT+ Reference Manual 3.3 Simple Types

The following are examples of real-number literals, as


explained in Section 2.
2l2.3E-l6
-22.454
2.0E+4·

3.3.5 BYTE and lIORD


The BYTE data type uses a single byte. It is compatible in
expressions and assignment statements with the CHAR and INTEGER
types. BYTE accepts any bit pattern and is useful for handling·
control characters, and performing character arithmetic.
The WORD data type uses a native machine word, except in the 8-
bit implementation where it uses two bytes. All arithmetic and
comparison operations on WORD expressions are unsigned, whereas
operations using INTEGER are signed.

3.3.6 User-defined Ordinal Types


You can define two kinds of ordinal types: enumer:ited types
and subranges.
An en~merated type is one in which you explicitly list each
va·lue in the type. The names for the values must be valid
Pascal/MT+ identif iers. The following example shows some type
definitions for enumerated types.
TYPE
COLOR = (RED, YELLOW, BLUE, GREEN, ORANGE);
SCORE (LOST, TIED, WON);
SKILL = (BEGINNER, NOVICE, ADVANCED, EXPERT, WIZARD);

3-5
Pascal/MT+ Reference Manual 3.3 Simple Types

The ordinal value of an enumerated-type constant is the same as


its position in the type definition. The first constant has an
ordinal value of O. In the example above, YELLOW has an ordinal
value of 1, and EXPERT has an ordinal value of 3.
A subrange is a set of values ranging between two specified
values of some previously defined ordinal type. The following are
examples of subrange definitions.
TYPE
GOOD ADVANCED •• WIZARD;
PRIMARY RED .. BLUE;
NUMERAL '0' •• '9';
INDEX 1 .• 100 ~
Both bounds in a subrange definition must be either literals or
named constants of the same ordinal type. The left constant must
have an ordinal value less than that of the right constant.

3.3.7 Pointers
A po inter is a var iable whose value is the address of a
dynamically allocated variable of some specific type. To define a
pointer type, use the pointer character, A, followed by a type name,
as in the following examples.
TYPE
INTPT "INTEGER~
LINK "TREE NODE;
NAMEPTR "STRING;
You can assign the value NIL to any type pointer to represent a
null pointer.
To reference the object whose address a pointer contains,
follow the pointer's name with the" character, as in the following
examples.
NEWREC := NEXT";
NAME" := 'ALPHA FIVE';
EMPLOYEE".AGE := 32;
If the compiler is using strong type checking, two pointers
must be of the .same type to be compatible. When the compiler is
using weak type checking, all pointer types are compatible, allowing
you to treat the same ·object as more than one data type.

Note: if you use the @ compiler command-line option, the compiler


accepts the cha~acter @ as a substitute for the" character.

3-6
Pascal/MT+ Reference Manual 3.4 Structured Types

3.4 Structured Types


Structured types are a composite of other types. A simple-type
variable only has one value, whereas a structure-type variable can
be a collection of values of different types. Arrays, records,
sets, and files are the major kinds of structured types. Section 7
discusses filetypes.
When determining the internal layout of a structured type, the
compiler sometimes leaves gaps between elements, putting the
elements at word boundaries to speed up access. If you want to
sacrifice speed for space, you can use the reserved word PACKED. In
the context of a structure type definition, the word PAC~ED causes
the compiler to eliminate any ~~sted space.

3.4.1 Arrays
An array is a collection of a fixed number of elements of the
same type. Arrays can have any type element, including other
structured types. An array type definition has the general format:
ARRAY [<index type> {,<index type>}] OF <element type>
The <index type> can be arq subrange type except LONGINT. You
can either use the name for a subrange type, or specify the bounds
explicitly_ For the <element type>, you can either use a type name,
or define the type right in the array definition. The following are
examples of array type definitions.
TYPE
LIST = ARRAY [FIRST •• LAST] OF STRING;
GRIDl = ARRAY [1 •• 20] OF ARRAY [1 •• 20] OF INTEGER;
GRID2 = ARRAY [1 •• 20, 1 •• 20] OF INTEGER;
TABLE PACKED ARRAY. [INDEX] OF PERPT;
Note that the definitions for GRIDl and GRID2 are functionally
identical.
You can use the reserved word PACKED in an array definition of
the form:
PACKED ARRAY [1 •• n] OF CHAR:
In this context, the word PACKED causes the compiler to treat
the array as a static string_
When accessing an array, the array's name by itself represents
the entire array: the name followed by an index references an
individual element in the array, as in the following.example.

3-7
Pascal/MT+ Reference Manual 3.4 Structured Types

PROCEDURE WORTHLESS:
CONST
FIRST =
LAST
TYPE
LIST = ARRAY [1 •• 20] OF STRING;
VAR
I : INTEGER;
NAMESA :'--LIST;
NAMESB : LIST:
BEGIN
FOR I := FIRST TO LAST DO
NAMEsA [ I] : = ' ';
NAMESB : = NAMESA
END;

3.4.2 Strings
The predefined type STRING is like a packed array of characters
in which byte 0 contains the dynamic length of the string and bytes
I through n contain the characters. When you declare a string, the
compiler allocates a predetermined number "of bytes for the string.
The default'length is 80, but you can specify from I to 255 bytes.
The dynamic length is the length of the string actually in use, not
the total available space. To specify the maximum length of a
string, put the length in square brackets, as in the following
example: .

VAR
TITLE· STRING [16]
LINE STRING;
LONGLINE STRING [255] ;
You can assign a string of any length to a string variable.
You can also assign a CHAR value to a str ing. The length byte o'f
the string variable reflects the new dynamic length, and the extra
bytes are undefined. However, if the assigned str ing is longer than
the maximum length of the string variable, errors can occur.
Assigning individual characters to a string does not change the
declared ).ength.
To access individual characters in a string, you index the
string like an array.
The predefined function LENGTH returns the dynamic length of a
string. Section 6 descr'ibes several other predefined string
rou.tines.
Pascal/MT+ Reference Manual 3.4 Structured Types

Pascal/MT+ supports static str ings, which have a preset,


static length. To declare a static string, define it as:

PACKED ARRAY [l •• n] OF CHAR


where n is an integer constant in the range 1 to 255.
Keep in mind the following points about static strings:
• You can ass ign a str ing lite ral to a sta tic str ing if the
string literal is exactly the same length as the static string.

• You can compare static strings to string literals of exactly


the same length.
• You can write static str ings to TEXT files using the' WRITE and
WRITELN procedures.
Pascal/MT+ stores str ing literals as dynamic str ing's, and the
string routines work only with dynamic strings.

3.4.3 Sets
A set is a structured type that contains elements of the same
base type. Unlike arrays or records, in which each element has a
value, the elemen ts of a se t are only sign ifican t in their presence
or absence from the set. Each element in a set has a corresponding
bit. If an' element is in a set, its bit is set, if the element is
not in the set,' its bit is O. .

Set opera tions are the standa rd rna thema tical opera t:Lons lik e
union, intersection, and difference. Section 4 describeG the set
opefators and expressions.
A set type definition has the general form:
SET OF <base type>

In Pascal/MT+, the <base type> can be any ord inal type. The
ordinal value of the upper and lower bounds of the base tyt:e must be
in the range a to 255. A se t-type var iable always takes up 32
bytes.
Listing 3-1 is an example program that uses sets e

3-9
Pascal/MT+ Reference Manual 3.4 Structured Types

PROGRAM USE_SETS;
VAR
LOWER, UPPER : SET OF CHAR;
DIGIT, DELIMIT : SET OF CHAR;
I, NUMLETS, NUMDIGS : INTEGER;
LINE STRING;
BEGIN
LOWER : = [' a ' • • ' z ' ] i
UPPER : = [' A' •• ' Z ' ] ;
DIGIT : = [' 0 ' •• ' 9' ] ; , , , , 'i', ':', '1',
DEL IMIT : = [" , •' , '?',];
NUMLETS := OJ
NUMDIGS :=-0;
READLN (LINE) j
FOR I := 1 TO LENGTH(LINE) DO
IF LINE[I] IN (LOWER + UPPER) THEN
BEGIN
NUMLETS := NUMLETS +.1;
IF LINE[I] IN LOWER THEN (* MAKE UPPERCASE *)
LINE[I] := CHR(ORD(LINE[I]) - 32)
END
ELSE
IF LINE[I] IN DIGIT THEN
NUMDIGS := NUMDIGS +1 .
ELSE
IF LINE[I] IN PELIMIT THEN
LINE [ I ] : = '*'
END.

Listing 3-1. Prograa Using Sets

3.4.4 Records
A record is a collection of distinct elements called fields,
each of which" can be of any type. Records are useful for describing
logically related data items that are of different types.
Pascal/MT+ records can either be variant, or nonvariant. Any
two nonvariant records of a particular type always have the same
internal structure whereas variant records can vary in internal
structure.
The type definition for a nonvariant record has the general
form:
RECORD
<field list> <field type> {i
<field list> <field type> }
END 1

3-10
Pascal/MT+ Reference Manual 3.4 Structured Types

The <field list> consists of one or more identifiers separated by


commas. Within any given record, each field name must be a unique
identifer. Outside ,the record, the field names can be used for
different identifers. Therefore, two different record types can
have identical field names.
The following is an exaniple of a nonvariant record definition:
TYPE
PART = RECORD
NAME, SOURCE STRING[lO];
ID NUMBER INTEGER;
PRICE REAL
END;
VAR
PARTLIST ARRAY [NUMPARTS] OF PART;
NEWPART PART;
Notice that the field definitions have the same format as variable
declarations.
You can reference each element in record by its fiel1 name
using the following form:
<record name>e<field name>
where the dot operator connects the record name and field name. For
example,
NEWPART.PRICE := 29.95;
WRITELN{PARTLIST[I] .NAME);
A variant record is a record whose internal structure varies
depending on how you use the record. That is, you can have two or
more records of the same type that have different types of fields.
The variant part of the record's definition acts like a CASE
statement (see Section 5.2) because each option in the defini tion is
labeled with one or more values, and the only option whose label
matches the value of a selector is used. .
The variant part of·a record must follow the nonvariant part,
and a record can have only one variant part. However, a field
within the variant can also be a variant record, so it is possible
to nest variants. .
The type definition for a variant record has the general form:
RECORD
{<field namelist>: <field type>;}
CASE <case selector> OF .
<case label ~{st> : «field list»
<case label list> ~«field list»
where the <field name list> is identical in form. to the listo£
fields in a record defirtition ~nd can have a·varlant part~ If a
3':"11
Pascal/MT+ Reference Manual 3.4 Structured Types

field has a variant part, it must be the last field in the list. To
indicate that a variant has no fields, use an empty parentheses
pair.
The <case selector> is either a <tag field> or simply a type
name. In either case, the type must be some previously defined
simple (scalar") type. The case labels are constants of the type of
the selector. If there are more than one, separate them with
commas.
If the <case selector> is a <tag field>, it has the form:
<field name> : <type name>
and is one of the regular fields in the record. The field list, or
variant with the correct case label, is selected depending on the
value of the <tag field>.
The following example shows a variant record definition:

RECORD
NAME RECORD
FIRST STRING [15] ;
MID CHAR;
LAST ". STRING [15]
END;
AGE, BIRTH : INTEGER;
SEX : CHAR;
CASE EMPLOYED : BOOLEAN OF (* START OF VARIANT PART *)
FALSE ();
TRUE (SALARY: REAL;
CASE EMP BY : EMP TYPE OF
SELF :-(YEARS :-INT~GER);
GOV, BUSI : {TITLE: STRING"[12];
NUMYRS : INTEGER
END;

Both the main variant and the nested variant in the preceding
example have a field that controls which variant applies. It is
also possible to use a type name "to control the variant, as in the
following example. This kind of variant is called a free variant.

RECORD
CASE INTEGER OF
1 (A, B, C, 0 CHAR) ;
2 (X, Y INTEGER);
3 : (Z LONGINT)
END;

3-12
Pascal/MT+ Reference Manual 3.4 Str uc tured Types

Every field name in a record must be distinct, even if the


fields are in different variants. Surround each variant with
parentheses; if there are no fields in the variant for a given
label, use empty parentheses, ( ).

End of Section 3

3-13
Pascal/MT+ Reference Manual 4 Operators and Precedence

~ab1e 4-1. (continued)


Operator I Operation I Operand I Result I Precedence
Relational
= equality scalar,string
set, pointer
record boolean lowest
<> inequality scalar,string
set, pointer
record boolean lowest
< less than scalar or
> greater than string boolean lowest
<= less or equal - scalar or
string boolean lowest
or
set inclusion set boolean lowest
>= greater or scalar or
equal string boolean lowest
or
set inclusion (see 404) boolean lowest
IN set membership (see 4.4) boolean lowest
Boolean
NOT riegation boolean boolean highest
OR disjunction boolean bool"ean 3rd highest
AND conjunction boolean boolean 2nd highest
Logical
- ? one's comple- integers and same as
or \ mentof operand " pointers operand highest
1 or logical OR integers and same as
I pointers
. operand 3rd highest
logical AND integers and same as
" pointers operand 2nd highest
Set
+ union set set 3rd highest
- set difference set set 3rd highest

* intersection set set 3rd highest

4-2
Section 4
Operators and Expressions

Pascal/MT+ provides a large assortment of operators for


building expressions in several general categories. Table 4-1
briefly describes each of the operators.
Pascal/MT+ evaluates every expression to result in a value of
some specific type. The type of the result depends on the,operator
and the kind of operands in the expression.
The simplest expression is a single operand, which can be a
cons tan t, var i able, function call, or sub-expression. In an
expression with more than one operator, the precedence of the
operators determines how Pascal/MT+ evaluates the expression. If
two or more operators have the same precedence, they are evaluated
from left to right unless you use parentheses to overr ide the normal
order of evaluation. For example,
4 - 3 + I =2 whereas 4 - (3 + 1) =0

Table 4-1. Su.mary of Pascal/MT+ Operators


Operator
I Operation
IArithmetic
Operands
I Result I Precedence
+ unary identity integer or same as 3rd highest
real .operand
+ addition, integer,real same as 3rd highest
o.r pointer operand
- unary sign integer or same as ·3rd highest
inversion real operand
- . subtraction, integer or same as 3rd highest
real operand

* multiplication integer or integer 2nd highest


real
div integer integer integer 2nd highest
division
/ real integer or
division real real 2nd highest
mod modulus integer integer 2nd highest

4-1
Pascal/MT+ Reference Manual 4 Operators and Precedence

Table 4-1. (continued)


Operator
I Operation
I Relational
Operand
I Result 1 Precedence

= equality scalar,string
set, pointer
record boolean lowest
<> inequality scalar,string
set, pointer
record boolean lowest
< less than scalar or
> greater than string boolean lowest
<= less or equal scalar or
,string boolean lowest
or
set inclusion set boolean lowest
>= greater or scalar or
equal string boolean lowest
or
set inclusion (see 4.4) boolean lowest
-
IN set membership (see 4.4) boolean lowest
Boolean
NOT negation boolean boolean highest
OR disju~ction boolean boolean . 3rd highest
AND conjunction 'boolean boolean 2nd highest
Logical
- ? one's comple- integers and same as
or \ ment of operand' pointers operand highest
1 or logical OR integers and same as
I pointers operand 3rd highest
..
& logical AND integers and same as
pointers operand 2nd highest
Set
+ union set set 3rd highest
- set -difference set set 3rd highest

* intersection set set 3rd highest

4-2
Pascal/MT+ Reference Manual 4.1 Arithmetic Expressions

4.1 Arithaetic Expressions


Pascal/MT+ has operators for addi tion, subtraction,
multiplication, and division. There is no operator for
exponentiation.
The arithmetic operators work with integers and reals, and
you can mix integers with reals. If both operands are integers, the
result is an integer, except with division. Otherwise, the result
is a real. A long integer mixed with a regular integer produces a
long integer. In an expression, the compiler treats an integer
subrange typ~ like an integer.
Be careful wi th multiplying large numbers, particularly
integers. The results of overflows are unpredictable.
The real-numbe~ division operator, I, always produces a real-
number result. For integer division, use the DIV and MOD operators.
DIV gives the integer quotient, and MOD gives the remainder. For
example,

6 I 3 = 2.0 (* REAL RESULT *)


6 DIV 3 = 2 (* INTEGER RESULT *)
44 DIV 7 6
44 MOD 7 = 2
-3 MOD 2 = -1
OIV and MOD work with regular and long integers.

4.2 Boolean Expressions


Boolean expressions have either the Boolean value TRUE or
FALSE. Two kinds of operators form Boolean expt:essions:

• Relational operators produce Boolean resul ts, but take operands


of many different types •
• Boolean operators work only with Boolean operands.

The relational operators for equality and inequ~lity work


with any type except files. The operators that test fOr ordering
only work wi th simple types and 'str ings. Some relational operators
also have special meanings in the context of set expressions, whidh
are destribed in Section 4.• 4.
All the relational operators have the same meaning that they
do in standard algebraic equations. When testing structures for
equality, both structures must have identical contents to be equal.

4-3
Pascal/MT+ Reference Manual 4.2 Boolean Expressions

Leading and trailing blanks are significant. For example,


'THIS , <> 'THIS' and 'XXZZY' <>' XXZZY'
When testing strings for ordering, the evaluator checks
character by character, from left to right until it either reaches
the end of a string or finds two characters that do not match. Th~
ordering is based on the ASCII values of the characters. For
example,
, AAAB' > ' AAAAAAAAA '

The ordering for enumerated types is based on the ordinal


values of the items. For example,
FALSE < TRUE
'c' > 'C'
Remember that relational operators have the lowest precedence.
You often have to use parentheses around relational expressions to
make them evaluate the way you want. Failure to do so is a common
cause of compilation errors. For example, the compiler interprecs
the expression
x < 3 OR X > 15

as
x < (3 OR X) > 15

which ,is an invalid expression. The proper way to wr i te the


expression is
(X < 3) OR (X > 15)

The Boolean operators AND, OR, and NOT have the same effect as
in standard Boolean algebra. Table 4-2 shows the results from
Boolean operations. T and F stand for TRUE and FALSE.

Table 4-2. Boolean Operations


A r
B I A AND B 'I A OR B I NOT A
T T T T F
T F F T F
F T F T T
F F F F T

4-4
Pascal/MT+ Reference Manual 4.3 Logical Expressions

4.3 Logical BxpressioDs

Logical expressions perform bitwise logical operations on


simple data items. Table 4-3 shows the three logical operators.

lfIabl.e 4- 3. Logical Operat:ors


Operator. I Use
& ' logical AND

(or I) logical OR
- ( or ? or \) one's comp lemen t NOT

The following example uses the logical operators to invert


four bits in a variable.
MIDBITS := -(FLAGS & $OOFO)i (* ISOLATE AND INVERT *)
FLAGS := FLAGS & $FFOF: (*-MASK OUT BITS *)
FLAGS := FLAGS! MIDBITS; (* PUT IN NEW FIELD *)

4.4 Set Expressions


There are two classes of operators for sets. One class of
operator forms relational expressions that produce Boolean' results.
The other class of operator forms expressions that build sets.

'1;'0 form valid expressions, the sets must be of compatible


types. Sets are of compatible types if either they are the same
type or if the base type~ for the sefs are assignment compatible, as
described in Section S.

The set constructor,

[<member list>]
spec ifies the values of a set. The <member list> can be any
combination of individual elements and closed intervalS, separated
by commas. The following examples demonstrate the set construe tor:

[ l, 3,' 5, 7 •• 20, 22", 34]


[1 •• 10, x •. y, i+j]
[89, 3, 54, 4 •• 13]
[] (* THIS IS THE EMPTY SET *)

4-S
Pascal/MT+ Reference Manual 4.4 Set Expressions

The members do not have to be in any order, and they do not


have to be constants. You can specify individual members and
intervals with variables or expressions. All of the members listed
must be in the declared range of values for the set, and the left-
hand bound of an interval must not be greater than the right-hand
bound.
There are three operato~s that build sets from other sets:
• The + operator produces the union of two setn.
• The * operator produces the intersection of two sets.
• The - operator produces a set equal to the set on the left,
minus all the elements that are in the set on the right.
The following examples demonstrate these set operators:

[RED, YELLOW, BLUE] * [RED, GREEN] = [RED]


[1 •• 20] + [3, 5, 11 •• 34] = [1 •• 34]
LETTERS := ['A' •• 'Z']i
CLOSED := ['A', 'B', '0', 'O' •• 'R ' ];
OPENED := LETTERS - CLOSED:

There- are five relational operators.that operate on sets:

• The IN operator tests for membership of an individual item in a


set. The item on the left must be of a compatible type with
the base type of the set •
. • The = operator tests for equali ty of two sets. Both sets must
have exactly the same members.
• The <> operator tests for inequality.
• The <= operator tests for inclusion of the set on the left in
the set on the right.
• The >= operator tests for inclusion of the set on the right in
the set on the left.

Listing 4-1 demonstrates several of the set operators.

4-6
Pascal/MT+ Reference Manual 4.4 Set Expressions

PROCEDURE CHECKLINE (ST STRING) ;

VAR
CH : CHAR;
I : INTEGER;
ALLOWED, FOUND : SET OF CHARi

BEGIN
ALLOWED : = [I A I •• ' Z " '0' •• ' 9', ' . ' , ' 'J;
FOUND := [];
FOR I := 1 TO LENGTH(ST) DO
FOUND := FOUND + [ST[I]];
IF FOUND = ALLOWED THEN
WRITELN ('ALL USED, NO EXTRAS')
ELSE
IF FOUND <= ALLOWED THEN
BEGIN
WRITELN ('NO EXTRA CHARACTERS IN STRING, BUT');
WRITELN ('THE FOLLOWING CHARACTERS ARE MISSING:');
FOR CH := CHR(32} TO CHR(126) DO
IF (CH IN ALLOWED) AND NOT (CH IN FOUND) THEN
WRITELN (CH)
END
ELSE
IF FOUND >= ALLOWED THEN
BEGIN
WRITELN ('ALL CHARACTERS USED, BUT SOME EXTRA:');
FOR CH := CHR(32) TO CHR(126} DO
IF (CH IN FOUND) AND NOT (CH IN ALLOWED) THEN
WRITELN (CH)
END
ELSE
WRITELN ('NOT EVEN .IN THE BALLPARK!')
END;

Listing 4-1. Set Expressions

End of Section 4

4-7
Section 5
Statements

This section describes the syntax for each of the Pascal/MT+


statements in alphabetical order. Anywhere in a .syntax description
that
<sta temen t>

appear s, you can use one of the sta temen ts descr ibed in th is
section, or you can use a procedure call or compound statemen t. A
compound statement is zero or more statements enclosed by a BEGIN
and an END.

5.1 ~be Assignment Statement


An assignment statement assigns a value to a variable. The
general form is

<variable> := <expression>

The assignment statement evaluates the expression on the


right and gives that value to the variable on the left. The
statement, does not change the value of the variable until it
evaluates the whole expression. If you use the same variable on
both sides of the assignment operator, the statement uses the old
value in the expression.

The expression assigned can be of any type. The left and


right sides of the assignment statement must be of the same type,
with the following exceptions:

• If the var iable is REAL the right can be an INTEGER or INTEGER


subrange expression.

• The variable's type can bea subrange of the expression as long


as the ass igned value is in the range of the variable.

• You can assign different set types if all members of the right
set can be members of the left set.

• You can assign expressions of type CHAR to variables of type


STRING or BYTE. .

• You cannot assign files or structures containing files.

5-1
Pascal/MT+ Reference Manual 5.1 Ass ignmen t Sta t~men t

Examples:

COUNT := COUNT + 1;

LETTER : = [' a ' •• ' z', 'A' •• ' Z, ] ;


LIST[I]A.VALUE := l6looo.o;

5.2 'fhe CASE State.ent

The CASE statement is a multiple-path branch. The general


form is

CASE <expression> OF
{ <constant> {, <constant>} <statement> ;}
END

or

CASE <expression> OF
{ <constant> {, <constant>} <statement> ;}
ELSE
<sta temen t>
END

The·CASE statement evaluates the <expression> and executes


the <statement> that is labeled with the matching value. If no
label matches, the <statement> after the ELSE executes. If there is
no match and there is no ELSE part, the program flow continues at
the next sta temen t after the CASE sta temen t.

The constants labeling the selectable statements must be ~e


same type as the expre ss ion, wh ich can be any ord ina 1 type. The
same value cannot label more than one path.

The CASE labels are different from decla·red labels: The


scope of a CASE label is confined to the body of th"e CASE sta temen t.
Note also that you cannot re ference CASE labels in a GOTO sta tement.

5-2
Pascal/MT+ Reference Manual 5.2 The CASE Statement

Examples:
CASE CH OF
I a I, I A' : WRITELN (' A' ) ;
'q', '0' : WRITELN ('0'); (* SEMICOLON OPTIONAL *)
ELSE
WRITELN ('NOT A OR 0')
END

CASE COMPARE(N[I], N[I+l]) OF


LESS ; (* DO NOTHING *)
SAME : DUPLICATES := DUPLICATES + 1;
GREATER
BEGIN
SWITCHED := SWITCHED + 1;
INTERCHANGE (N [I], N [1+1] )
END
END

5.3 The Empty Statement

A semicolon by itself is a valid Pascal/MT+ statement called


the empty" statement. However, if you misplace a semicolon, you can
end up with a program <that acts differently than you expect. For
example, in the following program fragment; the semicolon after the
reserved word DO causes an infinite loop. Because the semicolon is
misplaced, the only statement in the WHILE loop is the 'empty
statement, and the control variablanever changes.
WHILE LIST[I] <> ' 'DO; (* MISPLACED SEMICOLON *)
BEGIN
WRITELN (LIST[I]);
I := I + I
END;
The correct form is to omit the semicolon after DO. In general, it
is incorrect to put a semicolon before a BEGIN statement.

5.4 The FOR State.ant


The FOR statement repeats an action a specified number of
times. The general form is
FOR <control variable> := <expression> TO <expression> DO
<statement>
or
FOR <control var iable> .: = <.expression> DOWNTO <expression> 00
<statement>

5-3
Pascal/MT+ Reference Manual 5.4 The FOR Statement

The FOR statement assigns a succession of values to the


<control variable> and executes the statement body once for each
value of the var iable. In FOR TO statements, the value of the
<control variable> increments by one after each repetition.
In FOR DOWNTO statements, the value of the <control variable>
decrements by 'one after each repeti tion. Note that the value of the
<control variable> is undefined after the last repetition.
The expressions that control the FOR statement must be of the
same ord inal type as the <control var iable>. In the FOR TO
statement, if the first <expression> is greater than the second
<expression>, the statement body does not execute. The same thing.
happens in a FOR DOWNTO statement if the first <expression> is less
than the second.
The FOR statement evaluates both expressions and stores the
values before it executes the statement body. It evaluates the
first <expression> before it evaluates the second <expression>. If
the first <expression> contains a function reference that changes
the value of a variable in the second <expression>, the new value is
the one that applies. Evaluating the second <expression> has no
effect on the first <expression>.
The <control variable> must be a simple (scalar) variable: it
cannot be a pointer-referenced variable or an element of a
structure. The scope of the <control var iable> must be local to the
block containing the FOR statement, and its value must not change
inside the statement body.
Examples:
FOR CH := ' , TO 'z' DO
WRITELN (ORO (CH) : 3, , " CH)

FOR I := LENGTH (LINE) DOWNTO 1 DO


WRITE(LINE[I])

FOR X := LEFT TO RIGHT DO


FOR Y := BOTTOM TO TOP DO
IF GRID[X, Y] IN ['*', '+', I:'] THEN
BEGIN
STORELOC{X, Y):
CHECKPATTERN(X, Y)
END

5-4
Pascal/MT+ Reference Manual 5.5 The GOTO Sta temen t

5.5 'file GOTO State.ent

The GOTO statement transfers program control to a labeled


statement. The general form is

GOTO <label>

The label can be any positive integer literal of one to four


digits. You must declare the label in the label declaration section
of the block that includes both the GOTO sta temen t and the labeled
sta temen t.

The labeled sta temen t must be in the same block as the GOTO
statement or at a higher nesting level. The Pascal/MT+'run-time
system can transfer control out of ··routines and structures,
including deeply nested recursive routines, to any higher level that
meets the scope requirements for the label. However, transferring
control into procedures, functions, .or structured statements
produces unpredictable results.

Examples:

PROGRAM USE_GOTO;

LABEL
9999;

CONST
MAGIC WORD 'QU·IT'i

VAR
INP : STRING;

PROCEDURE BAILOUT (INST : STRING) r


BEGIN
IF INST <> MAGIC WORD THEN
WRITELN ( , NO, THAT" S NOT RIGHT I )

ELSE
GOTO 9999
END;

BEGIN
WHILE TRUE DO (* INFINITE LOOP *)
BEGIN
WRITELN (' WHAT IS .THE MAGIC WORD? I ) ;

READLN (INP) ;
BAILOUT (INP)
END;
9999
END.

5-5
Pascal/MT+ Reference Manual 5.6 The IF Statement

5.6 ~he IP State~t

The IF statement controls program flow based on the value of


a Boolean expression. The general form is
IF <Boolean expression> THEN
<S ta temen t>

or
IF <Boolean expression> THEN
<statemen t>
ELSE
<sta temen t>

If the <Boolean expression> is TRUE, the first statement


executes. If the <Boolean expression> is FALSE and there is an ELSE
part, the second statement executes. If the <Boolean expression> is
FALSE and there is no ELSE part, the program flow continues at the
nex t sta temen t.

In a sta temen t of the form,

IF <exp> THEN
IF <exp> THEN
<s ta temen t>
ELSE
<sta temen t>

the compiler assOciates the ELSE part with the closest IF.

5-6
Pascal/MT+ Reference Manual 5.6 The IF Statement

Examples:

IF HELP REQUEST THEN


BEGIN
HELP DISP;
GET LEVEL (LEV) ;
MESG DISP(LEV)
END -

IF SCORE < 60 THEN


GRAPE := 'F'
ELSE
IF SCORE < 70 THEN
GRADE : = '0 I
ELSE
IF SCORE < 80 THEN
GRADE := 'e'
ELSE
IF SCORE < 90 THEN
GRADE := 'B'
ELSE
GRADE : = 'A'

5•7 '!'he REPEAT S ta temen t

The -REPEAT statement executes a group of statements


repeate~ly until the exit condition is true. The general form is

REPEAT
<sta temen t> {;
<statement> }
UNTIL <Boolean expres~ion.>

The REPEAT statement executes the statement body before i t


evaluates the <Boolean expression> in the UNTIL part. I f the
<Boolean expression> is TRUE, the REPEAT statement is finished.
Note that i f the conftolling condition does not change in the
statement body, the statement loops indefinitely.

Notice that a BEGIN-END pair is not required around the


sta temen t body.

Examples:

REPEAT
READLN (INP) ; .
WRITELN (F, INP);
LINECNT : = LINECNT + 1
UNTIL INP =' I

5-7
Pascal/MT+ Reference Manual 5.8 The WHILE Statement

5.8 The WHILE State.ent

The WHILE statement repeatedly executes its statement body, as


long as the controlling condition is true. The general form is
WHILE <Boolean expression> DO
<statement>
The WHILE statement evaluates the <Boolean expression> before
it executes the statement body. If the <Boolean expression> is
intitially FALSE, the statement body does not execute. As long as
the <Boolean expression> is TRUE, the statement body executes.
Examples:
WHILE NOT EOF(FN) DO
BEGIN
READLN (FN, INP);
SCAN (INP)
END

WHILE (I < LENGTH(ST)) AND NOT FOUND DO


BEGIN
FOUND := ST[I] , . ' .,
I := I + 1
END

5.9 The WITH Statement

The WITH statement creates a context for referencing record


fields by their individual names. The general form is
WITH <record variabl~> {, <record variable>} DO
<statement>
Inside the statement body, you can reference any fi~ld of a
specified <record variable> by the field's name. For example, the
WITH statement,

WITH EMPLOYEE DO
BEGIN
NAME := 'John Doe';
AGE := 47;
TITLE := 'Programmer IV'
END

is equivalent to the three assignment statemerits,


EMPLOYEE. NAME := 'John Doe';
EMPLOYEEeAGE := 47;
EMPLOYEE. TITLE := 'Programmer IV';

5-8
Pascal/MT+ Reference Manual 5.9 The WITH Statement

~ WITH statement having more than one <record variable> is


equivalent to a series of nested WITH statements with one <record
variable> specified at each level. A <record variable> can be a
field in a previously specified ,record. For example, the single
WITH statement:
WITH Rl, R2, R3 DO
<statement>
is equivalent to:
WITH Rl DO
WITH R2 DO
WITH R3 DO
<statement>
If you specify more than one record, and if two records have a
field with the same name, the compiler associates the field name
with the innermost <record variable>.
Example:
PROGRAM SHOW_WITH;

TYPE
FULLNAME RECORD
FIRST, LAST STR~NG[15];
MIDDLE CHAR
END;
MEMBER RECORD
NAME FULLNAME;
JOINED STRING[8]i
ID INTEGER
END;

VAR
NEWMEM MEMBER;

BEGIN
WITH NEWMEM, NAME DO
BEGIN
FIRST := 'JOHN';
MIDDLE:= 'Q';
LAST := 'PUBLIC';
JOINED := '02/27/53';
ID := a
END
END.

End of Section 5

5-9
Section 6
Procedures and Functions

Pascal/MT+ is a block-structured, procedure-oriented language.


It contains all the necessary control structures you need to write
understandable, and maintainable code. The underlying concept of
any procedural language is designing the program as a series of
small, logically distinct units that are easy to code, debug, and
maintain.
Procedutesand functions are essential building blocks in a
structured programming language. A procedure is like a
parameter ized sta temen t, and a function is like a parameter ized
expression.
In Pascal/MT+, you call (invoke) a procedure by simply using
its name. Tha t is, a procedure call is the procedure name, followed
by the required parameters. A procedure call is like any valid
stat~ment. Anywhere that you can use a statement, you can use a
procedure call.
You can put a function reference anywhere that you can put an
expre ss ion. The funct ion reference is part of the process of
evaluating the expression. A function reference, like a procedure
call, is- just the flJnction name, followed by the required
parameters.
Pascal/MT+ functions and procedures can be recursive. They can
contain calls to themselves. They can also be mutlJally recursive.
Two procedures or functions can reference each. other.
Pascal/MT+also suppor ts a special type of procedure called an
interrupt procedure. See your programmer's guide for details.
In the rest of this section, the word procedtire refers to both
func t.ionsand procedures, unless the context makes it exclude
functions.

6-1
Pascal/MT+ Reference Manual 6.1 Procedure Definitions

6.1 Procedure Definitions


A procedure definition, like a program, has a heading followed
by a declaration section and a statement body. The following is an
example of a procedure definition.

PROCEDURE INTERCHANGE(VAR I, J INTEGER) ;


VAR
TEMP INTEGER;'
BEGIN
TEMP := I;
I : = J;
J := TEMP
END;
A function definition is like a procedure definition, with the
following additions:
• You must specify the data type for the function •
• At least once in the statement body, you'must have a special
assignment statement that returns the function value.
The data type for a function must be a simple or string typec
Put the type name after a colon at the end-of the function heading_
To specify the value that a function returns, use an assignment
statement with the function name on the left side.- You can put more
than. one of the special assignment statements in the function body,
in which case the last value assigned before the function returns
control is the value the function returns. The following is an
example of a function definition.

FUNCTION MIN (L, R : INTEGER) INTEGER;


BEGIN
IF L < R THEN
MIN := L
ELSE
MIN :=·R
END;

If you have to reference a procedure before its definition, use


a FORWARD declaration, that has the following form:
<procedure heading> : FORWARD ;
The definition of the procedure, later in the program, does not have
the parameter list in the heading. Listing 6-1 is an example of a
program wi:th a FORWARD declaration. The two functions are mutually
recursive •.

6-2
Pascal/MT+ Reference Manual 6.1 Procedure Definitions

PROGRAM RECURSE;
VAR
I : INTEGER;
FUNCTION G (X INTEGER) INTEGER; FORWARD;
FUNCTION F (X INTEGER) INTEGER;
BEGIN
IF X < 2 THEN
F := 1
ELSE
F := F(X-l) + G(X-2)
END;
FUNCTION G; (* NO PARAMETER LIST OR FUNCTION TYPE *)
BEGIN
IF X < 2 THEN
G := 1
ELSE
G := (X*X) + G(F(X-l) MOD X)
END;
BEGIN (* MAIN PROGRAM *)
FOR I := 1 TO 10 DO
WRITELN ('F(', I:2, ') = F (I) )
END.

Listing 6-1. FORWARD Declarations

6.2 Parameters
The parameters in the. procedure heading are called formal
parameters. The parameters in the procedure call are called actual
paraineters. There are two types of formal parameters in Pascal/MT+:
value and va~iable parameters. The difference between the two is
the way that the parameters are passed at run-time.
A value para~eter is like a local variable in the procedure~
During a proced~recall, th~ value of the actual parameter passes
into the procedure.. If you change the value of the formal parameter
ins ide the procedure body, it does not effect the value of the
actual parameter. In the procedure call, the: actual parameter can
be any expression whose type is compatible with the formal
parameter.
Changing a variable parameter inside a procedure body changes
the actual parameter. During a procedure call, the address of the
formal parameter, instead of its value, passes into the procedure.
The actual parameter in the procedure call must be a variable whose
type is compatible with the formal parameter. . A variable parameter
cannot be acon~tant or an element of a packed structure. A file
. par ametermust be a. variable parameter. .

6-3
Pascal/MT+ Reference Manual 6.2 Parameters

The following example demonstrates the difference between


variable and value parameters. Listing 6-2a shows the program and
Listing 6-2b shows the output from the program.

PROGRAM VALVAR~

VAR
XVAL, XVAR : INTEGER;
PROCEDURE MUDDLE (MVAL INTEGER~ VAR MVAR INTEGER) ;
BEGIN (* MUDDLE *)
MVAL := ll~
MVAR := 33;
WRITELN('IN MUDDLE AT END MVAL, ' " MVAR)
END~

BEGIN (* MAIN PROGRAM *)


XVAL := l~
XVAR := 2;
WRITELN('IN MAIN BEFORE CALL " XVAL, , " XVAR);
MUDDLE (XVAL, XVAR);
WRITELN('IN MAIN AFTER CALL , XVAL, , " XVAR)
END.

Listing 6-2a. Para.eter Passing Prograa

IN MAIN BEFORE CALL 1 2


IN MUDDLE AT END 11 33
IN MAIN AFTER CALL 1 33

Listing 6-2b. Output fro. VALVAR Prograa

To specify that a parameter is a variable parameter, place the


word VAR in the parameter declaration. The VAR applies to all of
the parameters grouped together with one type name. In the
following procedure heading,
PROCEDURE X (VAR I, J, K : INTEGER: M, N : INTEGER);
I, J; and K are all variable parameters,' and M and N are value
parameters.
Besides passing values and variables into procedures, you can
also pass procedures and functions. The declaratior.. for a
procedural parameter has the same form as a procedure headinge The
parameter names in the ·procedural parameter declaration have no
scope outside of the declaration. The formal name for the procedure
is the name' that the main procedure uses in the statement body ..

6-4
Pascal/MT+ Reference Manual . 6.2 Parameters

A procedure or function passed as a parameter can only have


value parameters and must be declared in the outermost block.
Listing 6-3 shows a program that uses procedures as parameters.

PROGRAM PASSPROC;

TYPE
REC RECORD
NAME, PHONE : STRING
END;
PTR "'REC;
.LST ARRAY [1 •• 10] OF PTR;

VAR
LIST : LST;
J : INTEGER;

PROCEDURE INIT (PT : PTR);


BEGIN
WRITELN('ENTER A NAME');
READLN(PT .... NAME) ;
WRITELN('PHONE NUMBER?');
READLN(PT .... NUMBER)
END;
PROCEDURE DISPLAY (P PTR) i
BEGIN
WRITELN(P .... NAME, , , , .p .... NUMBER)
END~

PROCEDURE WALKLIST (VAR LS LSTi PROCEDURE WORK(A:PTR»;


VAR
I : INTEGER;
BEGIN
FOR I := 1 TO 10 DO
WORK(LS[IJ) (* FORMAL PROCEDURAL PARAMETER *)
END;

BEGIN (* MAIN PROGRAM *)


FOR J := 1 TO 10 DO
NEW(LIST[J]}i
WALKLIST(LIST, INIT);
WALKLIST(LIST, DISPLAY)
END.

Listing 6-3. Procedural Paruaeters

6-5
Pascal/MT+ Reference Manual 6.3 Conformant Arrays

6.3 Confor.ant Arrays


You can define an array parameter for a procedure without
specifying the upper- or lower-bounds of the array. This lets you
pass different sized arrays to the same procedure. The arrays must
hav~ the same number of dimensions, the same element .type, and
compatible index types.
The declaration for a conformant array is like the declaration
for a static array parameter, except that it must be a VAR
parameter, and you do not specify the upper- and lower-b01:mds.
Instead, you supply var iables that hold the .values when the
procedure is called. A conformant array declaration has the
following form:
VAR <name> ARRAY [<low> •• <high>:<type>] OF <type>
Inside the procedure body, you can use the boundary variables to
control access to the array. Listing 6-4 is an example of a
procedure that has a conformant array.

6-6
Pascal/MT+ Reference Manual 6.3 Conformant Arrays

PROGRAM DEMOCOM:

VAR
Al : ARRAY [1 •• 10] OF INTEGER:
A2 : ARRAY [2 •• 20] OF INTEGER;

PROCEDURE DISPLAYIT
(VAR ARl : ARRAY [LOW •• HI : INTEGER] OF INTEGER);

(* THE DECLARATION ABOVE DEFINES THREE VARIABLES: *


* ARl THE PASSED ARRAY
*
* LOW LOWER BOUND OF AR1, PASSED AT RUN TIME
*
*
HI UPPER BOUND OF AR1, PASSED AT RUN TIME
*
*)
*
VAR
I INTEGER;

BEGIN (* DISPLAYIT *)
FOR I := LOW TO HI DO
WRITELN('INPUT ARRAY[', I, '] =', AR1[I])
END;

BEGIN (* MAIN PROGRAM *)


WRITELN('DISPLAYING UNINITIALIZED ARRAY Al');

D-ISPLAYIT(Al}; (* PASS Al EXPLICITLY, PASS


1 AND 10 IMPLICITLY' *)

WRITELN('DISPLAYING UNINITIALIZED ARRAY A2');

DISPLAYIT(A2) (* PASS A2 EXPLICITLY, PASS


2 AND 20· IMPLICITLY *)
END.

Listing 6-4. Confor.ant Array Example

6-7
pascal/MT+ Reference Manual 6.4 Functions and Procedures

6.4 Predefined Punctions and Procedures


This section describes the predefined functions and procedures
of Pascal/MT+. Table 6-1 summarizes these predefined routines.
Jiote:in the parameter lists' for the routines, NUM is an in teger or
real expression.

~able 6-1. Predefined Functions and Procedures

Ar'i thmetic Func tions


Function I ' Parameter List I Returns
FUNCTION ABS (NOM) REAL
FUNCTION ARCTAN (NUM) REAL
FUNCTION COS (NUM) REAL
FUNCTION EXP (NUM) REAL
FUNCTION LN (NUM) REAL
FUNCTION SIN (NUM) REAL
FUNCTION SQR (NUM) REAL
FUNCTION SQRT (NUM) REAL

Bit and byte manipulation. routines


Function I Parameter List I Returns
PROCEDURE CLRBIT (BAS IC_VAR, BIT_NUM)
FUNCTION HI (BASIC VAR) INTEGER
FUNCTION LO (BAS IC-VAR) INTEGER
PROCEDURE PACK (ARRAY-; INTEGER, ARRAY)
PROCEDURE SETBIT (BASIC VAR, BIT NOM)
FUNCTION SHL (BASIC-VAR, INTEGER) INTEGER
FUNCTION SHR (BAS IC-VAR, INTEGER) INTEGER
FUNCTION SWAP (BASIC-VAR ) INTEGER
FUNCTION TSTBIT (BASIC-VAR, BIT NOM) BOOLEAN
PROCEDURE UNPACK (ARRAY-; INTEGER~ ARRAY )

Byte and Character manipulation routines


Function I Parameter List
PROCEDURE FILLCHAR (DESTINAT~ON, LENGTH, CHARACTER)
PROCEDURE MOVE (SOURCE, DESTINATION, NUM BYTES)
PROCEDURE MOVELEFT (SOURCE, DESTINATION, NOM-BYTES)
PROCEDURE MOVE RIGHT (SOURCE, DESTINATION, NUM:SYTES)

6-8
Pascal/MT+ Reference Manual 6.4 Functions and' Procedures

Table 6-1. (continued)

Dynamic allocation routines


Function I Parameter List
PROCEDURE DISPOSE (POINTER, TAG, TAG, ... )
PROCEDURE NEW (POINTER, TAG, TAG, ... )

Input/Output routines
Function IParameter List
I "Returns
PROCEDURE ASSIGN (FILE, NAME)
PROCEDURE BLOCKREAD (FILE, BUF, lOR, NUMBYTES, RELBLK)
PROCEDURE BLOCKWRITE (FILE,BUF,IOR,NUMBYTES,RELBLN)
PROCEDURE CLOSE (FILE, RESULT)
PROCEDURE CLOSEDEL (FILE, RESULT)
FUNCTION EOF (FILE) BOOLEAN
FUNCTION EOLN (FILE) BOOLEAN
PROCEDURE GET (FILE)
FUNCTION GNB (FILE) CHAR
FUNCTION IORESULT INTEGER
PROCEDURE OPEN (FILE, TITLE, RESULT)
PROCEDURE OPENX (FILE, TITLE, RESULT, EXTENT)
PROCEDURE PAGE (FILE)
PROCEDURE PURGE (FILE)
PROCEDURE PUT (FILE)
PROCEDURE
PROCEDURE
READ
READHEX
" (FILE, VARIABLE, VARIABLE,
(FILE, VAR, SIZE) i
) · ..
PROCEDURE
PROCEDURE
READLN
RESET
(FILE, VARIABLE, VARIABLE,
(FILE)
) ·..
PROCEDURE REWRITE (FILE)
PROCEDURE SEEKREAD (FILE i RECORD NUMBER)
PROCEDURE SEEKWRITE (FILE, RECORD:NUMBER)
FUNCTION" WNB (FILE, CHAR) BOOLEAN
PROCEDURE WRITE (FILE, VARIABLE, VARIABLE, ) ....
PROCEDURE WRITEHEX (FILE, EXPRESSION, SIZE)
PROCEDURE
PROCEDURE
WRITELN "
LWRITEHEX.
(FILE, VAlUABLE, VARIABLE,
(FILE, EXPRESS ION, SI ZE ") *
) ·...
* does not apply to the 8080 implem~ntation

6-9
pascal/MT+ Reference Manual 6.4 Functions and Procedures

Table 6-1. (continued)

String handling routines


Function I Parameter List I Returns
FUNCTION CONCAT (SOURCE1, SOURCE2, ••• ,SOURCEn) STRING
FUNCTION COPY (SOURCE, LOCATION, NUM_BYTES) STRING
PROCEDURE DELETE (TARGET, INDEX, SIZE )
PROCEDURE INSERT (SOURCE, DESTINATION, INDEX)
FUNCTION LENGTH (STRING) INTEGER
FUNCTION POS (PATTERN , SOURCE) INTEGER

Transfer Functions
Function I Parameter List I Returns
FUNCTION CHR (INTEGER) CHAR
FUNCTION ODD (ORDINAL) BOOLEAN
FUNCTION ORD (ORDINAL) INTEGER
FUNCTION ROUND (NUM) INTEGER
FUNCTION TRUNC (NUM) INTEGER

Miscellaneous routines
Function I Parameter List I Returns
FUNCTION @BDOS (INTEGER, WORD) ** INTEGER
FUNCTION @BDOS86 (INTEGER, POINTER) * INTEGER
FUNCTION @CMD PTR_TO_STRING
PROCEDURE @ERR (INTEGER)
FUNCTION @HERR
PROCEDURE @HLT
FUNCTION @MRK INTEGER
FUNCTION. @RLS (INTEGER)
FUNCTION ADDR (VARIABLE REFERENCE) INTEGER
PROCEDURE CHAIN
PROCEDURE EXIT·
PROCEDURE INLINE (see Programmer's Guide)
FUNCTION MAXAVAIL. INTEGER
FUNCTION MEMAVAIL INTEGER
FUNCTION PRED (X) same type as X
FUNCTION RIM8S ** BYTE
FUNCTION SIZEOF (VARIABLE OR TYPE NAME) INTEGER
PROCEDURE SIM85 (VAL : BYTE) **
FUNCTION SUCC (X) same type as X
PROCEDURE WAIT (PORTNUM, MASK, POLARITY) **

* does not apply to the 8080 implementation


** does not apply to the 8086 implementation
Pascal/MT+ Reference Manual ABS Function

ASS Function

Syntax:
FUNCTION ABS(X)i

Explanation:
ABS returns the absolute value of X. X must be a real or
integer expression. The result has the same type as X.

Examples:

ABS(-5.789) 5.789
ABS(56) 56

6-11
Pascal/MT+ Reference Manual ADDR Function

AQDR Punction

Syntax:
FUNCTION ADDR(VARIABLE OR ROUTINE) POINTER:

Explanation:
ADDR returns the address of a var iable, function, or procedure.
Variable references can include subscripted variables and record
fields. ADDR does not work with constants, user-defined ordinal
types, or any item that does not take- code or data space:
You can reference externals, including those in over lays.
However, you must keep in mind the scope of th~ referenced item.
For example, you cannot use ADDR in the main program to find the
address of a variable you declare in a nested procedure.

Example:
PROCEDURE ADDR_DEMO(PARAM INTEGER);
VAR
REC RECORD
J : INTEGER;
BOOL : BOOLEAN;
END;
ADDRESS : INTEGER;
R : REAL;
Sl : ARRAY[l .• lO] OF CHAR;
P : . . INTEGER;
BEGIN
P := ADDR(ADDR DEMO);
P := ADDR(PARAM);
P := ADDR (REC) ;
P := ADDR(REC.J)i
END;

6-12
Pascal/MT+ Reference Manual ARCTAN Function

ARC'.rAR Function

Syntax:
FUNCTION ARCTAN(X);'

Explanation:
~ARCTAN returns the angle, expressed in radians, whose tangent
is X. X must be a real or integer expression. The result is real
number.

Example:
ARCTAN (1) o. (* THE ANGLE IS PI / 4 *)

6-13
Pascal/MT+ Reference Manual ASSIGN Function

MSIGl! Punction

Syntax:
PROCEDURE ASSIGN( FILE, NAME ),

Explanation:
ASSIGN attaches an external filename to a file variable before
using a RESET or REWRITE procedure. FILE is a filename7 NAME is a
literal or a variable string containing the name of the file to
create. FILE can be of any type, but must be of type TEXT to use~
the special device names listed in Table 6-2.
Pascal/MT+ implements the Pascal local file facility using
temporary filenames in the form
PASTMPxx.$$$
where xx is sequentially assigned, starting at zero, ~rom the
beginning of each program.
If an ASSIGN does not precede an external file REWRITE, a
. temporary filename attaches before creation. Locally declared files
cannot be used as temporary files unless you initialize the file
with ASSIGN«file>,").
The following table defines the device names supported in the
CP/M ~ run-time environment.

Table 6-2. Device Hames


Name I Definition
CON: As input, echoes input characters, CR as
CR/LF, and backspace [CHR(8}) as backspace,
space, backspace.
As output, echoes CR as CR/LF and CP/M expands
tabs to every 8 character positions. Line-feed
cannot be output.
KBD: CP/M console, input device only. No echo or
interpretation. Cannot be used with CON: input
or output.
TRM:· CP/M conso le, outpu t dev ice only. No
interpretation.
LST: CP/M printer, output device only. No
interpretation, including no tab expansion.

6-14
pascal/MT+ Reference Manual ASSIGN Function

~able 6-2. (continued)

Name I Definition

RDR: CP/M reader, input device only. Call auxiliary


input routine in the BIOS via the BOOS, using
Function 3. '

PUN: CP/M punch, output device only. Call auxiliary


output routine in the BIOS via the BOOS, using
Function 4.

Note that using CON: and KBD: together can create problems
because of the way they are implemen ted. To implemen t CTRL-S, CP/M
checks for typed characters when performing ·BDOS Function 2, wr iting
to CON:. If you type a character other than CTRL-S, CP/M stores it
internally, anticipating a subsequent call using Function 1.

Function 6, used by KBD:, goes directly to the BIOS for input,


ignoring any character in this internal buffer. Therefore, your
program might appear' to be losing characters when in fact CP/M is
stor ing them in'ternally.

EX~!!l£le!.!.

ASSIGN(CONIN,'CON: I);
ASSIGN(KEYBOARD,'KBD: ' );
ASSIGN(CRT,'TRM: ' );
ASSIGN(PRINTFILE,'LST: ' );

6-15
Pascal/MT+ Reference Manual BLOCKREAD, BLOCKWRITE Function

BLOCKRBAD, BLOCKWRI'rB Function

Syntax:
BLOCK READ (F:FILEVAR1 BUF:ANYJ VAR IOR:INTEGER1 SZ,RB:INTEGER)7
BLOCKWRITE(F:FILEVAR7 BUF:ANY7 VAR IOR:INTEGER7 SZ,RB:INTEGER):

Explanation:
These procedures enable direct disk access. FILEVAR is an
untyped file (FILE:). BUF is any array variable large enough to
hold the data. It can be indexed. lOR is an integer that receives
the returned value from the operating system. SZ is the number of
bytes to transfer. SZ is related to the size of BUFi it must be a
multiple of 128.
If BUF is 128 bytes, SZ must be 128. If BUF is 4096 bytes, SZ
can be as large as 4096. RB is the relative block number, which can
be in the range -1 to 32767. When RB is -1, the run-time routines
assume sequential block transfer. When RB is greater than -1, the
routine calculates the correct file location and opens new extents
as needed.
The data transfers either to or from your HUF variable for the
specified number of bytes.

6-16
Pascal/MT+ Reference Manual CHAIN Function

ClAIR Pupction

Syntax:
PROCEDURE CHAIN (FILE) 1

Explanation:
CHAIN allows you to chain from one program to another.
See Section 3.3 in the Pascal/MT+ Language Programmer's Guide
for more information.

6-17
Pascal/MT+ Reference Manual CHR Function

CDR PuQCtion

Syntax:
FUNCTION caR (X) CHAR:

Explanation:
caR returns.the character whose ASCII value is the integer X.

Examples:
WRITELN(CHR(7»: (* BEEP THE TERMINAL *)
IF C IN [·a· •• ·z'] THEN
C := CHR(ORD(C) - 32); (* CONVERT TO UPPERCASE *)

·6-18
Pascal/MT+ Reference Manual CLOSE Function

CLOSE Punction

Syntax:
PROCEDURE CLOSE FILE, RESULT ) ~
PROCEDURE CLOSEDEL FILE, RESULT )~

Explanation:
The CLOSE porocedure closes files. You must use it to guarantee
that data written to a file is purged from the buffer to th~ disk.
CLOSEDEL closes and deletes temporary files after use. FILE is
any filetype variable. RESULT is a VAR INTEGER parameter that has
the same value as IORESULT upon return from CLOSE •.
Files are implicitly closed when. an open file is RESET. The
number of files that can be open at a time is CPU-dependent. For
CP/M systems, this number is limited only by the amount of memory
available for File Control Blocks (FCBs).

6-19
Pascal/MT+ Reference Manual CONCAT Function

COICAZ luostioo

Syntax:
FUNCTION CONCAT( SOURCEl, SOURCE2, •••• , SOURCEn) STRING~

Explanation:
CONCAT returns a string in which all strings in the parameter
list are concatenated. The strings can be string variables, string
literals, or characters. You can concatenate a string of zero
length. The total length of all strings truncates at 256 bytes.
See the COpy function for restrictions when using both CONCAT and
COpy.

Example:
PROCEDURE CONCAT_DEMO;
VAR
Sl,S2 STRING;
BEGIN
Sl := 'left link, right linkf;
S2 := 'root roct root';
WRITELN(Sl,'/',S2) ;
Sl:= CONCAT(Sl,' ',S2,'!!!!!!');
WRITELN(Sl);
end;

Output:
left link, right link/root root root.
left link, right link root root root!!!!!!

6-20
Pascal/MT+ Reference Manual COpy Function

COPY Function

Syntax:
FUNCTION COPY( SOURCE, LOCATION, 'NUM_BYTES) STRING 1

Explanation:
COpy returns a string with the number of characters specified
in NUM BYTES from SOURCE, beginning at the index specified in
LOCATION. SOURCE must be a str ing. LOCATION and NUM_BYTES are
integer expressions. .
The COpy routine does not check whether LOCATION is out of
bounds or negative. Truncation occurs if NUM BYTES is negative or
NUM_BYTES plus LOCATION exceeds the length of the SOURCE.

Example:
PROCEDURE COPY_DEMO;
BEGIN
LONG STR := 'Hi from Cardiff-by-the-sea';
WRITELN(COPY(LONG STR,9,LENGTH(LONG STR)-9+1»;
END; - -

Output:
Cardiff-by-the-sea

. Hote:· COpy and CONCAT are str ing returning pseudo-functions and
have only one statically allocated buffer for the return value.
Therefore, if you use these functions more than once within the same
expression, the value of each occurrence becomes the value of the
last occurrence. For example,
CONCAT(A,STRING1) = CONCAT(A,STRING2)
is always true, because the concatenation of A and STRING2 ieplaces
that of A and STRINGI. As a further example,
WRITELN ( COpy (STRINGI, 1,4), COpy (S.TRINGI, 5,4) )
writes the second set of four characters in STRINGl twice.

6-21
Pascal/MT+ Reference Manual COS Function

cos Function

Syntax:
FUNCTION COS (X) REAL 1

Explanation:
COS returns the cosine of X. X, the angle in radians, must be
real or integer. The result is real.

Example:
IF COS(ANG) = SIN(ANG) THEN
WRITELN('4S DEGREES'):

6-22
Pascal/MT+ Reference Manual DELETE Function

DELETE Function

Syntax:
PROCEoqRE DELETE( TARGET, INDEX, SIZE) ~

Explanation:
DELETE removes SIZE characters from TARGET beginning at the
byte named in INDEX. TARGET is a string. INDEX ~nd SIZE are
integer expressions. No action occurs if SIZE is zero.

Note: serious errors result if SIZE is negative. The data and


surrounding memory can be destroyed if the INDEX plus the SIZE is
greater than the TARGET, or the TARGET is empty.

Example:
PROCEDURE DELETE_DEMO;
VAR
LONGSTR : STRING;
BEGIN -
LONG_STR := , get rid of the leading blanks';
WRITELN(LONG STR);
DELETE(LONG STR,l,POS('g' ,LONG STR)-l);
WRITELN(LONG STR); -
END; -

Output:
get rid of the leading blanks
get rid of the leading blanks

6-23
Pascal/MT+ Reference Manual DISPOSE Function

DISPOSB Function

Syntax:
PROCEDURE DISPOSE(VAR P POINTER) ;
PROCEDURE DISPOSE(VAR P POINTER, VARIANTS);

Explanation:
DISPOSE deallocates space that NEW allocates. When DISPOSE
returns, the value of the pointer var iable is uhdefined. If you are
using the FULLHEAP memory manager, the space is available for reuse.
Otherwise, the space is not available for reallocation.
See NEW for an example of using DISPOSE and more information
about deallocating variant records.

6-24
Pascal/MT+ Reference Manual EOLN, EOF Function

BOLN, BOF Panction

Syntax:
FUNCTION EOLN : BOOLEAN;
FUNCTION EOIN (VAR F : TEXT) : BOOLEAN;
FUNCTION EOF : BOOLEAN;
FUNCTION EOF(VAR F : FILE) : BOOLEAN;

Exp lana tion:


EOLN returns TRUE when the window var iable is over the end-of-
line character in a file. EOF returns TRUE when the window variable
is over an end-of-file character. If you do not specify a file, the
default input file is assumed.
EOLN returns TRUE on disk TEXT files when a READ statement
reads the last valid character on a line. The . sequence of
statements for a READ on nonconsole files is,
CH := FA;
GET (F) ;
This positions the window variable over the end-of-file pharacter.
Thus, EOLN returns TRUE on nonconsole TEXT files when the last
character is read, and a blank returns instead of the end-of-line
character.

On console files, this sequence reverses; READ has an initial


call to ~ET followed by an ass ignmen t from the window var iable. For
this reason, EOLN returns TRUE in console files after the
carr iage/return line-feed is read. EOLN returns TRUE in nonconsole
files after the last character is read. A blank still returns in
the character.
EOF, like EOLN, returns TRUE when the last character is read on
nonconsole files. On console files, EOF is TRUE only when the end-
of~file indicator is entered. The system does not support reading
past the end-of-file on console or disk files; it can crash. The
window variable returns a blank when EOF is TRUE.

EOF does not become TRUE at the end of the valid data in non-
TEXT files if the data does riot fill up the entire last sector of
the file.
The following example illustrates these concepts. Suppose the
input stream for a TEXT file consists of

I Ala' c leI tE{elal


0

6-25
Pascal/MT+ Reference Manual EOLN, EOF Function

If you repeatedly read characters from this stream, EOLN and EOF
return the values summarized in Table 6-3.

Table 6-3. BOLlI, BOP Values for a ~ Pile


Console Nonconsole
Character EOLN EOF Character EOLN EOF
returned returned
A F F A F F
B F F B F F
C F F C T F
space T F space F F
0 F F 0 F F
E F F E T F
space T F space T T
space T T space T T

For a non-TEXT file, suppose the input stream consists of

Table 6-4 shows the values of EOF when you repeatedly. read integers
from the input stream.

Table 6-4. BOP Values for a Non-TEXT Pile


Value returned EOF
1 F
2 F
3 F
6682 F

6682 T
(Note that 6682 is the end of the sector)

6-26
Pascal/MT+ Reference Manual EXIT Function

EXI'!' Function

~yntax:

PROCEDURE EXIT~

Explanation:
EXIT leaves the current procedure or function, or the main
program. If used in an INTERRUPT procedure, EXIT also loads the
regist.rs and reenables interrupts before exiting. EXIT is the
equivalent of the RETURN statement in FORTRAN or BASIC. You usually
execute it as a statement following a test.

Example:

PROCEDURE EXITTEST;
EXIT THE CURRENT FUNCTION OR MAIN ~ROGRAM.

PROCEDURE EXITPROC(BOOL BOOLEAN) ;

BEGIN
IF BOOL THEN
BEGIN
WRITELN('EXITING EXITPROC');
EXIT;
END;
WRITELN('STILL IN EXITPROC, ABOUT TO LEAVE NORMALLY');
END;

BEGIN
WRITELN('EXITTEST •...••• ') ;
EXITPROC'(TRUE) ;
WRITELN('IN EXITTEST AFTER 1ST CALL TO EXITPROC')i
EXITPROC (FALSE) ;
WRITELN('IN EXITTEST AFTER 2ND CALL "TO EXITPROC')i
EXIT;
WRITELN('THIS LINE WILL NEVER BE PRINTED');
END;

Output:

EXITTEST •••••..
EXITING EXITPROC
IN EXITTEST AFTER 1ST CALL TO EXITPROC
STILL IN EXITPROC, ABOUT TO LEAVE NORMALLY
IN EXITTESTAFTER 2ND CALL TO EXITPROC

6-27
Pascal/MT+ Reference Manual EXP Function

UP Function

Syntax:
FUNCTION EXP(X)

Explanation:
EXP returns the exponential of X. X must be real or integer.
The'result is real. The function returns a value that is the
natural logarithm (base e), raised to the power of X. Use this
function with the natural logarithm function, LN.

Examples:
IF (EXP(LN(X) + LN(Y» - (X • Y) <= TOLERANCE THEN
WRITELN('LOGARITHM FUNCTIONS PASS TEST');
WRITELN(X, ' •• ', Y, '=', EXP(Y • LN(X»);

6-28
Pascal/MT+ Reference Manual FILLCHAR Function

FILLCBAR Function

Syntax:
PROCEDURE FILLCHAR( DESTINATION, LENGTH, CHARACTER);

Explanation:
FILLCHAR is a fast way to fill in large data structures with
the same data. For example, FILLCHAR can blank out a buffer.
DESTINATION is a variable reference, but need not be a packed
ar ray of characters as in UCSD Pascal. It can be subscr ipted.
LENGTH is an integer expression.
Hote: if LENGTH is negative or greater than the length of
DESTINATION, it overwrites adjacent code or data. CHARACTER is a
literal or variable of type CHAR. Fill the DESTINATION with the
number of characters specified by LENGTH.

Example:
PROCEDURE FILL_DEMO;
VAR:
BUFFER PACKED ARRAY[l .. 256] OF CHAR;
BEGIN
FILLCHAR(BUFFER,256,' '); {BLANK THE BUFFER}
END;

6-29
Pascal/MT+ Reference Manual GET Function

GET Punction

Syntax:
PROCEDURE GET(VAR F, FILE VARIABLE);

Explanation:
GET advances the window variable by one element and moves the
contents of the indicated file into the window var iable. EOF must'.,.
be FALSE before GET executes. When there is no next element, EOF
becomes'TRUE and the value of the window var iable becomes undef ined
0

See Section 7 for more details on GET and TEXT files.

6-30
Pascal/MT+ Reference Manual HI,LO, SWAP Function

81 « LO, SWAP Function

Syntax:
FUNCTION HI (BASIC VAR) INTEGER~
FUNCTION LO(BASIC-VAR) INTEGER;
FUNCTION SWAP(BASIC=VAR) INTEGER;

. Explanation:
HI returns the upper 8 bi ts of BASIC_VAR ,(an 8- or l6-bi t
variable) in the lower 8 bits of the result.
LO returns the lower 8 bits, with the upper 8 bits forced to zero.
SWAP returns the upper 8 bits of BASIC_VAR in the lower 8 bits of
the resu~t and the lower 8 bits of BASIC VAR in the upper 8 bits of
the result. -
Passing an 8-bit variable to HI results in o. Passing 8, bits
to LO does nothing.
The following example shows the results of these functions.

Example:
PROCEDURE HI_LO_SWAP;
VAR
HL : INTEGER;
BEGIN
WRITELN ( 'HI LO SWAP ........ ');
HL := $104;- -
WRITELN ( 'HL=' ,HL) ;
IF HI (HL) = 1 THEN
WRITELN('HI(HL)=',HI(HL»;
IF LO(HL) = 4 THEN
WRITELN (' LO (HL) =' ,LO (HL) ) ;
IF SWAP (HL) = $0401 THEN
WRITELN ( • SWAP (HL)=' , SWAP (HL» ;
END;

Output:
HI LO SWAP •••••••
HL;;'260
HI(HL)=l
LO(HL)=4
SWAP (HL) =1025

6-31
Pascal/MT+ Reference Manual INLINE Function

IlILID Function

Syntax:
PROCEDURE INLINE(arg/arg/ ••• );

Explanation:
INLINE is a built-in feature that allows you to insert data in
the middle of a Pascal/MT+ procedure or function. You can insert
small machine-code sequences and constant tables into a Pascal/MT+
program without using externally-assembled routines. .
Section 4.3.2 of the Pascal/MT+Language Programmer's Gu ide has
examples of using INLINE.

6-32
Pascal/MT+ Reference Manual INSERT Function

IRSERr' Punction

Syntax:

PROCEDURE INSERT(SOURCE, DESTINATION, INDEX)1

Explanation:

INSERT puts SOURCE into DESTINATION at the location specified


in INDEX. DESTINATION is a str ing. SOURCE is a character or
str ing, li teral or var iable. INDEX· is an integer expression.
SOURCE can be empty. .

Rote: if INDEX is out of bounds or DESTINATION is empty, it


destroys data. If inserting SOURCE into DESTINATION makes
DESTINATION too long, it is truncated.

Example:
PROCEDURE INSERT_DEMO:
VAR
LONG STR : STRING;
S1 :-STRING[lO];
BEGIN
LONG STR := 'Remember Luke';
S1 :; 'the Force,';
INSERT(Sl,LONG STR,10);
WRITELN(LONG STR);
INSERT('to use ',LONG STR,lO);
WRITELN(LONG STR); -
end; -

Output:

Remember the Force, Luke


Remember to use the Force, Luke

6-33
Pascal/MT+ Refe~ence Manual IORESULT Function

IORBSOLT Function

Syntax:
FUNCTION IORESULT :.INTEGER:

Explanation:
After each I/O operation, the run-time library routines set the
value returned by the IORESULT function. In general, the value of
IORESULT is system-dependent. Never attempt to WRITE. the IORESULT
because it resets to 0 before any I/O operation.
Refer to the Pascal/MT+ Language Programmer's Guide for more
information about IORESULT.

Example:
ASSIGN(F,'C:HELLO');
RESET(F);
IF IORESULT = 255 THEN
WRITELN('C:HELLO IS NOT PRESENT');

6-34
Pascal/MT+ Reference Manual LENGTH Function

LENGTH Function

Syntax:

FUNCTION LENGTH( STRING) INTEGER~

Explanation:

LENGTH returns the integer value of the length of the string.

Example:

PROCEDURE LENGTH_DEMO~
VAR
Sl : STRING[40];
BEGIN
Sl := 'This string is 33 characters long';
WRITELN('LENGTH OF ',Sl,'=' ,LENGTH(Sl»;
WRITELN('LENGTH OF EMPTY STRING = ',LENGTH("»;
END;

Output:

LENGTH OF This string is 33 characters long=33


LENGTH OF EMPTY STRING = 0

6-35
Pascal/MT+ Reference Manual LN Function

LII Function

Syntax:
FUNCTION LN(X) REAL:

Explanation:
LN returns the natural logarithm of X. X must be real or
integer. The result is real.

6-36
Pascal/MT+ Reference Manual MAXAVAIL, MEMAVAIL Function

MAXAVAIL , MEMAVAIL Function

Syntax:
FUNCTION MAXAVAIL .' INTEGER:
FUNCTION MEMAVAIL INTEGER;

Explanation:
The functions MAXAVAIL and MEMAVAIL work with NEW and DISPOSE
to manage the heap memory area in Pascal/MT+.
MEMAVAIL returns the available memory at any given time,
regardless of fragmentation. MAXAVAIL reports the largest block
available.
/,If the result of these functions displays as a negative number,
the~amount of memory remaining is too large to express as a positive
integer. You can display the return value with WRITEHEX.
See your Pascal/MT+ Language Programmer's Guide for more
information on the use of dynamic memory.

6-37
Pascal/MT+ Reference Manual MOVE, MOVERIGHT, MOVELEFT Function

MOVE, MOVERIGBT, MOVBLBrl' Function

Syntax:
PROCEDURE MOVE (SOURCE, DESTINATION, NUM BYTES)
PROCEDURE MOVELEFT (SOURCE, DESTINATION, NUM-BYTES)
PROCEDURE MOVERIGHT(SOURCE, DESTINATION, NUM:BYTES)

Explanation:
These procedures move the number of bytes contained in
NOM BYTES from the SOURCE location to the DESTINATION location~
~and MOVELEFT are synonyms. They move from the left end of the
source to the left end of the destination. MOVERIGHT moves from the
right end of the source to the right end of the destination. The
parameters passed to MOVERIGHT specify the left end of the source
and destination.
The source and destination can be variables of any type, and
they need not be of the same type. They can be pointer s to
variables, but not named or literal constants. The number of bytes
is an integer expression between 0 and 64K.
MOVELEfT and MOVERIGHT transfer bytes from one data structure
to another or move data withfn a data stracture. These procedures
move on a byte level, ignoring the data structure type. MOVERIGHT
transfers bytes from the low end of an array to the high end ~
Without this procedure, you would need a FOR loop to pick up each
character and put it down at a higher address. MOVERIGHT is much
faster. You can use MOVERIGHT in an insert character routine to
make room for characters in a buffer.
MOVELEFT can transfer bytes from one array to another, delete
characters from a buffer, or move the values in one· data structure
to another.
When you use these. procedures keep .in mind the following:

• These procedures do not chec~ whether the number of bytes is


greater than the size of the destination. If the destination
is not large enough, bytes spill into the adjacent data storage
area.
• Moving 0 bytes moves nothing.
• There is no type checking.
Pascal/MT+ Reference Manual MOVE, MOVERIGHT, MOVE LEFT Function

Example:
PROCEDURE MOVE DEMO:
CONST -
STRINGSZ =
80:
VAR
BUFFER: STRING (STRINGSZ] :
LINE : STRING:

PROCEDURE INSRT(VAR DEST : STRING: INDEX: INTEGER: VAR SOURCE STRING):


BEGIN
IF LENGTH (SOURCE) <= STRINGSZ - LENGTH (DEST) THEN
BEGIN
MOVERIGHT'(DEST [ INDEX ], DEST [ INDEX+LENGTH (SOURCE) ],
LENGTH(DEST)-INDEX+l~:
MOVELEFT (SOURCE [l] , DEST[INDEX],LENGTH(SOURCE)):
DEST[O] :=CHR(ORD(DEST[O]) + LENGTH(SOURCE))
END:
END;

BEGIN
WRITELN ( 'MOVE DEMO ...... ') ;
BUFFER := 'Judy J. Smith/ 335 Drive/ Lovely, Ca. 95666';
WRITELN(BUFFER) :
LINE := 'Roland 'i
INSRT(BUFFER, POSt'5',BUFFER)+2,LINE);
WRITELN(BUFFER) ;
END;

Output:
MOVE DEMO •.....
Judy-J. Smith/ 355 Drive/ Lovely, Ca. 95666
Judy J. Smith/ 355 Roland Drivel Lovely, Ca. 95666

6-39
Pascal/MT+ Reference Manual NEW Function

_ Function

Syntax:
PROCEDURE NEW (VAR P POINTER) 1
PROCEDURE NEW (VAR P POINTER1 VARIANTS);

Explanation:
NEW dynamically allocates space for a record of the pointerts
type, and sets the value of the pointer to the new record. For
variant records, the procedure allocates enough space to hold the
largest variant, unless you specify which variant you want.
Specify the variant by its tag value. If the record has nested
variants, specify the variants in the order of nesting. When you
deallocate a record with DISPOSE, use the same parameter list.

Example:
PROGRAM NEWDEMO;
TYPE
COL = (RED, YELLOW, BLUE, GREEN, ORANGE, PURPLE):'
PTR = "REC;
REC RECORD
A : INTEGER;
CASE LIGHT COL OF
RED : ();
YELLOW: (R : REAL);
BLUE : (.
CASE TINT : COL OF
GREEN (W, X, Y, Z INTEGER);"
PURPLE: (H, I, J, K REAL)
)
END;
VAR
GENERAL, SMALL, BIG : PTR;
BEGIN
WRITELN(tTHIS PROGRAM DOES NOTHING BUT TWEAK THE HEAPt);
NEW(GENERAL) ; (* FOR ANY VARIANT *)
NEW (SMALL, RED); (* FOR SMALLEST VARIANT *)
NEW(BIG, BLUE, PURPLE); (* FOR LARGER VARIANT *)
DISPOSE(GENERAL);
DISPOSE (SMALL, RED);
DISPOSE (BIG, BLUE, PURPLE)
END.

6-40
Pascal/MT+ Reference Manual ODD Function

000 Function

Syntax:
FUNCTION ODD (INTEGER) BOOLEAN 1

Explanation:
ODD returns TRUE if the expression is odd and FALSE if it is
not.

Example:
IF OOO(LENGTH(ANSWER» THEN
WRITELN ( 'THAT' 's ODD!')
ELSE
WRITELN('EVEN I BELIEVE THAT')

6-41
Pascal/MT+ Reference Manual OPEN Function.

OPEN Function

Syntax:
PROCEDURE OPEN ( FILE, FILENAME, RESULT )~

Explanation:
The OPEN procedure opens an existing file for input. FILE is
any file variable. Filename is a string that contains the CP/M
filename. RESULT is an integer variable, which on return from OPEN,
has the same value as IORESULT. .
The OPEN procedure is the same as the sequence:
ASSIGN (FILE, FILENAME):
RESET(FILE):
RESULT := IORESULT:

Example:
OPEN ( INFILE, 'A:FNAME.DAT', RESULT );

6-42
Pascal/MT+ Reference Manual ORO Function

. ORO PUDction

Syntax:
FUNCTION ORO (SCALAR) INTEGER;

Explanation:
ORO returns the ordinal value of a scalar or enumerated type
expression. The result is an integer. For an enumerated type, the
ordinal value is the same as the order of declaration, startin9 with
O.

Example:
FUNCTION OIG20EC (C : CHAR) : INTEGER;

(* C MUST BE IN THE RANGE '0' .• '9' *)

BEGIN
OIG20EC := ORO(C) - ORD('O');
END;

6-43
Pascal/MT+ Reference Manual PACK, UNPACK Function

PACK, ORPACK Function

Syntax:
PROCEDURE PACK(A : ARRAY[M ••• N] OF T: Z ARRAY[U ••• V] OF T:
PROCEDURE UNPACK(A : ARRAY[M ••• N] OF T: Z : ARRAY[U ••• V] OF T:

Explanation:
The Pascal/MT+ compiler accepts PACK and UNPACK but does not
execute them. Because Pascal/MT+ i's byte-or iented, these procedures
are unnecessary.

6-44
Pascal/MT+ Reference Manual PAGE Function

PAGE Function

Syntax:
PROCEDURE PAGE(FILE VARIABLE);

Explanation:
PAGE sk ips to the top of a· new page when a TEXT file is
printing by inserting a begin-page character in the outp~ file. If
you do not specify the output file, it defaults to standard output.

6-45
Pascal/MT+ Reference Manual POS Function

POS Function

Syntax:
FUNCTION POS ( PATTE,RN, SOURCE ) INTEGER;

Explanation:
POS returns the integer value of the position of the first
occurrence of PATTERN in SOURCE. If PATTERN is not in the string,
the function returns O. SOURCE is a string. PATTERN is a string,
charact'er, or li teral.

Example:
PROCEDURE POS_DEMO;
VAR
STR,PATTERN : STRING;
CH : CHAR;
BEGIN
STR := 'Ada Lovelace';
PATTERN := 'Love';
CH : = 'v';
WRITELN('position of ',PATTERN,' in I,STR,' is " POS(PATTERN,STR»;
WRITELN ('position of ',CH,' in ',STR,' is ',POS (CH ,STR» i
WRITELN('pos of "z" in ',STR,' ~s ',POS('·z',STR»;
END;

Output:
position of Love in Ada Lovelace is 5
position of v in Ada Lovelace is 7
position of 'z' in Ada Lovelace is 0

6-46
Pascal/MT+ Reference Manual PRED Function

POD Put:lction

~yntax:

FUNCTION PRED(SCALAR) SCALAR:

Explanation:
PRED returns the value of the predecessor of a scalar
express ion. The ord inal value of the predecessor is 1 less than the
ordi~al value of the expression.

Example:
TYPE
WEEKDAY = (SUNDAY, MONDAY, TUESDAY, WEDNESDAY,
THURSDAY, FRIDAY, SATURDAY):
PRED(FRIDAY) THURSDAY
PRED(2 * 2) 3
PRED (' 0') 'c'

6-47
Pascal/MT+ Reference Manual PURGE Function

PURGE Punction

Syntax:
PROCEDURE PURGE( FILE )1

Explanation:
PURGE deletes the E"ile associated with th.! file variable. The
file is deleted from the disk directory.

Example:
ASSIGN(F,'BADFILE.BAD');
PURGE(F); (* DELETE BADFILE.BAD *)

6-48
Pascal/MT+ Reference Manual PUT Function

PUT 'Function

Syntax:
PROCEDURE PUT(FILE VARIABLE);

Explanation:
PUT transfers the contents of the window variable associated
with F to the next available record in the file. You must assign to
the window variable before executing a PUT. You can -use this
procedure only if EOF is TRUE. After execution, EOF remains TRUE
and the window variable becomes undefined.

6-49
Pascal/MT+ Reference Manual READ, READLN Function

READ, READLR Function

Syntax:
PROCEDURE READ (FILE VARIABLE, variable, variable, ••• ):
PROCEDUREREADLN(FILE VARIABLE, variable, variable, •• );

Explanation:
These procedures read from the file associated with the file
variable into the variables listed. If you do not specify a file,
the procedures default to the standard input.
READ~N works with TEXT files only, but both routines, when
reading from TEXT files, convert Booleans, reals, and integers from
their ASCII representations. All numbers convert on input, but the
formatting is lost. Therefore, you should separate numbers from
each other and from other data types by a blank or a carriage
return/line-feed.
READLN reads the data and then sets the file pointer at the
beginning -of the next lineo READ does not skip over data. When
reading strings, both procedures read from the current position to
the end of the line. Use READLN to read strings.
When reading from non-console files, the sequence of operations
for each data item is equivalent to:
<variable> := FA~
GET(F);
When reading from the console, the sequence is
GET (F) ;
<variable> := FA;
For non-TEXT files, the var iables in the parameter list must be
the same type as the data read from the file. The compiler does not
typecheck, however. You must construct a parameter list compatible
with your file's format.

6-50
Pascal/MT+ Reference Manual READHEX, WRITEHEX, Function

READBEX, . WRITEBEX, LWRITEBEX Function

Syntax:
PROCEDURE READ HEX VAR F TEXT VAR W : ANYTYPE; SIZE: 1 •• 4);
PROCEDURE WRITEHEX VAR F TEXT EXPRESSION ANYTYPE; SIZE: 1 ..
PROCEDURE LWRITEHEX VAR F TEXT EXPRESSION: LONGINT; SIZE: 1 ••

Explanation:
These routines read and write text in hex-adecimal
representation. SIZE specifies the number of bytes to read or
write.
READHEX reads two characters for each byte, then it skips to
the next carriage return/line feed. You cannot read more than one
hexadecimal number from a single line.
WRITEHEX writes two characters for each byte. It does not
output any leading or trailing blanks or a carriage return/line
feed.
LWRITEHEX is like WRITEHEX, except that it only works with long
integers, and it can handle up to four by~es. '
The 8~bit version of Pascal/MT+ does not have LWRITEHEX, and
its maximum data size for READHEX is 2 bytes.

6-5'1
Pascal/MT+ Reference Manual RESET Function

RBSB'l' Function

Syntax:
PROCEDURE RESET(FILE VARIABLE):

Explanation:
RESET moves the window pointer to the begir\ning of a file so
that you can read it. The window variable is set to the first
element of F. If you try to reset a file that does not exist,
IORESULT returns a value of 255. Any other val'ue means success.
RESET calls CLOSE if the file is already open.
The file is open to reading and' writing for random access.
With nonconsole typed files, the procedure RESET does an initial
GET. This process moves the first element of the file into the
window variable.
The initial GET does not perform on console ~r untyped files
because GET waits for a character, and you would have to type a
character before your program could execute.

6-52
pascal/MT+ Reference Manual REWRITE Function

RBWRXTE Function"

Syntax:
PROCEDURE REWRITE(FILE VARIABLE)~

Explana tion:
REWRITE creates a file on disk using the name associated with
the file variable, deleting any existing file by that name. If the
variable has no associated filename, specified with ASSIGN, REWRITE
creates a temporary file. -
Tenporary files are useful for scratch pad memory and data that
you no longer need after executing the program. The last two dig its
in the name make every temporary file unique, so you can have up to
100 temporary files.
The EOF and EOLN functions return TRUE because the file is an
output file. The file is open for sequential writing only and is
ready to receive data into its first element.

6-53
Pascal/MT+ Reference Manual RIM8s, SIM8s Function

RIM8S, SIM8S Function

Syntax:
FUNCTION RIM8s :". BYTE~
PROCEDURE SIM8s(VAL : BYTE)~

Explanation:
These routines use, the special 8085 instructions RIM and SIM.
They call the procedure that contains the instruction. Under CP/M,
the heap grows from the end of the data area, and the stack frame
(for recursion) grows from the top of memory down. CP/M preloads
the hardware stack register with the contents of absolute location
0006, unless the $Z option overrides it. The stack frame grows
starting at 512 bytes pelow the initialized hardware value.
Hote: these routines are only supported in the a-bit version of
Pascal/MT+.

6-54
Pascal/MT+ Reference Manual ROUND Function

ROORD Function

Syntax:
FUNCTION ROUND(REAL) INTEGER;

Explanation:
ROUND converts a real to an integer by rounding it up or down
to the nearest integer value.

Examples:
ROUND(2.67) = 3
ROUND(45.49) = 45

6-55
Pascal/MT+ Reference Manual SEEKREAD, SEEKWRITE Function

SBBKRBAD, SBBKWRI'l'E Fuoct ion

Syntax:

PROCEDURE SEEKREAO (F ANYFILE~ RECORD NUM: O•• MAXINT);


PROCEDURE SEEKWRlTE(F ANYFILE: RECORD:NUM O•• MAXINT);

Explana tion:

These procedures support random access I/O. SEEKREAD reads


from the specified record into the window variable. SEEKWRITE
writes from the window variable to the specified record" You must
assign to the window variable prior to a SEEKWRITE or assign from
the window var iable after a SEEKREAD. The records are numbered
sequen tially, starting. with record o.

Files wr i tten using SEEKWRITE are contiguous, regardless of the


record size. A fi·le can be accessed sequentially or randomly, but
not without executing a CLOSE before changing access modes.

To use SEEKREAD and SEEKWRITE, link in t'he library RANOOMIO,


which supports random access.

Section 7 has examples of these procedures and more information


about-random-access I/O.

6-56
Pascal/MT+ Reference Manual SHL, SHR Function

SBL, SBR· Function

Syntax:
FUNCTION SHL(BASIC VAR, NUM) INTEGER:
FUNCTION SHR(BASIC:VAR, NUM) INTEGER:

Explanation:
SHR shifts BASIC VAR by NUM bits to the right, inserting 0
bits. SHL shifts the BASI~ VAR by NUM bits to the left, inserting 0
bits. BASIC_VAR is an a=or l6-bit variable. NUM is an integer
expression.
Suppose you obtain a lO-bi t value from two separ.ate input
ports. Use SHL to read them in:
X := SHL(INP(a] & $lF, 3) ! (INP[9] & $lF);
The example reads from port number a, masks out the three high
bits returned from the INP array, and shifts the result left. Next,
this result logically OR's with the input from port number 9, which
has also been masked. .

Example:
PROCEDURE SHIFT DEMO;
VAR I : INTEGERT
BEGIN
WRITELN('SHIFT DEMO •••••••• ');
.I : = 4; -
,I);
WRITELN('I~'
WRITELN('SHR(I,2)=' ,SHR(I,2»;
WRITELN('SHL(I,4)=',SHL(I,4»;
ENO;

Output:
SHIFT DEMO ••••••••
1=4 -
SHR(I,2)=l
SHL(I,4)=64

6-57
Pascal/MT+ Reference Manual SIN Function

SIR Punction

Syntax:
FUNCTION SIN (ANGLE) REAL~

Explanation:
SIN returns the sine of the angle. Express the angle in
radians, as an integer or real expression.

6-58
Pascal/MT+ Reference ~anual SIZEOF Function

SIZBOP Function

Syntax:
FUNCTION SIZEOF (VARIABLE OR TYPE NAME) INTEGER~

Explanation:
SIZEOF is a compile-time function that returns the size of the
parameter in bytes. Use it in MOVE statements for the number of
bytes to be moved. With SIZEOF you do not need to keep changing
constants as the program evolves. The parameter can be any var iable
or user-defined ordinal type •.
SIZEOF is a compile-time function. Only the size of items that
do not generate code to calculate their address can be a parameter
to SIZEOF. The compiler must know the size of the item.

Example:
PROCEDURE SIZE_DEMO;
CONST
NAMELN 10;
ADDRLN 30;

VAR
A RECORD
NAME STRING [NAMELN] ;
ADDR STRING [ADDRLN]
END;
B RECORD
NAME STRING [NAMELN] ;
ADDR STRING [ADDRLN] ;
HIRE DATE INTEGER;
EMP NUM INTEGER
END; -
BEGIN
READLN(A.NAME);
READLN(A.ADDR);
B.HIRE DATE := 0;
B.EMP_NUM := 0;

MOVE (A, B, SIZEOF(A»; (* MOVES THE NAME AND ADDR


INTO B *)
WITH B 00
·WRITELN (NAME, ADDR, HIR_DATE, EMP_NUM)
. END;

6-59
Pascal/MT+ Reference Manual SIZEOF Function

In this example, if you change the value for NAMELN or ADDRLN,


you do not have to change the parameters to MOVE, because the SIZEOF
function always returns the current size of record A.

6-60
Pascal!MT+ Reference Manual SQR Function

SQR Function

Syntax:
FUNCTION SQR(X) REAL or INTEGER

Explanation:
SQR returns the square of X. X must be real or integer. The
result has the same type as X.

Example:
SQR(S) = 2S
SQR ( 4 • 0 ) = 16 • 0

6-61
Pascal/MT+ Reference Manual SQRT Function

SQRT Punction

Syntax:
FUNCTION SQRT(X) REALr

Explanation:
SQRr returns the square root of X. X must be real or integere
The result is real.

6-62
Pascal/MT+ Reference Manual SUCC Function

SOCC Function

Syntax:
FUNCTION SUCC(X) SCALAR~

Explanation:
X is a scalar or subrange expression. SUCC returns the value
of XiS successor.

Examples:
SUCC ( I AI ) = I B I
SUCC(FALSE) = TRUE
SUCC(23) = 24

6-63
Pascal/MT+ Reference Manual TRUNC Function

TRDHC Punction

Syntax:
FUNCTION TRUNC(REAL) INTEGER1

Explanation:
TRUNC converts a real number to an integer by dropping the
digits to the right of the decimal point.

Examples:
TRUNC(4.99) =4
TRUNC(36.2 + 1.11) 37

6-64
Pascal/MT+ Reference Manual TSTBIT, SETBIT, CLRBIT Function

'rS'rBIT, SBTBIT, CLRBIT Function

Syntax:
FUNCTION TSTBIT( BASIC VAR, BIT NUM} BOOLEAN;
PROCEDURE SETBIT(VAR BAS IC-VAR, BIT-NUM};
PROCEDURE CLRBIT(VAR BASIC:VAR, BIT:NUM};

Explanation:
TSTBIT returns TRUE if the designated bit is on, and returns
FALSE if the bit is off.
SETBIT sets the designated bit in the parameter.
CLRBIT clears the designated bit in the parameter.
BASIC VAR is any a-or l6-bi t var iable. BIT_NUM is' o•• 15 wi th
bit 0 on the right.
If BITNUM is out of range, results are unpredictable but the
program continues. For example, trying to set or clear bit 10 of an
a-bit variable causes unpredictable results, but no error message.

Example:
PROCEDURE TST SET CLR_BITS;
VAR
I : INTEGER;
BEGIN
WRITELN('TST SET CLR BITS ....•.• ');
I := 0; -
SETBIT(I,5};
IF I = 32 THEN
IF TSTBIT(I,5) THEN
WRITELN ( , 1=' , I) ;
CLRBIT(I,5);
IF I = 0 THEN
IF NOT (TSTBIT(I,5»- THEN
WRITELN('I=' ,I);
END;

Output:
TST SETCLR BITS ••••.••
1=32 - -
1=0

6-65
Pascal/MT+ Reference Manual WAIT Function

WAIT Function

Syntax:
PROCEDURE WAIT(PORTNUM , MASK, POLARITY)~

Explanation:
The WAIT procedure is only available in the a-bit version of
Pascal/MT+. PORTNUM and MASK are literal or named constants.
POLARITY is a Boolean constant. WAIT generates a tight ~tatus wait
loop:
IN portnum
ANI mask
J?? $-4
The WAIT procedure does not generate in-line code for the
status loop. A status loop is constructed in the DATA area and
called by the WAIT run-time subroutine. Thus, the loop is fast, but
the call and return from the loop add a small amount of execution
time. Use INLINE if time is critical.

Example:
PROCEDURE WAIT_DEMO;
CONST
CONSPORT = $F7; (* for EX?O NOBUS-Z COMPUTER *)
CONSMASK = $01;
BEGIN
WRITELN('WAIT DEMO ••.•••• ');
WRITELN('WAITING FOR A CHARACTER');
WAIT(CONSPORT,CONSMAXK,TRUE);
WRITELN ( I THANKS I ) ;
END;

6-66
Pascal/MT+ Reference Manual WNB, GNB Function

NRB, GRB Function

Syntax:
FUNCTION GNB(FILEVAR: FILE OF PAOC):CHAR;
FUNCTION WNB(FILEVAR: FILE OF CHAR; CH:CHAR) BOOLEAN;

Explanation:
These functions give you byte-level, high-speed access to a
file. PAOC is any type that is a Packed Array Of Char. The optimum
size of the packed array is in the range 128 •• 4095.
GNB lets you read a file one byte at a time. GNB returns a
value of type CHAR. The EOF function is valid when the physical
end-of-file is reached but not based upon any data in the file.
Attempts to read past the end of the file return $FF.
WNB lets you write a file one byte at a time. WNB requires a
file and a char acter to wr i te. The function returns a Boolean value
that is TRUE if there was an error while writing that byte to the
file. Written bytes are not interpreted.
GNB and WNB are faster than using F"", GET/PUT combinations,
because of their larger buffer.

6-67
Pascal/MT+ Reference Manual WRITE, WRITELN Function

WRID, WRI'fBLR Function

Syntax:
PROCEDURE WRITE (FILE VARIABLE, EXPR, EXPR, ••• );
PROCEDURE WRITELN(FILE VARIABLE, EXPR, EXPR, ••• );

Explanation:
These procedures write data to the file associated witt. F. If
the file is a TEXT file, they convert numbers to ASCII and write the
Boolean values as the strings TRUE and FALSE.
WRITE (F, DATA);
is equivalent to
F'" := DATA;
PUT(F);
WRITELN works only with TEXT files, ending an old line and
starting a new one. The procedure is like WRITE, except it puts a
carriage return and line feed after the data. A WRITELN with no
expressions outputs only a carriage retu;n/line-feed.
Data 'can be li teral and named constants, integers, reals,
subranges, enumerated, Booleans, strings, and packed arrays of
characters, but cannot be structured types, such as records.
If you do,not specify a file, the procedures default to the
standard output file.
WRITE and WRITELN treat strings as arrays of characters. They
do not write the length byte to the file.
You can specify the field format for any data type~ The field
format 1's
<real or non-real variable> : <field width>
or
<real variable> : <field width> : <fraction length>
The minimum <field width>, which is optional, is a natural
number that specifies the smallest number of characters to writeo
The optional <fraction length> specifies the number of digits to
follow the decimal point in a real 'number. For non-real numbers,
specify only the field width. The da,ta is right-justified in the
field. A number is always expressed in exponential notation if a
number is larger or smaller than the significant digits can
represent.

6-68
Pascal/MT+ Reference Manual WRITE, WRITELN Function

If you do not specify a <field width>, real numbers are output


in exponential format, and other types are output without any extra
leading or trailing blanks.

Example:
PROGRAM DO_WRITE;

CONST
STR 'COLORLESS GREEN IDEAS':
BUL TRUE:
INT 9876:
REL 2345.678:

VAR
F TEXT;
I INTEGER;

BEGIN
ASSIGN(F, 'SAMPLE.TXT'):
REWRITE(F) ;
WRITE(F, '*', 1, 2, 3) i
WRITE (F ,4, 5, 6) i
WRITELN(F, '*'):
WRITELN(F, '2: *' STR, '*');
WRITELN (F, '3: *' STR: 40, '*');
WRITELN (F, '4: *', BUL, '*', INT, '*', REL, '*');
WRITELN(F, '5: *',BUL:10,'*',INT:10,'*' ,REL:10,'*');
WRITELN(F, '6: *', REL:10:3, '*', REL:8:1, '*');
CLOSE (F, I)
END.

Output:
*123456*
2: *COLORLESS GREEN IDEAS*
3: * COLORLESS GREEN IDEAS*
4 *TRUE*9876* 2.34567E+03*
5 * TRUE* 9876* 2.3456E+03*
6 * 2345.678* 2345.7*

6"-69
Pascal/MT+ Reference Manual @BDOS Function

@BDOS Function

Syntax:
FUNCTION @BDOS~

Explanation:
@BDOS enables direct access to the CP/M operating system.
See the Pascal/MT+ Language Programmer I s Guide _ for more-
information.

6-70
Pascal/MT+ Reference Manual @BDOS86 Function

@BDOS86 Function

Syntax:

FUNCTION @BDOS86;

Explanation:

@BDOS86 enables direct access to the CP/M-86~ operating


system. See the Pascal/MT+ Language Programmer's Guide for more
information.

6-71
'Pascal/MT+ Reference Manual @CMD Function

@OID Function

Syntax:
FUNCTION @CMD "'STRING:

Explanation:
@CMD lets you access the command tail of a'command line. The
function retrieves the information from the command tail, moves it
to a string, and returns a pointer to this string. The command tail
starts with a blank. You can call @CMD only once, at the beginning
of the program before you open any files.

Example:
PROGRAM @CMD_DEMO:
TYPE
PSTRG = "STRING;

VAR S : STRING[16]:
PTR : PSTRG:
F : FILE OF INTEGER;

EXTERNAL FUNCTION @CMD : PSTRG:

BEGIN
PTR := @CMD;
S := PTR"'i
ASSIGN(F,S);
RESET (F)
END.

6-72
Pascal/MT+ Reference Manual @ERR Function

@BRR- Function

Syntax:
PROCEDURE @ERR ~

Explanation:
@ERR is the default error handling routine in PASLIB. You can
replace @ERR with your own error handling routines. See Section
4.6.3 of the Pascal/MT+ Language Programmer's Guide for more
information.

6-73
Pascal/MT+ Reference Manual @HLT Function

@BL~ Function

Syntax:

PROCEDURE @HLT ~

Explanation:

@HLT unconditionally halts your program, and returns control to


the operating system. Section 7.6 contains an example of using
@HLT.

6-74
Pascal/MT+ Reference Manual @HERR Function

@BBRR Punction

Syntax:
FUNCTION @HERRi

Explanation:
@HERR is a predefined BOOLEAN variable that the NEW procedure
uses to return the result of an allocation request. @HERR returns
FALSE if space is available, or TRUE when there is no space.
You should always use @HERR in conjunction with NEW, because
the heap management system in PASLIB does not signal an error if
there is no space available when you make an allocation request.

6-75
Pascal/MT+ Reference Manual @MRK Function

@MRK Function

Syntax:
FUNCTION @MRK INTEGER:

Explanation:
@MRK returns the address of the top of the heap. You must save
the address if you want to use @RLS to restore the heap· to its
previous state.
You can use @MRK to mark more than one address, and then use
@RLS to return to any of them.
See Section 4.3.5 of the Pascal/MT+ Languaqe Programmer • s Guide
for more information.

6-76'
Pascal/MT+ Reference Manual @RLS Function

@RLS Function

Syntax:
FUNCTION @RLS (INTEGER);

Explanation:
@RLS resets the top of the heap to the address returned by
@MRK. ."
See Section 4.3.5 of the Pascal/MT+ Language Programmer I s Guide
for more information.

End of Section 6

6-77
Section 7
Input and Output

This section descr ibes the Pascal/MT+ I/O (input/output)


system. The I/O system is hardware-independent, and allows a
program to transfer data between memory and external devices such as
a console, printer, or disk. ·Pascal/MT+ provides both sequential
and random access I/O.

7.1 Pundaaentals of Pascal;Mr+ I/O


A file is like an open-ended array that can contain elements of
any simple or structured type. The size of a file is limited by
your operating system or by the capacity of your disk.
In Pascal/MT+, a file variable has two parts: a File
Information Block (FIB), and a buffer •

• The File Information Block contains information about the file


such as the file's name and type, whether the file is open for
reading or writing, and the end-of-file and end-of-line flags.
The file named FIBDEF.LIB on your dist~ibution disk contains a
complete description of the FIB •
• The buffer holds one item of the file's base type. The I/O
routines read data into or write data from the buffer, and it
is the only part of the file variable that you can directl~
access. This buffer is sometimes called the "window variable"
• because you can visualize it as a window into the file.

You declare a f i'le var iable like any other var iable, as in the
following example:

TYPE
INTFILE = FILE OF INTEGER;
REC RECORD
x, Y, Z REAL;
I, J, K INTEGER
END;
VAR
Fl, F2 INTFILE;
F3 FILE OF REC;
F4 FILE OF ARRAY[l •• lO] OF CHAR;
FS FILE; (* UNTYPED FILE FOR BLOCK I/O *)

7-1
pascal/MT+ Reference Manual 7.1 Fundamentals of Pascal/MT+ I/O

When you declare a file var iable, the I/O system does not
associate a physical disk file with that variable. You have to use
the ASSIGN or OPEN procedure to associate an actual filename with
the variable. After that, all input and output to the file is
through the file variable.
In general, you use the file var iable I s name to refer to the
file. If you want to reference the buffer, follow the name with the
pointer character. For example,
ASSIGN (F3, ITEST.OAT I );

associates the name TEST.OAT with the file variable F3, and
F2" := 45;

puts the integer value 45 in the buffer of the file variable F2.
Each file must have an explicit end-of-file indicator. Most
operating systems use a control character to indicate the end-of-
file. When the I/O system encounters this character, the predefined
function EOF returns TRUE.
Under some cond it ions, however, the valid da ta end s before the
opera ting system signals an end-of-file condition. This can happen,
for example, when the data does not fill the last sector in the
file. In this case, EOF does not detect tl1e actual end of the Data
file. There fore, you must use a dummy record as the la st record, or
save the number of records in a separate file.

7.2' Regu1ar I/O


The two basic rou tines for reading and wr it in"g da ta are GET and
PUT. GET reads the next file element into the buffer. PUT "writes
the contents of the buffer to the next position in the file.

To write data to a file using PUT, you have to assign the data
to the buffe r and then call PUT a,s in the following sequence:
F ... : = ITEM;
PUT (F) ;

The newly written item is the last element in the file.

To read data with GET, you take the data from the buffer and
then call GET, as in the following sequence:
ITEM := F . . . ;
GET (F) ;

The reason for this sequence is not intuitive. Note however, that
when you call RESET to open the file for reading, the first element
in the file is au tomatically placed in the buffer e --carling GET
places the ~ item in the buffer.

7-2
Pascal/MT+ Reference Manual 7.2 Regular I/O

If you are reading from the console, you have to call GET
before you access the buffer, because initially there is nothing in
the buffer, and the program would wait indefinitely for the first
character.
The program shown in Listing 7-1 demonstrates the GET and PUT
routines. The program creates a file, writes some data to it, and
then reads the data back from the file. Notice that you have to
explicitly move data in and out of the buffer.
You usually do not have to use GET and PUT. The procedures
READ and WRITE allow you to read and write data without worrying
about the buffer. Both routines can handle any filetype. You do
not have to treat the console and other devices differently when you
use READ and WRITE.

Stmt Nest Source Statement

1 0 PROGRAM WRIT£ READ FI~E DEMO:


2 0
3 0 TYPE
4 1 CHFILE FILE OF CdAR;
5 1 VA?.
6 .l OUTFILE : CHFILE;
7 1 RESULT INTEGER;
8 1 FILENAME: STRING[16];
9 1
10 1 PROCEDURE WRITEFIL2( VAR F
1 ,
~ VAR CH : CHAR;
12 2 BEGIN
13 2 ~'OR CH : = fe' _v '(A' :~I:;
14 2 BEGIN
15 3
16 3 PUT (F)
17 3 END;
18 2 END;
19 1
20 1 PROCEDURE READFILE( VAR F CHFILE) ;
21 1 VAR I : INTEGER;
22 2 CH : CHAR;
23 2 BEGIN
24 2 FOR I := 0 TO 9 DO
25 2 BEGIN
26 3 CH := FA;
27 3 GET(F);
28 3 WRITELN(CH) ;
29 3 END:
30 2 END;

Listing 7-1. Pi1elnput and Output

7-3
Pascal/MT+ Reference Manual 7.2 Regular I/O

Stmt Nest Source Statement


31 1
32 1 BEGIN
33 1 FILENAME := 'TEST.DAT';
34 1 ASSIGN (OUTFILE,FILENAME) ;
35 1 REWRITE (OUTFILE) ;
36 1 IF IORESULT = 255 THEN
37 1 WRITELN('Error creating ',FILENAME)
38 1 ELSE
39 1 BEGIN
40 2 WRITEFILE(OUTFILE) i
41 2 CLOSE (OUTFILE,RESULT) ;
42 2 IF RESULT = 255 THEN
43 2 WRITELN('Error closing ',FILENAME)
44 2 ELSE
45 2 BEGIN
46 3 WRITELN('Successful.close of ',FILENAME);
47 3 RESET (OUTFILE) ;
48 3 IF IORESULT = 255 THEN
49 3 WRITELN('Cannot open' ,FILENAME)
50 3 ELSE
51 3 READFILE(OUTFILEf
52 3 END;
53 2 END;
54 1 END.

Listing 7~1. (continued)

7.3 INP and OUT Arrays


Pascal/MT+ allows' direct manipulation of input and output
hardware ports through two features.

1) Two predeclared arrays, INP and OUT, of type BYTE, can be


subscripted with port number constants and expressions.
The INP array can be used only in expressions. The OUT
array can be used only on the LEFT side of an assignment
statement. The most significant byte of INP contains 00 if
the values from INP are assigned to var iables of type
INTEGER. .
You can subscript these arrays with integer expressions in
the range 0 to 255. Two types of syntax are used with this
feature. The code is always generated in-line for INP and
OUT, but always uses variable ~ort I/O instructions.

7-4
Pascal/MT+ Reference Manual 7.3 INP and OUT Arrays

Examples:
OUT[(PORTNUM + I)] := $88~
OUT [ 0 ] : = $ 8 8 1
J := INP[(PORTNUM)];

2) A function INPORT_W, and a procedure OUTPRT_W manipulate' I/O


ports. Although they are present in the standard library,
you must declare them as:
EXTERNAL FUNCTION INPORT W (PORTNUM:INTEGER) :WORD;
EXTERNAL PROCEDURE OUTPRT:W(PORTNUM:INTEGER; DATA:WORD);
Examples:
INCHAR := INPORT W(PORTNUM) ;
OUTPRT W(PORTNUM~OUTCHAR);
OUTPRT:W($004F,OUTCHAR);

7.4 Redirected I/O


Redirected I/O is an alternative to the GET-character and PUT-
character routines in the run-time package. Redirected I/O is
useful when you do not want the regular I/O from your operating
system. Also, this feature works well for' converting numbers into
strings and strings into numbers. The sample program shown in
Listing 7-2 demonstrates this application.
Pascal/MT+ has a mechanism you can use to wr i te your own
character-level I/O drivers. This facility lets a ROM-based program
be system-independent. It also works with user-written character
input and output rou'tines that get their data from, or write it to,
strings or I/O ports~It lets them use the conversion routines·built
into the system Read-Write code.
Example:
READ ( [ ADDR (getch) ], ••• );
WRITELN ( [ ADDR (pu tch ) ], .... ) ;
.You can wr i te the "getch and "putch routines in Pascal/MT+ or
II II

in assembly language. The parameter requirements for these routines


are
FUNCTIONgetch : CHAR;
PROCEDURE putch(outputch: CHAR);
. .

When you use this mechanism, keep in mind the following points:

• You must show the declaration of these routines~

7-5
Pascal/MT+ Reference Manual 7.4 Redirected I/O

• The names need not be getch/putch, but the GET character


routine must not have parame-ters, and the PUT character routine
must have one parameter of type CHAR •
• You can assign the address of the procedure to a pointer using
the ADDR function and then specify this pointer. For example,
READ ( [P], ••• ). This saves typing time, but not execution time.

Note that READLN and EOF/EOLN cannot be used with redirected


I/O because EOLN and EOF both operate on files. Note also that you
cannot read into STRING var iables requir ing the use of READLN,
because READLN uses EOLN.
The reason is that the @RST (read string) routine tries to read
directly from the console device when no file is specified. You can
rewrite the @RST routine to perform any input and editing functions
you want for the target-system console device. This does not affect
programs that do not use redirected I/O.
Referring to the program in Listing 7-2, note that WIR, the PUT
character routine, (line 8) writes to a global string, named CONV,
and GETCH, the GET character function, (line 28) gets its character
input from this global string.
The test program code begins on line 39. The first statements
initialize' the variables required by WIR and GETCH. CONVERTING is a
Boolean value that is TRUE when WIR is writing a number to CONV.
CONV is initialized to the empty string, so. its length byte is 0 •.
On line 42, the test variable I is assigned the value 2438.
Then, on line 43 the regular WRITELN statement writes it to the
console.
Line 44 demonstrates the concept of redirected I/O in this
program.
WRITELN{[ADDR{WIR)] ,I);
Here, WIR's address is. passed to the WRITELN routine so that
W~R is used instead of the PUT character routine in the run-time
package. The run-time routinescoilvert the number I into characters
that are passed to WIR for output to the str ing, CONV. In this way,
the contents of I are converted to a string. Note that WIR must
always be called with a WRITELN because it uses the carriage return
to signal ~hat the number is complete.

7-6
Pascal/MT+ Reference Manual 7.4 Redirected I/O

StInt Nest Source Statement


1 0 PROGRAM CONV_DEMO;
2 0
3 0 VAR
4 1 I : INTEGER;
5 1 CONV : STRING;
6 1 CONVERTING : BOOLEAN;
7 1
8 1 PROCEDURE WIR{CH : CHAR);
9 1 BEGIN
10 2 IF CH = CHR (SOA) THEN (* DONE, IGNORE LINEFEED *)
11 2 EXIT;
12 2 IF CONVERTING THEN
13 2 IF CH <> CHR{SOD) THEN (* NOT AT END OF STRING" *)
14 2 CONV := CONCAT{CONV,CH)
15 2 ELSE
16 2 CONVERTING := FALSE (* REACHED END-DONE *)
17 2 ELSE
18 2 BEGIN
19 3 CONV := ";
20 3 IF CH <> CHR{SOD) THEN
21 3 BEGIN
22 4 CONV := CONCAT(CONV,CH);
23 4 CONVERTING := TRUE
24 4 END
25 4 END;
26 2 END;
27 1
28 1 FUNCTION GETCH : CHARi
29 1 BEGIN
30 2 IF LENGTH(CONV) > 0 THEN (* SOMETHING LEFT TO CONVERT *)
31 2 BEGIN
32 3 GETCH := CONV[I) ;
33 3 DELETE (CONV,l,l) ;
34 3 END
35 3 ELSE
36 2 GETCH ;= , '; (* RETURN BLANK-NO MORE CHARACTERS *)
37 2 END;
38 1
39 1 BEGIN (* MAIN PROGRAM *)
40 1 CONVERTING := FALSE;
41 1 CONV := I ' ;
42 1 I := 2438:
43 1 WRITELN('I=' ,I);
44 1 WRITELN ( [APDR (WIR) ) ,I) i (* FIELD WIDTH MAY BE GIVEN *)
45 1 I := 0;
46 1 WRITELN{'I=',I) ;
47 1 WRITELN (' CONV=' ,CONV) ;
48 1 READ ( [ADDR (GETCH) ) ,I) i (* READLN MAY NOT BE USED *)
49 1 W.RITELN (' I= I, I) ;
50 1 END.

Listing 7-2. Redirected I/O

7-7
Pascal/MT+ Reference Manual 7.5 Sequential I/O

7.5 Sequential I/O


Sequential I/O means that the I/O system accesses the data
items in a file in a serial fashion. Thus, you can read the data
items one after the other, and you can add items only at the end of
the 'file.

7.5.1 TEXT Files


A TEXT file is a file of ASCII characters subdivided into
lines. The predefined type TEXT is used for ASCII files. A line is
a sequence of characters terminated by a nonprintable end-of-line
indicator, usually a carriage return and a line-feed.
A TEXT file is similar to a file of CHAR except that numbers
are automatically converted when they are read from and written to
the file. Numbers written to TEXT files convert to ASCII, and can
be formatted. Numbers read from TEXT files convert to binary.
TEXT files differ from files of type CHAR in the following
,ways:

• TEXT files are subdivided into lines.


• TEXT files accept both ARRAY[I •. N] OF CHAR, and rACKED
ARRAY[-I •• N] OF CHAR as data.
• TEXT files accept STRINGS as data.
• Boolean values convert to the ASCII sequence TRUE or FALSE' on'
write, but TRUE or FALSE do not convert to Boolean values.
• You can access a TEXT file with GET and PUT for character I/O
(which do not do conversions), READ and WRITE, and READLN and
WRITELN.

The format ofa TEXT file in memory is a FIB and a I-byte


window variable. Figure 7-1 illustrates the way a TEXT file appears
on disk.

This )jis ~ a Iii IineC) 6 This Iii is'1ii the ~ next li'line G6 This Ii' is Ii' the li'last Iii' line 8 68

)'igure7-1. Lines ,in a ·"rEXT File

7-8
Pascal/MT+ Reference Manual 7.5 Sequential I/O

The program in Listing 7-3 writes data to a TEXT file and reads
it back for display on the output device. The procedure WRITE DATA
writes to the TEXT file and READ DATA retrieves the information
stored in the file. -
The field format can be specified for any data type. For non-
real numbers only the field width is specified, not the number of
places after the decimal point. The data is right-justified in the
field. The output is always expressed in exponential notation if a
number is larger than the significant digits can represent. It is
also written in exponential notation if the field width is too small
to express the number.
The body of the WRITE_DATA procedure can be written in the
following manner with the same results:
WRITELN(F,S) ;
WRITELN(F,I:4, 45.6789 : 9 : 4);
Referring to Listing 7-3, note that if a READLN were used on
line 31, the integer value 35 would be read properly because the
first blank terminates the number. However, the window variable
would advance past the real number to the end of the file. Then, if
you try to read the real number, you would only get the EOF.
STRINGS must always be read wi th a READLN because they are
terminated with end-of-line char'acters. If the data in the. file was

This t6 is t6 a t6 string 35 e6
the value returned for S would be the entire line, including the
ASCII 35.
Within the READ_DATA procedure, lines 20 and 21 write the data
to the console in the same format as in the file.
The main program stops after processing the call to READ DATA
on line 43. A CLOSE is not necessary because the data in TEXT'.. TST
is not altered from the last CLOSE ori that file;
Pascal/MT+ Reference Manual 7.5 Sequential I/O

Stmt Nest Source Statement


1 0 PROGRAM TEXT_IO_DEMO;
2 0
3 0 VAR F TEXT;
4 1 I : INTEGER;
5 1 S : STRING;
6 1
7 1 PROCEDURE WRITE DATA;
8 1 BEGIN -
9 2 WRITELN(F,S);
10 2 WRITE(F,I:4);
11 2 WR[TELN(F,45.6789:9:4);
12 2 END;
13 1
14 1 PROCEDURE READ DATA;
15 .1 VAR R : REAL; -
16, 2 BEGIN
17 2 READLN(F,S);
18 2 READ(F,I);
19 2 READ(F,R) ;
20 2 WRITELN(S);
21 2 WRITELN(I:4,' ',R:9:4);
22 2 END;
23 1
24 1 BEGIN
25 1 ASSIGN(F,'TEXT.TST');
'26 1 REWRITE (F) ;
27 .1 IF IORE7SULT = 255 THEN
28 1 WRITELN('Error creating')
29 1 . ELSE
30 1 BEGIN
31 2 I := 35;
32 2 S := 'THIS IS A STRING';
33 2 WRITE DATA;
34 2 CLOSE(F,I);
35 2 IF IORESULT = 255 THEN
36 2 WRITELN('Error closing')
37 2 ELSE
38 2 BEGIN
39 3 RESET (F);
40 3 IF IORESULT = 255 THEN
41 3 WRITELN( 'Error opening')
42 3 ELSE
43 3 READ_DATA;
44 3 END;
45 2 END;
46 1 END.

Listing.7-3. TEXT Pi1e·Processing

7-10
Pascal/MT+ Reference Manual 7.5 Sequential I/O

7.5.2 Writing to the printer


Listing 7-4 shows a typical way to write to the printer. The
program declares a file variable of type TEXT on line 5, and then on
line 11 "assigns this file variable to the printer. The filename
'LST:' passed to ASSIGN means that F is associated with the list.
device. All data written to F routes to the printer.
Next, REWRITE is called to open the list device for writing.
Lines 23 and 25 use standard Pascal formatting directives. Thus, on
line 23, R is written in a field seven characters long with three
digits to the right of the decimal place.
Once again, note that a CLOSE is not necessary because the dat~
was already written and the buffer does not need to be flushed.

Stmt Nest Source Statement


1 0 PROGRAM PRINTER;
2 0 (* WRITE DATA AND TEXT TO THE PRINTER *)
3 0
4 0 VAR
5 1 F TEXT;.
6 1 I INTEGER;
7 1 S STRING;
8 1 R REAL;
9 1
10 1 BEGIN
11 1 ASSIGN(F,'LST:') ;
12 1 REWRITE (F) ;
13 1 IF IORESULT = 255 THEN
14 1 WRITELN('Error rewriting file')
15 1 ELSE
16 1 BEGIN
17 2 S := 'THIS LINE IS A STRING';
18 2 I : = 55;
19 2 R := 3.141563;
20 2 WRITE(F,S);
21 2 WRI'rE (F, I) ;
22 2 WRITELN (F) ;
23 2 WRITELN(F,R:7:3) ;
24 2 WRITE(F,I,R) ;
25 2 WRITE(F,I:4,R:7:3);
26 2 WRITELN(F) ;
27 2 WRITELN(F,'THIS IS THE ENd.')
28 2 END
29 2 END.

Listing 7-4-. Wr i tinq to a Printer and NUJlber Pormatting

7-11
Pascal/MT+'Reference Manual 7 •.6 Random Access I/O

7.6 Random Access I/O

A random file is a typed Pascal file accessed with the random


access procedures SEEKREAD and SEEKWRITE. You can randomly access
any file by specifying the relative record number you want. This
differs from sequential access in which you must access record 0
before record 1, and so on. In Pascal/MT+, you can randomly access
up to 65,536 records.
With random files, a file that has been RESET can either be
read with SEEKREAD or written to with SEEKWRITE. Sequential files,
on the other hand, can be read only after a RESET. SEEKREAD can
access a new file created with REWRITE after you have writt'en data
to the file.
Sequential records within a file written with SEEKWRITE are
stored contiguously on the disk, regardless of the number of sectors
occupied by a record. Because of this, you can access a file
created using SEE~WRITE after a CLOSE and RESET using sequential
access methods.
After SEEKREAD or SEEKWRITE has accessed a file, you must CLOSE
the file and reopen it to access it with the sequential methods GET,
READ, PUT, and WRITE.
The sample program in Listing 7-5 called RANDOM_DEMO,
demonstrates random file access. This p~ogram creates or uses a
record fil~ of type PERSON. Each record in the file contains two
strings: the name and the address of a person. The loop betwe~~
lines 79 and 90 allows you to read any existing record with the
procedure READRECS, or to write to any record with the procedure
WRITEREC.
The main program begins on line 69 ~y asking if you want to
creat~ a file or open ~ne. After you respond, line 78 resets the
file. The repetitive loop allows reading and writing to continue
until you stop it with a Q input.
In this program, note that the procedure ERRCHK checks IORESULT
for errors encount~red in the operating system.
. - . .

The procedure READRECS asks for a record number, reads the


record from the file, and writes it directly from window variable to
the screen. Line 47 calls SEEKREAD and gives it the filename and
'record number. Line 51 writes the information.
Note that if record 0 and 2 contain data, you can attempt to
read record 1, even though it contains no data. Thus, you must be
careful when the system is unable to see errors in accessing
urtwritten records.

7-12
Pascal/MT+ Reference Manual 7.6 Random Access I/O

Note also that the window buffer works just as if it were


declared like a pointer to a record type. To save the data
elsewhere, you must make an assignment to a data structure of the
same type as the file, in this case type PERSON. For example,
VAR TEMP: PERSON; ••••••
••• TEMP := BF"';
The procedure WRITERECS asks you for the data it needs to fill
a record of type PERSON (lines 56 through 61), and for the record
number it should wr i te (lines 62 and 63). Then on line 64,
WRITERECS calls SEEKWRITE to write the data to the disk. -
Figure 7-2 shows how the file looks after wr i ting da ta to
records 0, 1, and 3.

Smith, John Brown, Susan tlJ'tIJ'1?tiJtIJ'tiJ .... Jones, Alan


Monterey Pacific Grove ........... Carmel
Record 0 Record 1 Record 2 Record 3

Figure 7-2. Records in a Pile

7-13
Pascal/MT+ Reference Manual 7.6 Random Access I/O

Stmt Nest Source Sta temen t

1 0
2 0 PROGRAM RANDOM_DEMO:
3 0
4 0 TYPE
5 1 PERSON. REX:ORD
6 1 NAME : STRING:
7 1 ADDRESS : STRING:
8 1 END:
9 1
10 1 VAR
11 1 BF : FILE OF PERSON:
12 1 S : STRING;
13 1 I : INTEGER;
14 1 ERROR: BOOLEAN:
15 1 CH : CHAR:
16 1
17 1 EXTERNAL PROCEDURE @HLT:
18 1
19 1 PROCEDURE HALT:
20 1 BEGIN
21 2 CLOSE (BF ,I) :
22 2 @HLT
23 2 END:
24 1
25 1 PROCEDURE ERRCHK:
7.6 1 BEGIN
27 2 ERROR : = TRUE: (*DEFAULT*)
28 2 CASE IORESULT OF
29 2 o : BEGIN •
30 4 WRITELN (' SUCCESSFUL');
31 4 ERROR : = FALSE;
32 4 END;
33 3 1 WRITELN (' READ ING UNWRI'rl'EN DATA'):
34 3 2 WRITEIN ('CP/M ERROR');
35 3 3 WRITELN('SEEKING TO UNWRI'rl'EN EXTENT');
36 3 4 WRITELN ('CP/M ERROR'):
37 3 5 WRITELN('SEEK PAST PHYSICAL END OF DISK')
38 3 ELSE
39 3 WRITELN (' UNREX:OGNIZABLE ERROR CODE : ' ,IORESULT)
40 3 END;
41 2 END:
42 1 .

Listing 7-5. RaDdom File I/O

7-14
Pascal/MT+ Reference Manual 7.6 Random Access I/O

43 1 PROCEDURE READRECS;
44 1 BEGIN
45 2 WRITE('RECORD NUMBER? I);
46 2 READLN(I) :
47 2 SEEKREAD(BF,I):
48 2 ERRCHK;
49 2 IF ERROR THEN
50 2 EXIT:
51 2 WRITELN(BFA.NAME,'/',BFA.ADDRESS):
52 2 END:
53 1
54 1 PROCEDURE WRITERECS;
55 1 BEGIN
56 2 WRITE ( 'NAME? ' ) ;
57 2 READLN(S):
58 2 BFA.NAME := S;
59 2 WRITE('ADDRESS?t) ;
60 2 READLN(S) i
61 2 BFA.ADDRESS := S:
62 2 WRITE('RECORD NUMBER?'):
63 2 READLN (I) ;
64 2 SEEKWRITE(BF,I)~
65 2 ERRCHK:
66 2 END;
67 1
68 1 BEGIN
69 1 WRITE('CREATE FILE?') ;
70 1 READLN (S) ;
71 1 IF S ( 1] IN (' Y' , 'y '] THEN
72 1 BEGIN
73 2 ASSIGN(BF,'BlG.FIL') ;
74 2 REWRITE (BF) ;
75 2 CLOSE(BF,I) ;
76 2 END;
77 1 ASSIGN(BF,'BIG.FIL') ;
78 1 RESET (BF) ;
79 1 REPEAT
80 2 WRITE('R)EAD,WrRITE OR Q)UIT? I);
81 2 READ (CH) ;
82 2 WRITELN;
83 2 CASE CH OF
84 2 'R' " r' READRECS:
85 3 'WI, 'Wi WRITERECSi
86 3 'Q', 'q' HALT
87 3 ELSE
88 3 WRITELN('ENTER R, W OR Q ONLY')
89 3 END
90 2 UNTIL FALSE:
91 1 END.

Listing 7-5. (continued)

End of Section 7

7-15
. Appendix A
Reserved Words and Predefined Indentifiers

Pascal/MT+ Reserved Words


AND END LABEL PACKED TYPE
ARRAY FILE MOD PROCEDURE UNTIL
BEGIN FOR MODEND PROGRAM VAR
CASE FORWARD MODULE RECORD WHILE
CONST FUNC'rION NIL REPEAT . WITH
DO GOTO NOT SET
DOWNTO IF OF THEN
ELSE IN OR TO

Pascal/MT+ Predefined Identifiers


@BDOS CLRBIT INSERT PRED SQRT
@BDOS86 . CONCAT INTEGER PURGE STRING
@CMD COpy IORESULT PUT SUCC
@ERR COS LENGTH READ SWAP
@HERR CREATE LO READHEX TEXT
@HLT CSP LONG READLN TRUE
@MRK CSPF LWRITEHEX REAL TRUNC
@RLS DELETE MAXAVAIL RESET TSTBIT
ASS DISPOSE MAXINT REWRITE WAIT
ADDR EOF MEMAVAIL RIM8S WNB
ARCTAN EOLN MOVE ROUND WORD
ASSIGN EXIT MOVELEFT SEEK READ WRD
BLOCKREA EXP MOVERIGHT SEEKWRITE WRITE
BLOCKWRI FALSE NEW SETBIT WRITEHEX
BOOLEAN FILLCHAR ODD SHL WRITELN
BYTE GET OPEN SHORT XIO
CHAIN GNB OPENX SHR XLONG
CHAR HI ORD SIM8S
CHR INLINE OUT SIN
CLOSE INP PAGE SIZEOF
CLOSEDEL INPUT POS SQR

End of Appendix A

A-l
Appendix B
Pascal/ MT+ Syntax

Backus-Naur Form (BNF) notation uses the following conventions:

• ::= The expression on the right of this symbol defines the


item on the left. You can pronounce the symbol "is rewritten
as" or "is defined as. II

• I A ver tical bar ind icates a choice between the items it


separates. Pronounce it "or."

• { } Items within braces are optional. They can be repeated 0


or more times.

• < > Items within angle brackets are self explanatory or


further defined in the syntax specifications.

• Items not in angle brackets are literal; enter them as they


appear.

For example,

<idehti~ier> ::= <letter> {<letter> I <digit> 1_ }


states that an identifier is a letter followed by 0 or more letters,
digits, or underscores.

End of Appendix B

B-1
Appendix C
Differences From ISO Standard

The following list summarizes the additions to ISO standard


Pascal that are implemen ted in Pascal/MT+.

• Additional predefined scalars: BYTE, WORD, LONGINT, STRING.


• Expressions can contain input from I/O po~ts.
• Assignments can be made to I/O ports.
• Operators on integers & (and), 1, I (or), and - ,\,1 - (not).
• CASE drops through on no match.
• ELSE on CASE statement.
• Interrupt, External, and Assembly Language procedures.
• BCD fixed point and binary floating-point reals.
• Long and shor t INTEGER da ta types.
• Modular compilation facilities.
• Redirectable I/O facilities (user written character I/O).
• Additional built-in procedures and functions:
- bit and byte manipulation,
- fast file I/O,
- random file access,
- move and .fill procedures,
- address and size of functions,
- string manipulation,
- heap management facilities.
The following list summar izes the differences between ISO
standard Pascal and Pascal/MT+..

• Identifiers are significant in only the first 8 characters.


• Variables are not packed at the bit level.
• The order of declarations can vary~
• The null string is allowed.
• CHAR is not implemen ted as ISO str ing because var iable-leng th
strings are supported (PACKED ARRAY [l •• n] OF CHAR).

End of Appendix C

0-1
Appendix D
Bibliography

Conway, Richard, David Gries, and E. Carl Zimmerman. A Primer on


Pascal. Cambridge, Massachusetts: Winthrop Publishers, 1976.

Draft Proposal ISO/DP 71851 Programming Languages-Pascal. Can be


obtained from Amer ican National Standards Institute,
International Sales Department, 1430 Broadway, New York, New
York, 10018.
Not designed for the novice. A precise language definition.

Findlay, William, and David A. Watt. P~SCAL: An Introduction to


Methodical Programming. Potomac, Maryland: Computer Science
Press, 1978.
Grog.ono, Peter. Programming in Pascal. Read ing, Massachusetts:
Addison-Wesley, 1978.
A good introduction for self-teaching.

Jensen, Kathleen, and Niklaus Wirth. Pascal User Manual· and


Report. New York: Springer-Verlag, 1974.
First definition of Pascal. Best used as a reference document.

Miller, Alan R. Pascal Programs for Scientists and Engineers.


Berkeley, Ca.: Sybex, Inc. 1981.

Wilson, I.R. and A.M. AddYman. A Practical Introduction to Pascal.


New York: Springer-Verlag, 1979.
Advanced textbook.

End of Appendix 0

0-1
Index

, 2-1, 7-:-2 Boolean values,


@BDOS, 6-69 TRUE, FALSE, 3-3, 5-6, 5-7,
@BDOSS6, 6-70' 5-8, 6~30, 6-41, 6-49,
@CMD, 6-71 6-64, 6-66, 6-67, 7-6, 7-9
@ERR, 6-72 BOOLEAN,
@HLT, 6-73 data type, 3-3
@HERR, 6-74 bounds in a subrange, 3-6
@MRK, 6-75 interval in a set, 4-6
@RLS, 6-76 set's base type, 3..... 9
BYTE,
A data type, 3-5

absolute value, 6-11 c


actual parameters, 6-3
AND, CASE statement, 5-2
Boolean operator, 4-4 in a variant record, 3-11
angle, CHAR,
arctangent of, 6-13 data type, 3-3
cosine of, 6-22 character array manipulation
sine of, 6-58 routines, 6-8
arithmetic, CHR,
expressions, 4-3 pseudo-function, 3-3
functions, 6-8 command line, 6-71
operators, 4-1 command tail, 6-71
array bounds, comments, 1-6
. upper, lower, 3-7, 6-6 compiler, 1-6, 3-1,3-2, 3-7,
elements, 3-7 3-S, 5-6, 5-9, 6-44, 6-50
indexing, 3-4, 3-7 command-line option, 3-5
subrange, 3-7 conunand-line option @, 3-6
type definition, 3-7 concatena~ion, 6-20
ASCII character set, 3-2, 7-9 conformantarrays~ 6-6
value, 4-4, 6-1S, 6-50, 6-67 constant, 2-2
value of a character, 3-3 control variable in a FOR
assignment operator, 5-1 DOWNTO statement, ~-4
statement, 5-1, 5-9, 6-2 control variable in a FOR
statement, 5-3
B cosine, .
of an angle, 6-22
BCD, CP/M filename, 6-42
real numbers, 3-5
bit and byte manipulation D
routines, 6-8
block, 1-1, 1-5, 3-1, 5-4, 6-5 data conversion, 3-4
BLOCKREAD, 6-16 data type CHAR, 3-3
BLOCKWRITE, 6-16 data type,
Boolean eXDression. 4-3, 5-6, BOOLEAN, 3-3
5-7, 5:S . BYTE, 3-5 .
Boolean operator compatibl~, 4-5,6-3
AND, OR, NOT, 4-4 CHAR, 3-3
enumerated~ 3~2
INTEGER, 3-4 .

Index-l
LONGINT, 3-4 6-53, 7-1, 7-2
ordinal, 3-5, 5-2, 5-4 fixed-point format, 2-3
pointer, 3-6 floating-point,
record, 3-10 format,
scalar, 3-1 real numbers, 3-5
sets, 3-9 FOR DOWNTO statement, 5-4
short, 3-4 FOR statement, 5-3
simple, 3-1, '5-4 formal parameters, 6-3
structured, 3-1, 3-7 FORWARD declaration, 6-2
subrange, 3-2 fragmentation, 6-37
WORD, 3-5 free variant, 3-12
decimal integer, 2-2 function, 1-1, 1-4, 6-1, 6-2,
declaration section, 1-1, 6-2 6-27
default length of a string, 3-8 FUNCTION,
definition section, 1-1 @BDOS, 6-69
device names, 6-14 @BDOS86, 6-67
DIV operator, 4-3 @CMD, 6-71
DO, @HERR, 6-74
reserved word, 5-3 @MRK, 6-75
dot operator, 3-11 @RLS, 6-76
dynamic allocation, 6-9, 6-24, ABS, 6-11
6-37,6-40 ADDR,6-12, 7-6
dynamic strings, 3-8, 3-9 ARCTAN, 6-13
CHR, 6-18
E CONCAT, 6-20
COPY, 6-21
element of a structure, 5-4 COS, 6-22
empty statement, 5-3 EOF, 6-25, 6-49, 6-53, 6-66,
end-of-file-indicator, 7-2 7-2, 7-6
end-of-line indicator, 7-9 EOLN, 6-25, 6-53, 7-6
environment, EXP, 6-28
CP/M, 6-54, 7-13 GNB, 6-66
exponentiation, 2-3, 4-3, 6-28, HI, 6-31
6-67, 7-10 IORESULT, ,6-34, 6-42, 6-52,
expres.ions, 4-1, 5-1, 5-4 7-13 .
external, LENGTH, 6-35
devices, 7-1 LN, 6-36
filename, 6-14 LO, 6-31
EXTERNAL FUNCTION INPORT_W, MAXAVAIL, 6-37
7-5 MEMAVAIL, 6-37
identifiers, 2":2 ODD, 6-41
EXTERNAL PROCEDURE OUTPRT W, ORO, 6-43
7-5 - POS, 6-46
PRED, 6-47
p RIM85, 6-54
ROUND, 6-55
FALSE, SHL, 6-57
BOOLEAN value, 3-3 SHR, 6-57
fields, SIN, 6-58
elements ofa record, 3-10 SIZEOF, 6-59
names ina record, 3-11 SQR, 6-60
fil~s, 3-1, 4-3, 5-1, 6-19 SQRT, 6-61
buffer, 7-1, 7-2, 7-3, 7-12 SUCC, 6~62
Information Block, 7-1, 7-9 SWAP, 6-31
variable, 6-14, 6-48, 6-50, TRUNC, 6-63

Index-2
TSTBIT, 6-64 members of a set, 4-6, 5-1
WNB, 6-66 miscellaneous functions, 6-10
G MOD operator, 4-3
MODEND,
garbage collection, 6-37 reserved word, 1-5
global, module, 1-4
declaration, 1-5 MODULE,
scope, 2-2 reserved word, 1-5
GOTO statement, 5-2, 5-5 mutually recursive procedures,
6-1
N
hardware ports, 7-5, 7-6
heap, 6-37, 6-54 named constant, 2-3, 3-6, 6-38,
hexadecimal integer, 2-2 6-65 -
named constants, 6-67
I native machine word, 3-3
natural logarithm, 6-28, 6-36
identifier, 1-3, 1-5, 2-1, 3-11 nested block, 1-1, 1-5,
IF statement, 5-6 procedure, 6-12
indexes for arrays, 3-4 variants, 3-11, 6-40
inner block, 1-5 nested WITH statements, 5-9
INP, nesting comments, 1.-6
predeclared array, 7-5 NIL,
input/output routines, 6-9 pointer value, 3-6
INTEGER, nonvariant record, 3-10
data type NOT,
literal, 2-2, 3-4 Boolean operator, 4-4
internal data representation, null pointer, 3-6
3-4, 3-5 numeric literal, 2-2
L o
label, ODD,
on a GOTO stat~ment, 5-5 pseu~o-function, 3-3
on CASE statements, -5-2 one's complement NOT, 4-5
least-significant bit, 3-3 operator, 4-1
l~ngth of identifiers, 2-1 arithmetic, 4-1
LENGTH, . assignment, 5-1
'predefined function, 3-8 Boolean, 4.;..2
local declaration, 1~5 logical, 4-2
logical expressions, 4-5 precedence, 4-1
logical operators, 4-2 relational, 4-2
AND, OR, one's complement NOT, set, 4-3
4-5 OR,
long· integer, 2-2 Boolean operator, 4-4
long integer. literal, 2-3 ORO,
LONGINT, pseudo-function, 3-3
data type, 3-4 ordinal,
literal data types, 3-2, 3-5
type. 3-2, 3-6, 3-9, 5-2, 5-4,
M v~iue, 3-6, 6-43, 6-47
ordinal value of FALSE, 3-3
mai.n program block, 1-1, 1-4 ordinal value of TRUE, 3-3
ma~n v~riant,3~12 OUT,

Index-3
predeclared array, 7-5 @HLT, 6-73
outer block, 1-5 ASSIGN, 6-14, 6-53, 7-2, 7-12
outermost block, 1-1 CHAIN, 6-17
over flow, 4-3 CLOSE, 6-19, 6- 52, 6- 56, 7-10,
over lays, 6-12 7-12, 7-13
CLOSEDEL, 6-19
p CLRBIT, 6-64
DELETE, 6- 23
packed structure, 3-3 DISPOSE, 6-24, 6-4:0
~ PACKED, EXIT, 6- 27
reserved word, 3-7 FILLCHAR, 6-29
parameters, GET, 6- 30, 6- 52, 6- 66, 7- 2,
variable, 6-4 7-3, 7-9
Pascal statements, 5-1 INLINE, 6-32
passing arrays to procedures, INSERT, 6-33
6-6 LWRITEHEX, 6-51
passing procedures and MOVE, 6-38, 6- 59
functions, 6-4 MOVELEFT, 6-38
pointer character, MOVERIGHT, 6-38
.... , 2-1, 3-6, 7-2 NEW, 6-40
pOinter type compatibility, 3-6 . OPEN, 6-42, 7-2
poin ter, PACK, 6-44
data type, 3-6 PAGE, 6-45
null, 3-6 PURGE, 6-48
precedence of operators, 4-1, 4-4 PUT, 6-49, 6-66, 7-2, 7-3, 7-9
predecessor of a scalar, 6-47 READ, 6-50, 7-3, 7-9
predeclared arrays, READ HEX , 6- 51
INP, OUT, 7~5 READLN, 6-50, 7-6; 7-9, 7-10
predefined data type, RESET, 6-14, 6-52, 7-2, 7-13
STRING, 3-8 REWRITE, 6-14, 6-53, 7-12
predefined function, RIM85, 6-54
LENGTH, 3-8 SEEKREAD, 6-56, 7-13
predefined functions and SEEKWRITE, 6-56, 7-13
procedures, SETBIT, 6-64
ar ithmetic, 6-8 UNPACK, 6-44
bit and byte man ipu1ation WAIT, 6-65
routines, 6-8 WRITE, 6-67, 7-3, 7-9
character array man ipulation WRITEHEX, 6- 51
routines, 6-8 WRITELN, 6-67, 7-7, 7-9
dynamic allocation routines, 6-8 pr09ram,
input/output routines, 6-8 heading, 1-2
string handling routines, 6-8 parame ter s, 1-2
transfer functions, 6-8 pseudo-function, 3-2
miscellaneous routines, 6-8 CHR, 3-3
predefined identifier, 1-3, 2-2 ODD, 3-3
predefined simple data types, ORO, 3-3·.
3-2 WORD, 3-3
pr in table charac ter, 2-3, 3-3 pseudo-functions, 6-21
procedure, 1-1, 1-4, 6-1, 6-27
procedure definition, 6-2 Q
procedure parameters,
ac tual, formal, 6- 3 quotien t, 4- 3.
procedure-oriented language, 6-1
PROCEDURE,
@ERR, 6-72

Index-4
R CASE, 5-2
compound, 5-1
random access I/O, 6-56, 7-1, 7-13 empty, 5-3
random record number, 7-13 FOR, 5-3
real number, 2-2, 3-5 FOR DOWNTO, 5-4
real-number literal, 2-3 GOTO, 5-2, 5- 5
record, IF, 5-6
da ta type, 3-10 Pascal, 5-1
recursive procedures, 6-1 REPEAT, 5-7
redirected I/O, 7-5, 7-6 WHILE, 5-8
relational operators, 4-2, 4-3 WITH, 5-8
relational operators on sets str ing,
IN, =, < >, < =, >= , 4- 6 handling routines," 6-10
r-emainder, 4-3 indexing, 3-8
REPEAT statement, 5-7 literal, 2-3, 3-9, 6-20
reserved word PACKED, 3-7 s ta tic, 2- 9 , 3- 9
reserved word, zero-leng th ,6- 20
DO, 5-3 STRING,
----- PACKED, 3-7 predefined data type, 3-8
reserved words, 2-2 strong type check, 3-2, 3-6
run-time entry points, 2-2" structured data types, 3-1
arrays, records, sets, files,
s 3-7
structured type, 6-67, 7-1
scalar data type, 3-1, 5-4 subrange, 3-5, 3-6
scalar type, 6-43, 6-62 subrapge data types, 3-2, 3-9,
scientific tlotation, 2-3 5-1, 6-62, 6-67
scope, 1-5, 2-2, 5-5, 6-12 successor of a scalar, 6-62
global, 1-5 syntax, 5-1
local, 1-5
of a CASE sta temen t, 5- 2
of a control variable, 5-4
semicolon TEXT file, 6-14, 6-50, 6-67, 7-9
as a valid sta temen t, as a transfer functions, 6-10
statement'separator, 5-3 TRUE,
statement separator, 1-4 BOOLEAN value, 3-3
sequential I/O, 7-1, 7-9 FALSE, Boolean values, 5-6, 5=7,
set constructor, 4-5 5-8
set expressions, 4-3, 4-5 type check ing, 3- 2, 6- 38, 6- 50
set opera tions, type conversion, 3-2
un ion, in te·r sect ion, type conversion functions,
difference, 3-9 FUNCTION SHORT, 3- 4
set operators, 3-9, 4-3 FUNCTION LONG, 3-4
. +, *, - . pp, 4- 6 FUNCTION XLONG, 3-4
set type d~finition, 3-9 type convers ion opera tor, 3- 2
sets, type definition, 3-1
data type, 3-9 nonvar ian t record, 3-11
short data type, 3-4 ·variant record, 3-12
!) imp le da ta type, 3-1, 5- 4
simple type, 4-3, 7-1
sine of an angle, 6-58
square root of a number, 6-61
statements
assignment, 5-1
statements, 1-4

Index-5
u
up-level reference, 1-5
user-defined ordinal type, 3-5,
6-59
user-defined ordinal types,
6-12
v
value parameters, 6-3
variable,
address, 6-12
allocation of space, 3-1
declaration, 3-1
pa r a me te r , 6- 3
variant record, 3-10, 6-40
w
weak type check ing, 3-6
WHILE statement, 5-8
window variable, 6-25, 6-30,
6- 49 , 6- 5 2 , 6- 56, 7 -1, 7 - 9
WITH sta temen to' 5-8
WORD,
da ta type, 3- 5
pseudo-funct:on, 3-3

Index-6
Reader Comment Form
We welcome your comments and suggestions. They help us provide you with better
product documentation. .

Date _ _ _ _ _ Manual Title _ _ _ _ _ _ _ _ _ _ _ Edition _ _ __

1. What sections of this manual are especially helpful?

2. What suggestions do you have for improving this manual? What information
is missing or incomplete? Where are examples needed?

3. Did you find errors in this manual? (Specify section and page number.)

COMMENTS AND SUGGESTIONS BECOME THE PROPERlY OF DIGITAL RESEARCH.


----- ---~. -:...----------------- ------

NO POSTAGE
NECESSARY
IF MAILED IN THE
UNITED STATES

BUSINESS REPLY MAIL


FIRST CLASS I PERMIT NO. 182 I PACIFIC GROVE, CA

POSTAGE WILL BE PAID BY ADDRESSEE

I!ID DIGITAL RESEARCH'"


P.o. Box 579
Pacific Grove, California
93950

Attn: .Publlcatlons Productlor

You might also like