Ithaca_Pascal Z_Ver_4.0_Nov81 Ithaca Pascal Z Ver 4.0 Nov81

Ithaca_PascalZ_Ver_4.0_Nov81 Ithaca_PascalZ_Ver_4.0_Nov81

User Manual: Ithaca_PascalZ_Ver_4.0_Nov81

Open the PDF directly: View PDF PDF.
Page Count: 137

DownloadIthaca_Pascal Z_Ver_4.0_Nov81 Ithaca Pascal Z Ver 4.0 Nov81
Open PDF In BrowserView PDF
ITHACA INTERSYSTEMS

PASCAUZ
PASCAUBZ
USER'S MANUAL
VERSION 4D

CI

Copyright 1981 JEFF MOSKOW
Revised 11/1/81

ITHACA INTERSYSTEMS
PASCAL/Z AND PASCAL/SZ
USER'S MANUAL
VERSION 4.0

(c)

by

Copyright 1981
Jeff Moskow

Revised 11/1/81

COPYRIGHT NOTICE.

... ...... ... .. .. .. . . . .... . . . .. . . . •• 1

INTRODUCTION ••••••••••••••••••
•• ~ •2
PASCAL/Z OBJECTIVES ••••••••• -.-.
• .' ~ ~ 3
IMPLEMENTATION FEATURES •••••••••••••••••
· . •. 4
EXTENSIONS TO THE STANDARD LANGUAGE ••• -•••
.4
PASCAL/Z RESTRICTIONS ••••••
.5
SYSTEM REQUIREMENTS ••.•••••
•• 6
RECEIVING INSPECTION •••••••
• •• 7
Contacting Intersystems ••••
• •• 8
CONTENTS OF THE PASCAL/Z DISTRIBUTION DISKETTE. • . • • • 9
CONTENTS OF THE PASCAL/Z LIBRARY DISKETTE ••
• ••• 10
JENSEN & WIRTH EXAMPLE PROGRAMS ••••••••
• .12
GETTING STARTED ••••••••••••••••••••••••
..13
INTRODUCTION TO PASCAL ••••••••••••••••••
• •• 14
Declarations & Definitions •••••••••••
• •• 15
Intrinsic Constants & Data Types ••••
• •• 16
Scalar Data Types •••••••••••••••••
• •• 17
Structured Data Types •••• ~ ••••••••
• •• 18
The Pointer Type •••••••••••••••••••••
..••• 20
Constants •••••••••••••••••••••••••••
• •• 22
Variables ••••••••••••••••••••••••••••
• •• 23
Global & Local Variables ••••••••••••
• •• 23
Accessing Variables •••••••••••••• ; ••
• ••• 24
Assignment Statements ••••••••••••••••••
• •• 25
Repeat & While Statements.....
• ••••
••• 26
For Statements ••••••••••••••••
.26
Conditional Statements.; •••••••••••••••
• •• 27
Compoound S ta temen'ts •••' • • • • •
• •••••••
• ••• 28
With Statements •• o.....................
.-.. 29
Procedures & Functions..............
• •••••••• 30
Pascal Standard Functions •••••••••••••••
31
Pascal Standard Procedures.................
• •• 31
Program Structure & Use of Semi-Colons •••••.•••• 32

...

0

• • • • • • • •

THE PASCAL/Z COMPILER •••••••••••••••••••••
The Symbol Table ••••••••••••••••••••••
The Type Table ••••••• ~ ••••••••••••••••
COMPILER OPTIMIZATIONS ••••••••••••••••
VOCABULARy •••••••••••••••••••••••••••
PASCAL SPECIFICATIONS & LIMITATIONS ••••
Specifications ••••••••••
Limitations •••••••••••••••••••••••••
COMPILER OPTIONS •••••••••••••••••••••••
OPTIMIZING PASCAL/Z PROGRAMS FOR SPEED •••••
.
PASCAL/Z TYPE DECLARATIONS.
HOW TO RUN PASCAL/Z ••••••••••••••••••••••• ' •••••

.34
.34
• •. 34

••• 36

.37
• ••• 38
• •• 38
• ••• 40

..41
••. • 43
• ••• 44

• ••• 46
COMPI LE. SUB ••••••••••••••••••••••••••••••••••••• 48

INTERPRETING PASCAL/Z LISTINGS & ERROR MESSAGES. • •• 50
Run-Time Errors -- Stack Overflow •••••••••••• ••• 51
PASCAL/Z INPUT & OUTPUT.
• ••• 53
DIRECT FILE ACCESS •••••••••
• ••••..• . 58
RENAME & ERASE •••••••••••••
• .59
DEVICE INPUT & OUTPUT ••••••
• •• 60
PASCAL/Z EXTENSIONS ••••••••••••
• ••• 61
Pascal/Z Constants •••••
• .63
Pascal/Z Functions •••••
..64
Pascal/Z Strings ••••••••••••••••••
• ••• 66

...... . .

Pa sea liZ CAS E S ta temen t •••••• ,••••••"••••• '•••••••• 69
,S epa rat e Com p i 1 a t'i 0 n .". • • • • .,." •.• ,.. • • •"': • • • • • • • • • • • • 7 0
Paseal/Z External Routines ••••••••••••• ~~ ••••••• 74

ov e r 1 a y i rig ••• ~ • .' •-." ....... '••• '.'." ••••••••••••••••••• 7 9

INCLUDE Files •.' •. • :".<~.':.:.• -' ••••• '.'." ••••••••• ' ••••••••• • 85
CHAINING ••••.•••••••••• ~ •••••• • -•••••••••••••••.•••• 86
PASCAL!Z POINTERS •••• '••••••• ." "'.~~ •••• '.••...•••• ~ '•••••• 87
>

•

,-

~,:

::"

'-,'.-

,,~

~-'

PASCAL/Z FLOATING POINT NUMBERS ••.••••••••••••.•.•. 89
FORMATTING OUTPUT ..................... '••••.••••••••.•• 90
ASSEMBLER & LINKER ERRORS ••••••••• '•••••..•••••••.•• 92
MEMORY USAGE ••••••••••••••••••••••••••• ~ ••••••••••• 93
STACK & HEAP ORGANIZATION •••••••••••••••• ~ •••••••.• 95
INSTALLING PASCAL/Z PROGRAMS IN ROM •••.••.•••••..•• 96
APPENDICES . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . '. • . • • . • . . . . . 97

Appendix
Appendix
Appendix
Appendix
Appendix
Appendix
Appendix

One -- Parameter Stack Configurations~.97
Two -- Troubleshooting ••••..•.•••••••.. 98
Three -- Fixed Point Paekage ••••.••••• l01
Four -- Pascal/Z Users' Group ••••••••• 108
Five -- Warranty ••••••••••.••••••••••• 109
Six -- Error Messages ••••••••••••••••• 110
Seven -- Paseal/BZ •••••••••••••••••••• 114

PASCAL/Z COMMENTS & BUG'REPORTS •••••••••••••••••.. 121
INDEX,

Page 1 -

Pascal/Z User's Manual
,COPYRIGHT NOTICE

'This
copyrighted
software
product
is
distributed
exclusively by ITHACA INTERSYSTEMS for the use of the
original purchaser only, and no license is granted herein to
copy, duplicate, sellar otherwise distribute to any other
person, firm or entity.
Further, this software product and
all forms of the program are copyrighted by JEFF MOSKOW, and
all rights are reserved~'
Wherever referred to throughout these manuals, CP/M and Z-80 are
registered trademarks of Digital Research and Zilog, Inc.,
respectively.

Page 2,

Pascal/Z User's Manual
INTRODUCTION
Pascal was designed in 1971'-by Niklaus Wirth to:

" .•• make available a language suitable to teach programming
as
a
systematic
discipline...
(and)
to
develop
implementations of this language which are both reliable and
efficient on presently available computers."
I

The Ithaca InterSystems, Inc.
Pascal/Z compiler w~s designed to
compile programs written in the Pascal
language
into Z-80
macro-assembler code.
Its design closely follows that of Jensen
and Wirth's Pascal User Manual and Report
(Second "Edition).
Pascal/Z is presently available to run under Digital Research's
CP/M operating sy~tem.
The Pascal/Z software package includes object code for tne
P,ascal/Z compiler in both 48K and 54K versions, object" code for
the debugger
(InterPEST), the assembler
(ASMBLE/Z)" and the
linker/loader (LINK/Z), and both object code and,commented source
code for the library routines.
Also on the diskettes are several
example programs, including the .PAS and .COM files for the"
exar.1ple prog rams in the Jensen & Wi rth USER MANUAL AND REPORT,
and some utility programs to facilitate using
the Pascal/Z
package.
Documentation includes the Pascal/Z
Implementation
Manual, the InterPEST Reference Manual, the ASMBLE/Z and LINK/Z
manual.s, and the Jensen & Wirth USER MANUAL AND REPORT.'

Page 3

" Pascal/Z User' s Manual
PASCAL/Z OBJECTIVES

Pascal/Z is a recursive descent Pascal compiler for the Z-80, and
was designed to be useful in a variety of environments.
Our
design objectives were:
I} To run resident on a Z-80.
2}'To. generate ROM-able re-entrant code.
3) To ~reate a compiler which could be easily re-hosted for use
as a cross-compiler.
4) To write the compiler in Pascal for ease of maintenance and
reliability.
5} To write a compiler which could be easily
generate code for the new 16 bit processors.
6) To produce code which is
amount of threaded code.
7) To add extensions
pros ramming.

efficient

necessary

for

and

to

industrial

modified
minimize

and

to
the

scientific

While objectives one throu9h six are straightforward, our seventh
objective
is m~ch more difficult
and
1S
constantly being
reconsidered.
The extensions which have been added were added
only if they allowed the user to easily do something that
previously would have been impossible or awkward; or if they
greatly increase the readability of Pascal programs.
In all
cases we have striven to maintain the "spirit" of Pascal.

Pascal/Z User's Manual

Page 4

IMPLEMENTATION FEATURES

*

The code generated
r e- en t ran t' ~

by

Pascal/Z

is

both,

ROM-able

and

*

Dedicated Pascal/Z programs may be as small as a few hundred
bytes.

*

The compiler generates code optimized for a 2-80 processor
and takes advantage of special cases.

*

macro assembly code
is generated
includes Pascal source lines as comments
peephole optimization if desired.

*

Pascal/Z supports separate compilation of user programs in
order to reduce the time to re-compi Ie, re-assemble and
re-link large programs.

*

Overlays are supported to permit
larger than system memory size.

*

InterPEST (InterSystems Pascal Error Solving Tool),
interactive symbolic debugger designed specifically
isolate and correct faults in a Pascal/Z program.

and optionally
to allow user

2-80

execution

of

programs
an
to

EXTENSIONS TO THE STANDARD LANGUAGE
speed

program

versatile

EXTERNAL

*

Separate
compilation
development.

*

Assembly
routines.

*

INCLUDE files allow insertion of any file within a Pascal/Z
program.

*

Overlay capabilities provided.

*

A STRING type is provided.

*

Direct File Access (random access)

*

An ELSE clause is allowed with the CASE statement.

*

Symbolic I/O of enumeration
interactive programs.

*

Integer constants can use the operators +, CONSTI = CONST2 DIV CONST3) •

*

Functions may now return structured types.

language

to

permitted

interface

allows

is supported.

types

immensely

*

simplifies
DIV (i.e.,

Page 5

Pascal/Z User's Manual

*

TIME/SPACE optimization
CASE statement •

is

user

selectable when using

the

. - See page 61 for more detail on Pascal/Z extensions.
PASCAL/Z RESTRICTIONS

*

GOTO may not leave a block (procedure or function).

*

Standard GET/PUT I/O is not implemented.

*

Procedural parameters not implemented. A procedure/function
cannot
be
passed
as
a
parameter
to
another
procedure/function.

*

Dynamic storage is implemented
rather than NEW and DISPOSE

*

The PAGE routine is not implemented.

using NEW, MARK and RELEASE

. See page 40 for more detail on Pascal/Z restrictions.

Page 6

Pascal/Z User's Manual
SYSTEM REQUIREMENTS

Pascal/Z runs under the Digital Research CP/M Operating System.
We recommend version 2.2, since earlier versions of CP/M did not
implement Random File Access, and thus the Random Access (called
Direct File Access in Pascal/Z) capabilities of Pascal/Z would be
lost when using any early release of CP/M.
While a compilation is in progress, Pascal/Z requires 48K of RAM
for itself (54K for the non-overlaying version), plus additional
memory for the operating system - usually 8K in the- case of
CP/M.
However, after a program has been compiled, assembled and
linked the actual program module may be considerably less than
lK.
The' system must also have at least one disk drive while compiling
.since all compilations read a Pascal source file from the disk
and output the resulting macro code to the disk.
A 64K system with two
program development.

disk

drives

is

recommended

for

Pascal

'Pascal/Z User's Manual

Page 7
RECEIVING INSPECTION

When your Pascal/Z diskette arrives, inspect both the diskette
and the shipping carton immediately for evidence of damage during
shipping.
If, the shipping' carton is damaged or water-stained,
request the carrier's agent to be present when the carton is
opened.
If the carrier's agent is not present when the carton is
opened, and the contents of the carton are damaged, save the
carton and packing material for the agent's inspection.
Shipping
damages should be immediately reported to the carrier.
We advise that in any case you should save the shipping container
for ~se in returning the module to InterSystems, should it become
necessary to do so.
Factory Service
Your Pascal/Z compiler comes with updates for one year from the
date of original purchase.
These updates are available for a
nominal copying charge.
Contact InterSyste~s for details.
Before returning the diskette to InterSystems, for any reason,
first obtain a
Return Authorization Number
from our Sales
Department.
This may be done by calling us, sending us a TWX, or
by writing us.
After the return has been authorized, proceed as
follows:
1) Include an explanatory letter.
2}

Include
a
listing
of
the
malfunctioning
program
or
operation.
If no
listing is enclosed we can make no
guarantee regarding correction of the error, since it may be
impossible for us to duplicate the problem without a listing
illustrating
the
malfunction.
YOU
CAN
EXPECT
AN
ESSENTIALLY IMMEDIATE. RESPONSE IF YOU 'INCLUDE· A LISTING.
Please send the smallest program which demonstrates the
'error so that we may isolate and correct the problem in the
shortest possible time.
If you are working with standard
8", soft-sectored, single density CP/M compatible diskettes,
sending the program on disk in addition ,to the listing would
also be helpful.
All materials will be returned to you upon
request once the problem has been diagnosed.

3) Include the Return Authorization Number.
4) Pack the above information
method of shipment.

in

5) Ship prepaid to InterSysterns.

a

container

sui table

to

the

Page 8

Pascal/Z User's Manual
Contacting InterSystems:
The following apply.-for both correspondence and service.
Ithaca InterSystems Inc.
1650 Hanshaw Road
P.O. Box 91
Ithaca, New York 14850
U.S.A.
Telephone
TWX

(607) 257-0190
510 255-4346

In Europe:
Ithaca InterSystems (U.K.)
58 Crouch Hall Road
London N& 8HG U.K.
Telephone
Telex

01-341-2447
299568

Ltd.

::"P,age ·9

. Be fo re:d.o in~"··a.riy·th1.rig· 'wr' th '-y~::~r': ·pa:~~·al:/-Z";:·"d:fs'k:~·tte:s.~::-~MAKE~;A: BACKUP
COPY ..0 F.. '" E'ACH ~DI.s,K:ET,TE. '.' 'Us·e. '.:,th·eO:':~ :,.:back\ip<·.:~:for ...' all·' .0 f
yo ur
prog'rammlng ~ e.ffor·ts·· to elim.i.n·a.t.e,,·t'h-e· po·ssTb11i"tY .. ·of.... d.e's,tr·oy.ing
th'e d'i str..i·butlo:n·',.:di~s-ke·t te:"'- i·t· i,s'" i.n· . ·, yo:u;r,:·.:be:s·t' 'inte-r,e.$ts." NEVER TO
WRITE ON' THE ·]j·ISTRIBUTION, D1-SI.·th:e compiler,
i'nstead of o'r fn' ·o·ddi..t.io-n, ... ·to ~ Pa'scal/Z ~ . s'e'e Append:i.x·· S-even for
information.'
.
T.he first, ,si-d'e .. o·f .:yo·ur. ··P·s,sc·al/Z", ··Ma·s'te.r,··,Di·s-k-ette
follow i ng f i 1 e s :
PASCAL 4·8·~ COM
PAS248'
PASCA'L54·. C·OM·
PAS254
DECS

PFSTAT
DEBUG. REL
HOWTO.·,RUN

HELLO. PAS
COM·PI L·E • .5 UB.·

LIB. REL
MAI'N. SRC
EMAIN. SRC.

XMAIN.SRC

XEMAIN.SRC

ASMBL. COM
LINK. COM
INFO.NEW

contains

the

A· p-reli,mtnary :p-r'o-gram which loads PAS248
The .ac:t~ual-:·c:om'p':i.le rOo (-ove'rla'yi ng ver s ion)
'Th'e54K ver.s·{on of PASCAL. COM
Th-e' ":54'K"v'e-rsio:ri' of . PAS 2..
Ove·rlay: .... m·o·dtil,e··:·~·f-o:r;· the:' 4-8K>. ve.r.s-ion of the
:c'omp-fi'e'r::" '.
.
Over,l.ay module fo r t'he' 4'8K ver:s'io'n 0 f the
'(;'otirpflei .: .'
",
The "Lnterclctive . 'symbol ic. debugg'e'r, InterPEST
(InterSystems Pascal Erro·r Solving Tool)
A descrip'cion of how to run the compiler,
·assembler and 1 inker
Demonstration program
·A· ·su·,bm-it macr'o .to".compi,le.,. assemble, 1 ink and
-r'Ut1'.· :.f'ascal,"· pro',g'r'am's' . fA
d'e'sc ri pt ion
0 f
'C OMPILE... SUB. :b eg Ln:s' .ci.n .':pa:g e' .4:9. ) ..
·T.h"e', :.Pa:s:c'a-l ···run,..··t·im-e s~ppo rt. 1 ib'r'a ry
DefinLtion.s and routin·e's· to b-e a'ssembled wi th
the' o~ut'put 0 f the c'omp'i l"e'r -. . '.. '
Ro·u.tin.e:s··:.· <·t·o ':- be
assembled
with
compiled
'ex'ternal . Pascal
r·o·l.ltine-s
and
s epa rat ely
:comp-l1e-d' :mod-ul es'
Def.in.i tions a'nd' routin'es to b'eas-sembled with
the output .. of the. compLIer.. when· usi-n-g the
debugger·.
Defini tio·ns and r'outines to' be ·as·se'mbled wi th
separa't'el y compi led m-od ul'e-s when us i ng the
d:ebugger "
Z":'80" Macro assembler· .... .
Rel06atable- linker/loader
Hot. in-fo·r.ma·tion not yet. inclu-d'ed
in the
manual
.
_.r

"-,

-:

The s'ecdn'd s'ide 0 f your.' Pascal./Z Mast'er ·d'isk·e t·te·.' cO'rita ins the
follow'ing·,·f:iles· for . the' ·Fix·e~'. po·in.t Package (see Appendix Three
for d eta i 1 s.) :
FIXED. PAS

FI XCONST. PAS·

.k collection ~f procedures which perform
signed
. a cbftr.ar'y: ":. pr ec.i.s ion . 'ar i thmet ic
in
. ··flxed"",:po··int.dec imal
, ;
." ,- " : ·De·c.:1;ar.-e-d,-,'-::···:con·-stants. :.:.fo.[ .·-the
'fixed-point
.. : . "p-ackage . '

Page 10

Pascal/Z User's Manual
FIXTYPE.PAS
FIXVAR.PAS
FIXEDEX.PAS

Declared types for the fixed-point package
Declared
variables
for
the ·fixed-point
package
Example for use of fixed point package

Also on this side of the Master Diskette are the following files:
PASOPT
CMAIN.SRC
OVLYGEN.COM
OVERLAY. SRC
UCTRANS.*
PRIMES.*
FILEIO.PAS
EXTENS.PAS
EXTENS.LST
EXTENS.SRC
EXTENS.REL
EXTENS.COM
CALL.*
RENERA.SRC
RENDRV.PAS
ERADRV.PAS
EXAMPLE.*
PEEK.*

Optimizer for Z-80 source output of compiler
Commented version of MAIN.SRC
Program to be used when overlaying
Source for the overlay routine in LIB.REL
Programs to allow UCSD --> CP/M file transfer
Demonstration program to generate the primes
factors of the numbers from 1 to 1000
A demonstration of Pascal/Z file I/O
A demonstration program containing at least
one example of each Pascal/Z extension.
Listing file generated by Pascal/Z
Macro code generated by' Pascal/Z
Relocatable object code module generated by
ASMBLE/Z
Program module generated by LINK/Z.
EXTENS
cannot be relinked by the user.
It is for
demonstration purposes only.
Loads Z-80 registers and transfers control to
a specified address
2-80 source for the RENAME and ERASE routines
contained in·LIB.REL.
Sample program which drives RENAME
Sample.program which drives ERASE
A progr~m to calculate the transient program
area available in a CP/M system
PEEK and POKE for Pascal/Z -- allows the user
to exam ine any location in memo ry and sto re
into that location

Also on this side are the .PAS files for the Jensen & Wirth
example programs on the second side of the Library Diskette,
provided with permission from Springer-Verlag New York, the
publishers of the USER MANUAL AND REPORT.

CONTENTS OF THE PASCAL/Z LIBRARY DISKETTE
The first side of
following files:

your ·Pascal/Z

P-.B SSQR. SRC

Integer absolute value and square floating
point absolute value
Does BCD addition and subtraction
Arctangent function
Passes a character from file buffer to A
register
Passes a character from A register to file
buffer
Routine to chain Pascal/Z programs

ADDSUB.SRC
ARCTAN.SRC
BYTIN.SRC
BYTOT .. SRC
CHAIN.SRC

Library Diskette

contains

the

Pascal/Z User.t s· M·a·noal
CHKD.SRC
C.LS QT·. S Re .
CMPCHK. SRC ..
CONSOL.SRC
CVTFLT. SRC .
CVTSFP.SRC
DEFLT.SRC
DIVD.SRC
DONE2.SRC
DSKFIL.SRC
DYNALL.SRC
ENTEXT. SRC·
EOFLN. SRC .
ERROR.SRC
EXPFCT.SRC
FADDSB.SRC
FCTMAC.SRC
FILEXT.SRC
FILNAM.SRC
FLTIN.SRC
FMULT.SRC
FOUT.SRC
FPDIVD.SRC
FPERR.SRC
FPINIT.SRC
FPMAC.SRC
FPRLOP.SRC
FPSQR.SRC
FPTEN.SRC
FXDCVT.SR~

INDIR.SRC
INPT.SRC
LAST.SRC
LO.SRC
LOOK.SRC
MAIN.SRC
MPNORM.SRC
MULT.SRC
NATLOG.SRC
OPFILE.SRC
OUT PT. SRC
PSTAT.SRC
RBLOCK.SRC

. Rang·e

Page 11

chec.k

6Qtput file
··Flo·a.t1ng·: . point rout·in·e·s·. to . complein·e·nt· an
·o·perand ·and check. numb-e.r .. fo r . a zero·
Console· read·· and print
Co·nvert 16 bi t in.t·e·ge:r.- t·o flo a t.ing po in t.numbe·r.· .
Convert a string to a floating point number
Con·ta.ins . defaul t v·alues used in assembl ing
some library.:modules
Divide ro·utines
F.inishes·
two-operand
floating
point
opera t.ions
Routines to specify device name and delete
files from directory
Dynamic storage allocation and dea.llocation
·Enter and exit routines for procedures and
functions
End of file and end of· line routines
·Closes output. files. wne.n. run t.ime error is
encountered.
Exponential function
Floating·point add and subtract
Cont·a ins macros used in assembl ing some
libr.ary modules
Routines shared by reset and rewri·:e routines
Passes file name to file control block
Floating point input
Floating point multiply
Floating point output
Floating point divide
Floating point ·rout ine returns a zero and
set sea r. ry bit
Conta ins in i ti-allza tion-s 0 f val ues used in
assembling some library modules
Contains mac·ros used
in assembling
some
library modules
Floating point relational operators
Floating· point square
Floating point multiply and divide by 10
Converts a f10a t ing po 1.n t n umber to fixed
poi·nt format
Indirect load and store
Read and Readln
Marks the last location of the user program
Routine for closing output files
Looks one character ahead
Definitions and routines to be assembled with
the output of the compi.ler
Multiple prec·ision add and subtract, and
no-rmali zing .a . floating· point number
Multiply ro~tines
Natural log function
Opens input and 0 utput f i 1 e's·
Wri~e and Writeln
.
Trace and extende·d e-r.ror me·ssage routine
··Calculates random access block number and
size, and loads file buffer
.
Clos~s

Pascal/Z User's Manual
RESET.SRC
REWRIT.SRC
ROTATE.SRC
ROUND.SRC
SAVREG.SRC
SETCON.SRC
SETFTN.SRC
SINCOS.SRC
SQRT.SRC
SRELOP .. SRC
STRFCT.SRC
STRLOP.SRC
TEXT.SRC
URELOP. SRC

Page 12

Resets a file
Rewrites a file
.Rotates floating point mantissa one bit right
or 1 eft
Truncate and round functions used to convert
floating point to integer
Saves HL register and sets up pointers to two
sets on stack
Routines to construct a set, take the union
and intersection of two sets, and test for
membership
Set
relational
operators,
and
difference
routines
Sine and Cosine functions
Square root function
Structural relational operators
String length, setlength, append, and index
String relational op~rators
Buffers
flow of
characters
to
and
from
console
Unstructured relational operators.

Each of these routines is self documented.

JENSEN & WIRTH EXAMPLE PROGRAMS
On the second side of the Library Diskette are the .COM files for
the Jensen & Wirth example programs.
(The .PAS files are on the
second side of the Master.) Also included are data files fa r
file
those
programs
which
require
input.
Look
at
the
JENWIRTH.DOC on the second side of the Library Diskette fa r
detailed information on these programs. "

Pascal/Z User's Manual

Page 13
GETTING STARTED

Before doing anything with your Pascal/Z diskette, make a backup
copy of the diskett·e· and use that for all of your programming
effo r ts.
It is in your best interests NEVER TO WRITE ON THE
DISTRIBUTION DISKETTE.

Throughout this manual, whenever a sample dialogue is given, both
the computer and user responses will be shown; the user responses
should always end with a carriage return.
Now that you have a backup copy of the distribution diskette,
insert it into the currently 'logged in' drive (drive 'A' if the
system was just booted).
In order to verify your copy of the
distribution
software
you may compile,
assemble and
link
HELLO.PAS.
To do this try the following dialogue:
A>pasca148 hello
InterSysterns Pascal v-4.0
HELLO

o

1--

compilation error(s).

A>asmbl main,hello/rel
PASCAL run-time support interface

ASMBL v-7d

A>link hello /n:hello /e
LINK version 2b
A>
If any of the above steps did not work as indicated, refer to the
section on TROUBLESHOOTING in Appendix Two.
Now
your~

that you have successfully compiled, assembled
first Pascal program you may run it as follows:

and

linked

A>HELLO

If the program did not welcome you to the land of Pascal/Z then
refer to the section on TROUBLESHOOTING.
Once you have verified your diskette by. being formally welcomed,
continue reading
for
a brief
introduction
to
the
Pascal
language.
If you are already familiar with Pascal, you may wish
to
skip
to
page
34
for
information
on
the
Pascal/Z
implementation.
If you are using Pascal/BZ, the business version of Pascal/Z, see
Appendix Seven for details on how to use BCD numbers, and for an
explanation of the differences between Pascal/Z and Pascal/BZ.

Page 14

Pascal/Z User's Manual
INTRODUCTION TO PASCAL

The Pascal/Z Implementation.Manual
The first section of the Pascal/Z Implementation Manual contains
a br ief descr i pt ion 0 f the Pascal prog rammi ng languag e and the
facilities available to you; however, the discussion here is by
no means complete and if you feel that you need additional
material, you are advised to refer to a Pascal programming text.
Many books about~Pascal have recently appeared; among the better
ones are:
An Introduction to Pascal by Rodnay Zaks (Sybexf 1980)
An .Introduction to Programming and Problem Solving Using Pa sca 1
by G.M.
Schneider, S.W.
Weingart and D.M.
Perlman (Wiley,
'1978)
and a slightly more advanced and in-depth book:
Programming in Pascal by Peter Grogono (Addison Wesley, 1978)
The

Pascal USER MANUAL AND REPORT shipped with the Pascal/Z
is an excellent reference manual and is the "standard"
by which this compile~ was written; it may, however, be a little
heavy for the newcomer to Pascal.
compl~er

The design of the Pascal language was ·based on the idea that
computer programs have two main parts.
The first part of a
program is the data (variables and constants)' and the second part
is the "actions" which act upon that data. The data is described
by "declarations"
and "definitions"
while the actions are
descr~bed by "s~atements".
The following sections decribe how to
declare and define the dat~ and then how to write the statements
that act upon the data.
This description does not include a discussion of Variant records
or GOTO statements: the former because of its complexity and the
latter in an effort to discourage its use. The user is referred
to the above mentioned texts for a discussion of these topics.
The

second

section of this manual
describes the Pascal/Z
of the language.
If you are already familiar with
Pascal then branch to page 34 for information on using Pascal/Z.
If you purchased Pascal/BZ instead of or in addition to Pascal/Z,
read Appendix Seven before going on to the rest of the manual.
impl~mentation

Pascal/Z User's Manual

Page 15

DECLARATIONS AND DEFINITIONS
Pascal is a nstrongly typed n language.
This means that each
piece of data (whether it is a variable, constant or a parameter)
has
an
associated
data
type
(i.e.,
integer,
real,
character •••• ).
In addition, each variable must be declared
BEFORE it can be used; this . allows the compiler to check all
operations to make sure that the operands are compatible and are
not being misused~
There are a number of intrinsic data types
(pre-declared by the Pascal language) and there is a fac iIi ty by
which the programmer can construct his/her own data types if
desired.
There are two basic classes of data in Pascal.
These are scalar
and structured.
Examples of scalar data are INTEGER, REAL and
CHAR.
Examples of structured data are ARRAY, FILE, SET and
RECORD.
·Pascal allows users to create their own data types through use of
the TYPE declaration section.
This is a section of the program
where it is possible to define a type which is used later in the
program.
Types other than the standard pre-declared types may be declared
i~ the TYPE declaration section of a program.
The following four
sections of this manual describe 'both the pre-declared types,and
how to declare your ow~ data types.

Pascal/Z User's Manual

Page 16

( INTRINSIC CONSTANTS AND DATA TYPES
Pascal has five pre-declared
redefined by the p·rogrammer.
are described below.
INTEGER

REAL
CHAR
BOOLEAN
rj

TEXT

data types which may be used or
These types and their attributes

A variable of type INTEGER is an integer in the range
-MAXINT •• MAXINT.
Pascal has the pre-defined constant
MAXINT which is the maximum allowable INTEGER value for
a
particular
implementation
(MAXINT
=
32767
in
Pascal/Z) •
A variable of type REAL is a floating point number.
REAL numbers are 32 bits and have a precision of
approximately 6 1/2 digits
A variable of type CHAR may be assigned any legal ASCII
character.
BOOLEAN is actually a pre-declared enumeration type
with the definition: BOOLEAN = ( FALSE, TRUE).
TEXT is a pre-declared FILE OF CHAR and is used for
I/O.

There is also the pre-defined value NIL.
For more information
about NIL, see the sections on THE POINTER TYPE and PASCAL/Z
POINTERS.

Pascal/Z User's Manual

Page 17
SCALAR DATA TYPES

One very powerful feature of Pascal -is the ability to create a
new type which is a ~ubrange of an existing type, for example:
TYPE INDEX

=

1 •• 10j

This is useful both because it forces the programmer to decide in
advance how a particular variable will be used, and because it
allows
the
compiler
to
generate
code
to
insure that the
particular variable remains within the specified range (if an
assignment outside the specified range is attempted, an error
will result) ..
prog rammer may create his own scalar data type, which is
referred to as an enumeration type (so called because all of the
possible values are enumerated when the user declares the type).

A

Example of a TYPE declaration section:
TYPE COLOR = ( RED, BLUE, YELLOW, GREEN, ORANGE, VIOLET );
SMALL = 0 •• 99;"
PRIMARY = RED •• YELLOW;
SECONDARY = GREEN •• VIOLET;
LETTERS = 'A' •• 'Z·;
ASCII = CHAR;
COLOR is an enumerated type; PRIMARY and SECONDARY are subranges
of COLOR.
In the following' examples, the curly brackets - {} - are the
In Pascal/Z n (*" and If*) H may
standard Pascal comment markers.
be used for the same purpose.
The COLOR
manual.

definition

will

be

used

in

examples

throughout

this

Pascal/Z User's Manual

Page 18
STRUCTURED DATA TYPES

Pascal allows the user
to
combining other types.
Each
discussed in this section.

constru~t

of

the

his own data
major structures

type
will

by
be

First is the ARRAY (similar to the array in BASIC).
An ARRAY has
two basic parts: the index type and the element type.
The index
~ype determines how a particular point in the ARRAY is referenced
and the element type defines what type of data exists at that
pqj:nt.
{ THIS WILL BE AN ARRAY INDEXED FROM 1 TO 50 AND }
{ EACH ELEMENT IS"OF TYPE INTEGER}
TYPE TABLE = ARRAY( 1 •• 50 ] OF INTEGER;
{ THIS ARRAY IS EQUIVALENT TO THE LAST ONE
TYPE INDEX = 1 •• 50;
ELEMENT = INTEGER;
TABLE = ARRAY[ INDEX] OF ELEMENT;
{ THIS WILL BE AN ARRAY, INDEXED BY SIZE, OF PRICE}
TYPE SIZE = ( TINY, SMALL, MEDIUM, LARGE, XLARGE );
PRICE = REAL;
CHART = ARRAY[ SIZE] OF PRICE;
The next data structure is . the RECORD..
Like the ARRAY', the
RECORD allows the programmer to combine many pieces of data into
one type.
A RECORD is a collection of elements (which may be of
different types) where eac~ element is given a unique name.

{ A RECORD TO SPECIFY THE SIZE AND WEIGHT OF AN OBJECT }
TYPE OBJECT = RECORD
S 12 E: ('T INY, SMALL, MEDI UM, LARGE, XLARGE );
WEIGHT: REAL
END;
RECORD TO SPECIFY A DATE AND TIME ••• }
AND A CALENDAR OF IMPORTANT DATES}
TYP& MONTHS = ( JANUARY, FEBRUARY, MARCH, APRIL, MAY,
JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER,
NOVEMBER, DECEMBER );
DATE = RECORD
MONTH: MONTHS;
DAY: 1 •• 31;
YEAR: 1900 •• 2100;
HOUR: 1 .• 12;
MINUTE, SECOND: 0 •• 59
END;
CALENDAR = ARRAY ( ( BIRTHDAY, ANNIVERSARY, GRADUATION,
VACATION, HOLIDAY, PAYDAY) ] OF DATE;
{

A

{

w

••

Pascaliz User's Manual

Page 19

{ A RECORD TO RECORD INFORMATION ABOUT A FRIEND }
TYPE NAME = ARRAY ( 1 •• 30 ] OF CHAR;
ADDRESS
RECORD
.
STREET: ARRAY [ 1 .. 30 ] OF CHAR;
NUMBER: O•• MAXINT;
TOWN, CITY: ARRAY ( 1 •• 30 ] OF CHAR;
END;
FRIEND = RECORD
WHO: NAM·E;
WHERE: ADDRESS
END;

=

The next type of structure is a SET.
A SET is a collection of
objects of a given type.
A SET is declared to have a particular
el ement type.
Each SET var iable may contain none, one, some 0 r
all· of the possible elements for that SET.
For example, consider
the following:
TYPE STOCK =
IN_STOCK

( PAINT, BRUSHES,
= SET OF STOCK;

THINNER, TOOLS, ROLLERS );

A variable of type IN STOCK will indicate for each of the
possible values of STOCK-; whether or not the particular element
is present.
Pascal
allows
the
programm~r
to
test
for SET membership,
inclusion: (is one SET a subset of another),· equal-ity and
inequality.
In addition the programmer may take the difference,
union or intersection of two SETs.
Here are some more examples of SET declarations:
TYPE DIGITS = SET OF 0 •• 9;
ATTENDEES = SET OF ( DAVE, BILL, STEVE,

JEFF~

ROB );

The last structured type is the FILE.
FILEs are used
to
communicate with the world outside of Pascal.
Each file has a
particular element type so that both you and the compiler know
what type of data will be read or written.
The following
examples should help to clarify the use of FILE types.
{ A TEACHER'S GRADE RECORDS MIGHT BE STORED AS •.• }
TYPE BLUE BOOK = FILE OF RECORD
NAME: ARRAY [ 1 •• 30 ] OF CHAR;
GRADE: • A' •• IF 1
END;
{ A LIST OF #'S MIGHT BE STORED AS •••.
TYPE NUMBERS = FILE OF INTEGER;

}

PaScal/Z User's Manual

Page 20
THE POINTER TYPE

The 1 a s t t y p e 0 fda t a i s a po in t e r •
A po in t e r va ria b 1 e i son e
which points to another variable of a specified type. This type
is useful when constructing linked lists or other data structures
where one datum has a need to know about another.
In Pascal
pointers are used in connection with dynamic variables
variables which DO NOT have to be declared ahead of time.
co mmo n e x am pIe i s the ere at ion 0 f a l i n ked 1 i s t 0 f r e cor d s .
The idea is this: a type is defined as a pointer to a record of
type; the record of type is the kind of record we want to have
linked together and created dynamically.
An example
(from
Jensen/Wirth User Manual and Report):

A

type link

=

person

Aperson;

=

record

next: link;
end;
Here, person is a type defined as a record presumably with
various fields in it concerned with age, health, sex, social
security number (these fields are indicated by the periods), but
including at lea.st pne f.ield whicp is a .pointer to a record of
the same type.
After such a type definition, the variable declaration would be
something like this:
var first, p: link;
To write a program that creates a linked list of these records,
the' Pascal built-in procedure NEW is used.
Every time the
program statement NEW(p) is encountered, it will create another
record of type person, because "p" is a variable of type link
which is defined as a pointer to the type person.
In addition,
the NEW procedure assigns to the variable p the value that points
to this newly created record.
Since this record that is being
created by each NEW(p) statement has, as one of its fields, a
pointer variable, one may link each newly created recqrd to the
next record by proper arrangement of assignment statements. Many
schemes are possible, with pointers that point both forward and
backward, but the important thing to remember is that the
procedure NEW creates an entirely new variable.
The example from
the User Manual and Report goes like this (using the types
declared above):

Pascal/Z User's Manual,"

Page 21

var p, first: link;
i: integ er;
socialsecurity: file of array[l •• 3] of integer;
begin
first := nil; { "nil" is a special value which
indicates that the poi~ter points
to nothing }
for i := 1 to n do
begin
read( socialsecurity, s );
new( p );
pA. next := first;
p" .ss := s;
first := p
end;
end.
What happens here is that n records are created, of the type"
person.
"pA. SS := s" assigns a value to a field in the present
record,
s
i~
retrieved
from
a
file
in the previous read
statement.
"pA .next := first" assigns the value of the pointer
"first" to the pointer field that was built into the record; then
"first := p" makes first point to the present record.
Each time this group of statements is executed by the FOR loop,
the pointer "first" is set to point to the most recently created
record, and the pointer field within that record is set to point
to the previous record.
To get the data out of such a structure, a program could use the
•• fir s t " po in t e r to 10 cat e the mos tree en t· r ec 0 r d, and the nth e
pointer within the record to reference the second record, and so
forth.
One might create another variable of type pointer, which
could be 'assigned the values of the pointers from each record,
one "after another, to inspect the other fields in the record
(stopping when the "next" pointer is nil) •
The advantage of such a data structure is largely its dynamic
nature, since it is not necessary to declare the size of the list
ahead of time.
Dynamically created storage may be returned when it is no longer
needed (see the section on Pascal/Z pointers).
To assist those users wi th non-standard
symbol
has the ASCII value SE hex.

keyboards,

the

po inter

A

A

later
section,
PASCAL/Z
implementation of pointers.

POINTERS,

decribes

Pascal/Z's

Pascal/Z User's Manual

Page 22
CONSTANTS

Many programs make use of constants such as the maximum number of
items, size of table, perfect score, etc.
In Pascal it is
possible to define scalar constants and strings symbolically in
the CONST declaration section.
In addition to making your
program more legible and easier to maintain, the use of constants
rather than variables will help the compiler to generate more
compact and efficient code.
Example of CONSTant declarations:
CONST

TABLE SIZE = 50;
VERSION = TVersion la';
PI = 3.1415926;
NEGATIVE = -TABLE_SIZE;

'It is clearly advantageous to declare constants and use them
throughout your program since it gives you,the ability to change
the value of all occurrences of the constant throughout the
entire program by redefining one constant ~t the beginning (e.g.,
changing all references to a table size from 50 to 100).
Pascal defines a constant string, such as VERSION in the example,
to be:
ARRAY [ 1 •. N,] OF CHAR
where N > 1.
ARRAY OF CHAR.

If N

=

1 then the constant is of type CHAR, not

Pascal/Z User's Manual

Page 23
VARIABLES

All variables must be declared before. a Pascal program is allowed
to refer to them.
In addition each variable must be explicitly
decl ared to be 0 f a c erta in type.
The type 0 f a var iabl e
determines the amount of storage that it requires, as well as
defining how it may be used throughout the program.
Example of VARiable declarations (the two groups of declarations
here are equivalent):
VAR

COUNTER: ARRAY [ -4 •• 20 ] OF COLOR;
FLAG: BOOLEAN;
SIZE: ( TINY, SMALL, MEDIUM, LARGE, XLARGE )i
I,J: INTEGER;
TABLE: ARRAY [ 1 •• 50 ] OF INTEGER;
LETTER: ' A' •• ' Z f ;
TEMPERATURE: REAL;

and
CONST TABLE_SIZE = 50;
TYPE EXPANSE = ( TINY, SMALL, MEDIUM, -LARGE, XLARGE );
LETTERS = 'A' •• 'Z';
NUMBER : INT~GER;
TABLE ~NGE = I •• TABLE SIZE;
TABLE-ELEMENT = INTEGER;
VAR

COUNTER: ARRAY [ -4 •• 20 ] OF COLOR;
FLAG: BOOLEAN;
SIZE: EXPANSE;
I,J: NUMBER;
TABLE: ARRAY[ TABLE RANGE) OF TABLE_ELEMENT;
LETTER: LETTERS; . TEMPERATURE: REAL;

Global and Local Variables
A global variable is one which is defined under the main program
heading.
It may be used, referenced or changed anywhere within
the program.
Global variables may be. accessed by any procedure
or function
which
does not use the same identifiers.
,
.
A local variable is one which is defined within a
function.
It will disappear once the procedure or
been executed, and will have no effect outside its
function.
A local variable will have no effect
variable.

procedure or
function has
procedure or
on a global

Pascal/Z User's Manual

Page 24

Accessing variables
Variables are accessed simply by referring to the variable by
"name.
However,
sometimes it
is
desirable
to
refer
to
a
particular part of a variable, such as an ARRAY element," a field
of a RECORD, or the target of a pointer.
These types of accesses
are illustrated below:
TABLE [ 24 ]
DATE.MONTH
FRIEND.NAME[ 1
FRIEND.NAME[ I
LINK . .
LINK ..... SIZE

{ THE 24TH ELEMENT OF OUR ARRAY }
{ THE MONTH FIELD OF A DATE RECORD
{ THE FIRST CHARACTER OF A NAME }

}

{ THE Ith CHARACTER OF A NAME }
{

THE RECORD POINTED TO BY LINK }

{ THE SIZE FIELD IN THIS RECORD

}

Now that you know about the intrinsic data types, Now that you
know about the instrinsic data types, how to create new data
types, declare constants and declare var iables, the following
sections will describe the statements which manipulate the data.

Pascal/Z User's Manual

Page 25
ASSIGNMENT STATEMENT

One of the most basic statements in any· language is the
assignment statement (called the LET statement in BASIC).
All
assignment statements in Pascal have the same form, which is:


:~



Where  may be any combination of constants, variables
and function calls, as long as the type of  is
compatible with that of .
Examples of

assi~nment

statements are:

{ two assignments to a variable of type INTEGER}
A :

=

4;

RESULT := X

* Y DIV Z;

{ assignment to a variable of user defined type COLOR }
STOCK. ITEM := GREEN;
{ assignment to an element of an ARRAY OF CHAR }

TAB LE [ 20 J : =

f

Z' ;

{ This is an assignment to a variable of type BOOLEAN
{ the effect of this statement is to:
{
1) INTEGER divide A by B
{
2). multiply the iesult ~f' step 1 by B
{
3) compare result of step 2 to A
{
4) assign result of the comparison to DIVISIBLE
{ this works without parenthesis because relational
{ operators are the lowest precedence operators
DIVISIBLE := A DIV B * B = A;

}
}
}
}
}
}
}
}

{ The variable MY NAME is of type:
{
ARRAY [ 1.e4-] OF CHAR
{ This assignment copies one ARRAY into another
MY_NAME := 'Lyla';

}
}

}

{ This assignment copies one RECORD into another of
{ the same type. (The type of these RECORDs is DATE
{ which was defined in the section on structured types)
PARTY DATE := BIRTH_DATE;

}
}
}

Pascal/Z User's Manual

Page 26

REPEAT AND WHILE STATEMENTS
The REPEAT and WHILE statements are used to execute a loop until
some desired condition is reached.
The main difference between
the two statements is that the REPEAT loop does a test for
completion at the end of the loop; and the WHILE loop does a test
at the beginning.
This means that the body of a REPEAT loop is
executed at least once before the loop is terminated, but the
same is not true for a WHILE loop'.
The form of these statements
is :
REPEAT 

>

WHILE  DO 
In both statements  must be a BOOLEAN expression.
The REPEAT loop terminates when the expression is TRUE and the
WHILE loop exits when the expression is FALSE.

FOR :3TATEMENT
~he FOR 'statement should be used ·irt ~lace of the REPEAT or WHILE.

statements when it is possible to determine in advance the number
of repetitions necesssary.
The format of a FOR statement is:
FOR  :=  TO/DOWNTO
 DO
The type of variable allowed is any variable of scalar type
except REAL.
The following examples should give an idea of the
flexibility of this statement:
FOR INDEX := 1 TO 50 DO 
FOR ITEM := PAINT TO ROLLERS DO 
FOR TINT := VIOLET DOWNTO RED DO 

Pascal/Z User's Manual

Page 27
CONDITIONAL STATEMENTS

The next statement
statement in BASIC).

is the IF statement
Its form is:

(similar

to

the

IF

IF  THEN 
or
IF  THEN  ELSE 
The expression must be a BOOLEAN expression and the statement
following
the THEN is executed if the expression is TRUE,
otherwise the statement following the ELSE (if there is an ELSE)
is executed instead.
There is another conditional statement, the CASE statement.
CASE statement is similar to, but more powerful than,
ON ••• GOTO statement in BASIC.
Its form is:

The
the

CASE  OF
: ;
: 
end;
The  may be a variable or an expression.
Each
 is a,list of constants (they MUST be constants)
for use in selecting ·a particular CASE.
Here is an example of
the use of the CASE statement:
CASE TINT OF
WHITE, RED: ;
GREEN: ;
YELLOW, ORANGE, BLUE: 
END;

Pascal/Z' User's Manual

Page 28
COMPOUND STATEMENTS

Sometimes it is desirable to have a group of statements act as
one statement so that the programmer can insert the group into a
construct which expects only one statement. For example it might
be useful to be able to do the following, which is. not legal in
Pascal:
IF  THEN



.. . ..


ELSE 
This can easily be done in Pascal by constructing
statement. The compound statement takes the form:

a

compound

BEGIN
 ;
 { This line may be repeated zero or more times}
END

The above example becomes:
IF  THEN
BEGIN
 i


.. . . .


END

ELSE 
A compound statement may be used ANYWHERE a statement is used.

Pascal/Z Userts Manual

Page 29
WITH STATEMENT

The WITH s.tatement is used when a particular RECORD; is being
accessed repeatedly.
It is both shorthand for the programmer and
in some cases allows? the· compiler to produce more efficient
code.
The CALENDAR RECORD from the RECORD d~scription section is
used in this example of the WITH ~tatement:·
VAR C:
BEGIN
C(
C[
C[
C[
C[
C[
END;

CALENDAR;
BIRTHDAY
BIRTHDAY
BIRTHDAY
BIRTHDAY
BIRTHDAY
BIRTHDAY

].MONTH := JANUARY;
].DAY := 17;
].YEAR := 1958;
].HOUR := 12;
]. MINUTE : = 18;].SECOND := 0;.

The following group of statements accomplishes the same thing:
VAR C: CALENDAR;
BEGIN
WITH C[ BIRTHDAY] DO BEGIN
MONTH := JANUARY;
DAY := 17;
YEAR := 1958;
HOUR := 12;
M.INUTE· : = 18·;
SECOND := 0;
END;
END;
Notice how the compound statement was used in the second example
to reduce the verbiage and increase the readability of the code.

Pascal/Z User's Manual

Page 30

PROCEDURES AND FUNCTIONS
In Pascal there are two. types of subroutines -- procedures and
functions.
Functions are basically the same as procedures except
that functions return a scalar value (e.g., ASS, SIN, SQRT,
etc.).
Procedures are called explicitly as statements (procedure
statements).
Functions are used in expressions.
Pascal allows parameters to be passed to procedures/functions.
There may be as many parameters as desired and each parameter may
be passed either by value or by reference ( VAR parameter ).
In
addi tion
each
procedure/function
may
have
its
own
local
constants, types and variables.
Procedures and functions may be
nested and each can access the constants, types and variables of
all surrounding blocks.
All
procedures/functions are
fully
recursive.
Listed below are some examples of procedures and
functions:
TYPE STUDENTS = ( :M.OB, JEFF, BILL, LAURIE,- LYLA, NEAL);
TEST SCORES = ARRAY [ STUDENTS] OF 0 •• 100;
{ A PROCEDURE TO OUTPUT THE SCORES OF A TEST }
PROCEDURE RESULTS ( TEST N: TEST SCORES );
VAR STUDENT: STUDENTS; BEGIN
FOR STUDENT := ROB TO NEAL DO
BEGIN
WRITE ( STUD&NT:lO, TEST N( STUDENT ]:3 );
IF TEST N( STUDENT] = TOD THEN WRITELN{ 'A+'
ELSE WRITELN;
END;
END;
{ A FUNCTION TO RETURN THE MAXIMUM OF TWO NUMBERS }
FUNCTION MAX( X~ Y: INTEGER ): INTEGER;
BEGIN
MAX := Xi
IF X < Y THEN MAX := Y
END;

Pascal/Z User's Manual

Page 31

PASCAL STANDARD FUNCTIONS
Pascal contains a variety of pre-defined functions which are
available to ,the programmer.
Each function and its description
are listed below:

ABS( X )
SQR( X )
ODD ( X
CHR ( X
ORD'( X
PRED( X
SUCC( X
EOLN ( X
EOF( X
TRUNC ( X
ROUND ( X

Return the absolute value of X.
This function
takes either a REAL or an INTEGER argument and
returns a value of the same type.
Return the square of X.
This function
takes
either a REAL or an INTEGER argument and returns a
value of the same type.
The type of X must be INTEGER.
Returns TRUE if X
is odd, FALSE otherwise.
The type of X must be INTEGER and the result is
the character with the ordinal' value of X.
The type of X may be any scalar except REAL and
the result is the ordinal number of that element.
The type of X may be any scalar except REAL and
the result is the value which precedes X.
The type 0 f X may be any seal ar except REAL and
the result is the value which succeeds X.
Th e type 0 f X mus t be FILE 0 F CHAR (i. e ., TEXT)
and the result is TRUE if the file is at the end
of the current line.
The type of X must be FILE and the result is TRUE
if end-of-file has been reached.
The type of X must be REAL and the r~sult is the
INTEGER whose absolute value is less than x.
The type of X must be REAL and the result is the
INTEGER whose value is closest to X.

The following functions take
and return a REAL result.
SIN ( X )
COS (- X )
ARCTAN ( X
SQRT( X )
LN ( X )

EXP ( X )

either a

REAL or

INTEGER argument

The trigonometric SINE of X.
The trigonometric COSINE of X.
The trigonometric ARCTANGENT of X.
The squa re root of X.
The Natural Logarithm of x.
e raised to the Xth power.

PASCAL STANDARD PROCEDURES
Pascal defines a number of standard procedures which may be used
by the programmer.
They are Llsed in I/O and dynamic storage
allocation/deallocation.
For a discussion of these procedures,
see the sections on PASCAL/Z INPUT AND OUTPUT, THE POINTER TYPE
and PASCAL/Z POINTERS.

Pascal/Z User's Manual

Page 32

PROGRAM STRUCTURE AND USE OF SEMI-COLONS
The actual format of Pascal programs is not fixed.
You may put
symbols anywhere on a line and any statement or declaration may
be spread over many lines, as long as each individual symbol is
not broken by any separators.
However, there is a structure to
Pascal programs which must be followed.
This structure is:
 ::= PROGRAM  i



::= 

Source Exif Data:
File Type                       : PDF
File Type Extension             : pdf
MIME Type                       : application/pdf
PDF Version                     : 1.3
Linearized                      : No
XMP Toolkit                     : Adobe XMP Core 4.2.1-c043 52.372728, 2009/01/18-15:56:37
Create Date                     : 2013:04:17 08:23:26-08:00
Modify Date                     : 2013:04:17 08:17:23-08:00
Metadata Date                   : 2013:04:17 08:17:23-08:00
Producer                        : Adobe Acrobat 9.52 Paper Capture Plug-in
Format                          : application/pdf
Document ID                     : uuid:567daeed-4aa7-4a44-b674-edecff6278f3
Instance ID                     : uuid:f530a28a-d065-4017-8df3-73dfc6dcb914
Page Layout                     : SinglePage
Page Mode                       : UseOutlines
Page Count                      : 137
EXIF Metadata provided by EXIF.tools

Navigation menu