广告
广告
[
1
14e QJ DU U U U
o i <
Vw Wu
~
God Wl
‚
Ч.
у
k
FU Ш
U:
k
*
User Guide
For the Sinclair QL Computer
== ео о —н нк a —
e tg f US:
- computer ONE
(С) Copyright Computar One Limited +984.
Na part of 103 manval may be idapted or reproduced in any form withoyr the prin won tan sopeavel of Compyrer Cine
Limited,
AL 1he informatión (1 given in good teith, Computed One can ecespt no random ball lor ny lox or dernage are
from the intarmation comsined in this manual or from the ya of this product
Computer Ona rmaetves the right to alter vive specification of 1he product without warning
Computer Ona welcome comments snd idem. Thess and any bug reports of further anquinsy Quid be ant on the
Mont form pt the Bach of this mpnual to:
Technical Ervpuiries.
Cormmpute Ore Lid
cien бым ®
Milton Rom]
Camtr don CHA LBW
Ма че! Мо бытом гп assessing eny GL soboware, which you would Tk e пос аи ры ЛР
Ye regrel That telephone cu Castor he ar 3
Sinclar & OL are Registered Trade Marks ol Sinclar Aercarch Lid.
An am ae dh SM AR BS A A MA
Aly A aes
Fa
' 5 OX a. = nn Se F
ERRATA = Sth October 1984 i
This sheet gives a list of additions and changes to the Pascal
User Guide, PLEASE READ THIS BEFORE USING YOUR COMPUTER ONE SOFTWARE
Pry 11 - The Jirectory command also allows you to look at the
directory of a device other £han a microdrive, If you press the ' BACKING-UP
letter 707 «hen prompted for a drive number, the prompt
Que to the unreliable nature of microdrive cassettes, RE ts
important that you use the supplied Computer One cassette putely
4% a Master copy. As soon as you receive your software, you
which device 7?
et
mas:
15 displayed and you can then enter the name of a device. " should make two backups of the master cartridge onto blank
cartridges, and use these as working copies. The Master 1s then
Paye 13 - A Format command has been added to the command menu. used as an emergency backup, and not to run the software.
Paye 48 - Section %.5.1.1 on parameters should say that alt file Copies of the Master may be easily made using the ‘clone program
) parameters must be var parameters, (supplied on each Computer One software cartridge) as follows:
Page 50 - In the example, the word “var” In front of the 1. Place the Master copy in microdrive 2 (the right hand side
parameters for procedure a should be deleted, drive),
J
Page 32 - In the example, the parameter "stringl” should be 2. Place e blank cartridge in microdrive 1.
deleted from the read statement, and on the last line of the page,
"Не part of the line after the first semi-colon should be J. Enter the following command:
deiated, This 19 because strings cannot be read with a single read
statement, Use the functions ‘getline’ or ‘gethytes’' [natead, LRUN mdv? clone <ENTER>
Tage 61 - In the procedure ‘recal’, the parameter cA should be 4. The QL will respond with various instructions to name the new
parameter cO and should be the first parameter in the list of microdrive, and initiate the copying. Check you have insertrd
rciours, le, The first colour parameter specifies the new colour the cartridges in the correct drives, and invoke the copying.
for all the black pixels, the second specifies thes new colour for
Ail the Blue pixels etc, 5. The new system may be used as soon as the microdrives have
stopped running,
Page 64 - The 'qgetbytes procedure is now a function which
returns tae number of bytes actually read. The parameters of the
function are the same, A new function ‘getline’ has been added :-
function getline ( var f : File; count: integer; addr: address | |
j t Integer ;
feadn the specified number of bytes (rom the given lle, ot, a |
rofiuence of bytes terminated by 3 line-feed character, Returns the |
number of bytes read, including the line-feed, "joresult” isa set
to bulfer-full {1-5} If no line-feed La read. This function
allows the cursor control keys to «dit the line if it is entered
| from the keyboard.
Paye 74 - The run-time error message "Number expected’ now reads
Bad number’ and can also occur Lf the number entared ia too
large, or is too long.
Fage 79 - In the PUNCTION part of the subprogram definition
syntax diagram, there should be à line going round just ths,
paremetar list box, in addition to the line going round the
parameter list and the type-identifier boxas.
The wysten han been modified so that Lt can be reloaded from Sasic
ty typlwg “Pascal”. Tain only spplies after the Pascal system has
Tirut been losded. REÍA
a
age, ту 3 Her - - — TITTY IIL AS Cs * ES E UE "—— Semmes MN
ee в uy + ODE - RA CT BR
>.
A number of enhancements have heen made to the editor, which are not
documented in the mania],
The File menu has three new options -
1! Read Pile - this option prompts for & (île name and inserts the
contents of the given file at the current cursor position,
2) Remove error text = this options removes the errors from a
bistiny file,
3) Directory - this option prompts for a device and Эту A
directory listing, -
1.5 EDIT MENU
This menu appears when the FS key is pressed. It has four options
which allow you to cut or Copy pieces of text, paste pieces of text,
or display the last piece of text cut or copied,
To leave the edit menu you press Fl, Each of the options are described
below, Some options EXPECT a marker to be set. This is described in
the following section,
1.5.1 Inserting a marker
A marker is set in the text by pressing the CNTL and FA keys
together, The character ar this position La shown in reverse video,
Only one position in the file may be marked at one time. The Marker
«111 be removed by any action except moving the cursor (either with
The CUFSOF Keys. paging or the life), The marked character will only
be displayed in inverse video until it moves off the screen,
4.5.2 Cut
Trias Aption is only available if à Marker has been set, It allows you
Pe remove a piere of text from the edit file and save ir in an
thteenal buffer. The contents of this buffer can then be pasted into
trther parm of the file. To cut text, set a marker (CMTL-F4) at
"fm stact of the text to be removed, Then place the cursor after the
PAST to be cut, Now press ES to get the edit menu, select the cut
"Prion And press FNTEA, The text will be removed from the File but
ill temaire available to be Subsequently pasted. You will only be
Allowed tm cur LE there is sufficient space act as an internal buffer.
In a QL with [28% of memory the buffer space is approximately 1x,
1.5.) Copy
This +4 similar to the Cut opción except that the rewr selected 19
ried nto the internal buffer without being removed from the edit
Fite,
1.5.4 Paste
"Mis option is oniy available if there 19 some text in the internal
hutf{er, i. e. if you have cur or copled text, The cursor should Be moved
TH where you wish the text to be pasted. Press ES to get the adit menu
then select paste and press ENTER, The text in the internal buffer is
inserted at the current cursor position untess the resulting File dd
tdo big for the workspace in which case an error will accur and the
Paste will not proceed,
1.3.% Show buffer
You may examiné the contents of the internat buffer by pressing FS to
qet the adit menu, salecting the show buffer option and pressing
ENTER. The buller contents are then displayed,
INFORMATION
Operating System Version
Computer One Pascal { version V1.0 } vas developed and tested
Using the AH version of the nas erating system. Should you have
any difficulty using Pascal wich earlier versions of the operating
System, ve SUGGeSt that you obtarn AN upgrade From Sinclair. ?
Back ing Up
There 13 a "clone routine on the Pascal system microdrive
written in BASIC, which you should uge ta backup the Pascal
system. bo this before you use the «yatem, we strongly recommend
that you make tequlsr backups of everything. We also recommend
that you NEVEr reas: the System vith a cartridge in any of the
drives, as this can damage the Cartridges. NOTE thar this
Formats the cartridge in drive t,
In the Pascal system the ®rror message not complete on à
file Operation will often indicate that there is à bad or changed
medium on the microdrive cartridge. This does NOt mean that the
Cartridge is not usable, Repeating the Operation may he
ap ccessful; failing that trying the cartridge in the other Micro
TIVE may work; and if that fails it probably means that the file
tou voy However, the test of the cartridge will nermally be ok.
immediately. advised to backup the rest of the Cartridge
Example Programs
A few Example programs are Fl Yen on the System micro drive +-
Clone pas * This program is vritten in Pascal and i3 a routine Гог
formating and cloning microdrives from the pascal System. [e
formats the cartridge in drive в, reads the name of each fija from
the directory an Microdrive | aná Copies the files from drive tro
drive 2, Note that unlike the BASIC clone routine You do not need
CO know the name of each file YOU are going to copy. You will have
ta compile thin Frogram before You can use ik, NOTE that unless
you have a ODOS manual this program will probably be meaningless
globe paw - this program draws 8 globe on the .
Pascal ellipse routine, 7 t ICreen using the
fit pas : This Program, which is used ay a
‚ n example in the ,
Outputs the first n numbers of the Pibonacci series, manual
D0" WW UW U- ds JIU UII IY UV YUU UM
inserting Text
Goto Statement
1 ! Eat sin. lL E - ey hod = 02
| A Constant Definitions
2.) Type Definitions
TABLE OF CONTENTS | >) 5.2.4 Variable Declarations
5.2.5 Procedure and Function Definitions
| 5.2.6 Statements
Chapter 1 Introduction. tvs vn tits tree rs sant n nnn .....Page 1 5.3 Data Types
E.l Using this Manual | 5.7.1 Standard Scalar Types
3.3.1.1 Integer Type
Chapter 2 Getting Started... ..ececosecarrerrearerana cre. Page 3 5.3.1.2 Real Type
7.1 startup 5.3.1.3 Boolean Type
2.2. Example Session 5.3.1.4 Char Type
5.3.2 Enumerated and Subrange Types
Chapter ) The Commands.......eecererecoreos Crean ....Page 7 3.) Array Type
3.1 Filenames 5.3.3.1 String Arrays
3.2 Commands . 5.3.4 Record Type
1.2.1 Edit 5.1.5 Ser Type
1.2.2 Compile ) 3.1.6 Printer Буре
1.2.2.1 Compiler Options 5.3.7 File Type
3.2.3 Run | 5.1.8 Type Compatibility
1.2.4 Directory 5.3.8.1 Assignment Comparibilicy
1.7.5 Delete 7. 4 Statements
1.2.6 Copy 5.4.1 Aasignment Statements
1.2.7 Exit y 5.4.1.1 Expressions
5.4.2 Compound Statement
Chapter The Edito, ....e.nnnmaa evi. ..n.......ww..‚Paqe 14 9.4.) Repetition Statements
Edit File Formac 5.4.1.1 While Statement
Edit Filé Names 3.4.1.2 Repeat Statement
Editing a File 3.4.3.3 For Statement
Moving The Cursor „4,4 Conditional Starements
. 1 Paging 4.4.1 LE Statement
4.4.7 Case Statement
5
6
Neleting Text
+
With Statement
Procedures and Function
Procerdyres
Splitting and Concatenating Lines
Finishing the Edit Session
The Editor Pile Menu
kde dr PO
MATE UT A LITE GE TT ел A LA AAA ANNA
. 4,
4.
5
‚5.1
1 Creating a New File 8.1.1 Paramerers
„1 Loading s Pile 5.1.2 Forward Declaration
.1 Saving a Copy of a File 5.2 Funecinns
1 Saving the Current File 6 Input and Dutput
1 Saving a Listing 6.1 Inpur
1 Saving and Exiting 6.2 Qutpur
L Exiting ‚56.3 Files
Search String Facility ) 6.3.1 Texrfiles
Editor Lift Facility ; 6,4 [71 Frrorsg
I 1 " = F - 7 ! E + "
DA CAR de de Ee ST ня щи al ha el Lal Ка ea
= + E + = -
Edir Listing Facility
Chapter 6 standard Procedures and Functions for the 4 Page 58
Chapter 5 Language Definition............. Chee ....Paga 32 6.1 E/7 Procedures and Funcrions a
5.1 Fundamentals 6.2 Memory Access Pescedures an Funetinns
5.1.1 Numbers 6. + Other Pracedires amd Functians
E identifiers
5.1.3 String Constants — Chapter 7 Standard Pascal Procedures Ind Funcrions Page AY
3.4.4 Comments 7.1 Funct iene E Be.
5.2 Pascal Programs 5 *,2 Procedures
5.2.1 Label Declarations
MANRANADERNANANNACAaANNACA
>
° "ыы
vu UVC UL
“me
vow wow oy
CF 1
Ser”
TY + e © "E М Fa ME
| CHAPTER ONE
Bibliography. .....s..ee.enoero, т. ч я ла 4 4 & 3 в я я + + req. Page 70 )
A ndices
Ppe INTRODUCTION
A - Compiler Error Messages,.,....., rider. Page 71
8 « ‘ Run-tire Errors............. 0... e... ‚ «Раде 74
C = Pascal Syntax Diagrams,......... .......0411,.P8Qe 76
D - A "0 «--..Pagé BA
Index, ия т + | вая + 4d 4 NR dy a gay omen E ве LE LE Page q
This user guide provides the Information required to edit, run
) and compite programs Using the Computer One Pascal system on the
Sinclair OL MISFrOCOMPUter, The quido ig not intended tp tearh
Pascal and the reader is referred to the Bibliography for a
number of references on learning Pascal.
The Computer One Pascal System is a powerful menu driven System
y which allows you to edit, compile and run Programs with ease
there are no command names to remember as all commands are
executed by selecting from the displayed menu. In addition, a hely
window aids you whenever data input .s required. The syatem ed) rng
is a general purpose screan editor, which has heen designed wirh
| usefulness and simplicity wn mind. You are Mot restricted ra
editing files used by the Pascal system and can use the editor ra
edit any QL text filas. The editor also allows YOu to edit Fascat
SQUICe files whita ÉxamMining compiiation errors for the Fite
AS well as editing, compiling and running Pascal
also have the option of examining microdrive carted
directory command and deleting
Pros amas, PU:
FAS NSIM Elie
and copying micendrivae tilrs
The Computer One Pascal Compiler ptodures
a comparr
intermediate code which Ls interpreted when the
PEOGIram 165 rig
The language implemented is close to the 150 Pascal
specification, with a small number af
language is described in Chapter Five.
standard
ifferences Tha
A number of extra procedures and functions are provider ta
| allow you to make full use of the QL from the Pascal system, These
; ' | procedures allow you to use the QL windowing and Itaphics [eatures
and also to make calls ro MAC ne rode revit ines
Se
LARA A AGAR NANA RA ADNAN |
An
Tv Yd (WY о)
Jd ‘Lv dd dd yd
or’
u
Nf
Ww Qu
‘VU Ww
—
|
1.1 USING THIS GUIDE
This section contains a brief overview of the contents of each
chapter in the guide,
CHAPTER 2 describes how to get started using the Pascal system
and warks through an example of an edit, compile, run session.
CHAPTER 3 describes the Pascal system environment and gives a
description of each of the commands,
CHAPTER 4 describas, in detail, the general purpose editor,
including the edit listing option, which allows you to edit a file
while looking at the error messages produced for that file hy the
compiler.
CHAPTER 5 describes the Computer One version of the Pascal
language.
CHAPTER 6 describes the standard procedures and functions which
have been added to the language to allow you to make use of the
OL.
CHAPTER 7 gives a brief description of the standard Pascal
procedures and functions,
Appendices - The appendices list ths compiler, run-time and
system error messages and give the full syntax of Computer Onn
Pascal,
- CHAPTER TWO
GETTING STARTED
This chapter describes how to use the Computer One Pascal
system and works through an example of editing, compiling and
running a short Pascal program.
2.1 STARTUP
re
To start up the Pascal system it +5 important to carry sur
fallowing :-
(1) Remove any cartridges from the two microdrives. ге is
inadvisable to reset the system with the cartridges in the drives,
as they may be damaged,
(2) Press the reset button on the right side of the machine.
- the
11) Place the Computer One Pascal cartridge a drive one
left hand drive.
14] Press Fl or Fi to select Monitor or TV mode,
When you have selected the mode the Pasral System el
automaticatly be lcaded from the cartridge. The Pasca
interpreter, and the environment code are loaded into memory ar
startup and remain resident while the Pascal system 15 being user
These are kept resident $0 that the system does not have to reload
the interpreter code from microdrive everytime you «ish to run a
program. The resident code, the screen map and 9005 work se
require about 45K of memory, leaving berw.=an 79K and ВОК in NADIA
ro run programs. When the editor 13 joaded into memory there 2
approximately 635K to 70K of free space for editing The
shan = A
ne
> mn Pi
Ann
=
=.
тт тя
nn
Шаля
a
“о
тат
n
E
ls a
A
ARAN
wg al —
)
4 =" = FTE
The following Pascal program will now appear in the editing
window . 5
program [ibonacci ;
var fibl, fib2, i, n : integer:
begin
{generate each number from the aum of its two predecessors)
Fibl := О;
#162 := О;
y rm 2; [ number of Éib numbers generated |
writeln { "Generate how many Fibonacci numbery 7):
readin [ n,) y
while i < ndo
begin
weiteln { £ibl, fib2
Fibl := Etbi + Cab? y
Fib2 := Éibi + [ibd ;
1, := i + 2 ;
end :
1€ i = n then writeln { fibl,
end.
No
fib? ) else writeln { fibl }
The program does not need to be changed, so when you understand
how it works you can exit the editor, Press Fl to get the
editor file menu to reappear, Use the cursor keys to select the
leave option. When this has been selected press ENTER and the
System Command Menu will reappear. We now want to select the
Compile option. When you have selected this option press ENTER.
The following prompt will appear on the screen next to the menu :-
Which file ? | pas]
The bracketed ” pas” indicates that the compiler will
automatically append this extension to the Eilepame you en-er.
Notice that the help message at the bottom of the screen has nov
changed to tell you that you can press ENTER to return to the menu
and that mdv2 15 the default microdrive, Enter the filename now
mivl fib
Hhen yo: have done this the compiler will be joaded | this takes
less than half à minute | and a new screen will then appear. There
15 a Window along the bottom of the screen, which the compiler
uses En butpuc messages, for example if the compiler could not
Find a particular file on microdrive, a message «quid be outpüt in
this window. The compiler does not produce a full listing to the
Screen, unless the listing option i4 switched on, but only outputs
lines with errors and the appropriate error numbers. The error
messages can be displayed and the file re-edited using the edit
listing option ın the editor. This is described 1n section 4.7,
Unless you have changed the file "fib pas” there should be no
errors and the compiler vill output a message indicating that the
file has been successfully compiled. A message will then be
da | i
‚=
ттт тат
TN
AM Daman
— — —
N
=
LARD
Ths nF былым
TITEL
TE
UN,
Ч
|
co
—— —
SE a
JJ
y.
| J
|
``
+
И
—"
чей
hart
— MM "a - -
The compiler is not resident and is loaded into memory Erom
microdrive cartridge when you wish to compile a program.
Fhe
The loading of the system takes approximately half a minute ar.
when complete a system command menu will appear on the screen,
waiting for you to select commands to be run. To select an
ude the cursor up ( ) and curser down { ] keys or enter the number
of the command you wish to select. The currentiy selected men.
item is always highlighted. When a command has been selected 1»
can be run by pressing the ENTER key,
Lt am
The window at bottom of the screen tells you how to selert ani
run menu items, Help messages will appear in this window to qui:
you when a command 158 waiting for input from the keyboard.
2.2 EXAMPLE SESSION
We shall now work through an example program showing how ta
edit, compile and run the program. The program 15 already on the
Pascal microdrive cartridge which should still be in drive nope
The file containing the program is called "fib pas”. Ir
recommended practice to use meaningful extensions for file names,
so that it is easy to tell what type of file 1t 15. For example
“fib_ dat” might be data file and "fib pas” might he a Pascal
source file. For this reason the compiler insista that Pascal res-
(ites should have the extension * pas”.
15
af tha
Вы, в”.
rhe Fara
— The example program generates the first nm terms
Fibonacci sequence, where each term, beyond the first
generated from the sum of ¿ts two nearest predecessors,
но terms being D and !. Thus the sequence starts :-
0, E, 1, 2, 1, 5, A,
LI, 21,
| Before we attempt to run the file we will take a look at qr
using the editor. Select the editor command by pressing "1° —1
using the cursor control keys. Now press ENTER to run the editor
The main menu screen will disappear and a new screen will appear
wIEN another menu, This 14 the Editar File Menu. flse the cur=ar
keys to select the ‘load file’ option. When this aption has heer
Fe
selected press ENTER to use this nption,
top of the screen the prompt
In the тм о я | по
Load which file 7?
ill appear. You should now enter
mdvl fib pas
The default microdrive for the Pascal system is always drive
two, since the system cartridge is usually in drive one. If you
wish to specify a file an drive two there is no need to Jive the
drive name, but to specify a file on any other drive the name must
be given,
“a — C0 we 7) RA) de IA
3
)
displayed asking you to press any key to return to the menu - this
allows you time to examine any errors you might have,
Having compiled the file and returned to ¿he menu ve can now
try running the program, Select the run’ option and press ENTER.
You will be given the following prompt :-
Which file ? [_qlp]
The compiler always produces a file with the extension “_glp”
IQL Pascal) and again you need not specify the file extension
when entering the name,
Enter the file name
mdvl fib
The file "Eib glp” «will now be loaded, a clear screen will appear
and the program will rum. This program will prompt for a number n
and then print to the screen the first n numbers in the Fibonacci
sequence. When the program has finished you bes asked to press any
Key to return to the menu screen.
A mare detailed description of all the menu commands can be
found tn Chapter 3 of thid user guide,
CHAPTER THREE
THE COMMANDS
When the Pascal system has been Loaded the System Command Menu
is displayed. This screen allows you to select commands from the
menu and run them, and to input the data required by some commands
when they execute. The screen has three main windows :-
1} The MENU window displays the names of the seven available
commands. The cursor up { 1 and cursor down { 1 keys or the
numeric keys are used to select menu items, the current item
always being highlighted. A command 15 run by selecting ar nid
pressing the ENTER key,
2} The CONSOLE window, to the right of the menu window, 19 used hy
some commands to prompt for data and to mutpur data. Froror
messages are also displayed in this window.
1} The HELP window, along the bottom of the screen, 15 IAN Tel
give information about what input the system currently experts.
There ate currently seven commands available on the system
These are the edit, compile, run, directory, delete, copy aml exit
commands. Several of the rormands prompt for filenames ant the
following section desvribes what are valid File names.
1 FILENAMES
A valid file name can have up to 16 characters, wtncloading a 4
character extension | saaî, but not including the 5 character
microdrive name [мух |. The only valid characters in a filename
are letters, digits and underscores { ) and the first character of
the name must be a Irtter, The system does not differentiate
between upper and lower case letters and they can ba used
interchangeably. When checking the length of 3 file name the
system checks if the fourth character from the end sf the name :3
an underscore, [If the character 1s an underscore the syatem
assumes the following 3 characters to be the extension, LÉ the
character 15 not an underscore the system assumes there is no
extension and the maximum length of the specified name 15 32
characters, to allow the extension tó be added.
NARRAN TANNTNTANANNANA |
nn
}
4
er Ч "= E чот че tag?" WF wy WF FF AE
Examples : Below are shown some examples of valıd and invalid
file names
thisIsAFilename pas - valid name with extension ‘pas’
Invalid.name - invalid because of the |.)
f name - valid name with no extension
anothername ab - valid name with no extension
It a filename entered is too long the error message
“** Error - name too long
1s output and the file name is prompted for again.
if the prompt for a file name is followed by an extension in
brackets, the system will expect a file name with no extension and
will automatically append the displayed extensión to the name.
Alternatively a name with the displayed extension can be entered.
I! another extension is given with the file name, the error
message
*** Error - bad extension
Ls output and the system returns to the Command Menu.
The default microdrive (or the system 18 microdrive two and the
prefix "mdve 7 need not be added to file names on this microdrive,
3.2 THE COMMANDS
The following sections give à description of each of the
commands,
3.2.1 Edit
When this command 13 selected the screen is cleared and the
editor 158 cun, The operation of the editor is described in detail
in Chapter 4,
3.2.2 Compile
+ ï
When the compile command 15 selected the console window
displays the prompt
Which file ? [ pas|
ard the help message at the bottom of the screen changes to remind
you that the default microdrive 18 two and that ENTER can be
pressed to return to the command menu, The system will attempt to
find the given file, with the ” pas” extension, on microdrive.
Tf it is not found the error message
\ «**% Error - пот found
is displayed and the system returns to the command menu. Otherwise
the compiler 15 loaded from microdrive one and a new screen
appears. At the top 15 a title window and at the bottom is a
message window which is used for messages and prompts. The Pascal
system micradrive cartridge should always be kept in microdrive
one while the compiler is running, as the compiler needs to access
the cartridge periodically.
The compiler does not output a full listing of the file heing
compiled to the screen, unless the listing option 15 turned on
tsee 3.2.2.1), but dispiays lines with errors and the aporopriate
error numbers. In the message window 15 a prompt giving you the
option of quitting the compilation or of continuing. If no key has
been preased after thirty seconds the compiler will automatically
continue the compilation. An exampie of a compilation error 15
shown below,
Ds
Anm error indicator appears under the symbol on the sore line
«ch caused the error. The error andicators appear ~n rhe same
Line, unless two errors occur at the same symbol, in »AiCH Case
-he second indicator for the symboi and subsequent ¿mdicators
appear on the next tine, The line after the error _adicatar
linels) contains the error numbers. These are pro.ided for
Sonventance, since the 2rtor messages Can be examir=1 in the
source code using the edit listing facilitEy an the ‘troc fas
section 4.71), The *ampiler produce. © fite with the 2erenspon
LEY , which is used hy the editor to display the erınr -essages
This oprion is particularly useful LE you have a > onbar of
compilation error messages. The compiler will hatt arar went;
errors have been output. A full list of rhe rompr.ar eptri
messages and correspond: ng error numbers oan be “cui aa
for i = | to 1% do
Press ESCAPE to quit, any other key to continue
Appendix В,
] [f the ESCAPE key is pressed the compitlation t=rminates,
atherwisa it continues and Further errors, LÉ they ur, are
>utput ın the same manner, When the compilation has É--7isher gr
outputs the number of errors found, You ars then asked ro press
ny key TO return to the Command Menu.
= On
AIN NARAAAIMAAEAAANAAAA0NANAN AA
Ë
7 LA WwW WY Ye BW VU WEE Ue X
If there is no cartridge in the given drive or if there 15 no
drive attached for the number entered the error message
*** Error - not found
is displayed. Otherwise the name and length of each file on the
cartrige are displayed as shown below.
Cib pas - 834 bytes
tib_qlp - 510 bytes
letter txt - 4152 bytes
fib_err - 35 bytes
The system then returns to the Command Menu. Note that che CTRL
and F% keys can be pressed together to stop a window scrolling.
Press any key to start it scrolling again.
3.2.5 Delete
When this option is selected the console window displays the
prompt
Which file 7?
and the help message at the bottom of the screen changes to remind
you that the default microdrive is two and rhat ENTER con be
pressed to return to the Command Menu. Note that the ful:
filename must be specified for this command. If the given fita |)
not found on microdrive the error message
3
*** Error - not found
5 output. Otherwise the system will ask for confirmation of the
deletion :-
Hit Y to confirm deletion >
If esther the “Y ar y' keys are pressed the fije vil] he deleted
and the system will return to the Command Menu, atherwige hi
System returns immediateiy to the Command Menu,
3726 Copy 1
when this option is selected the console screen shows the
prompt
Which File 7
and the help message at the bottom of the screen changes to
temind you that the default Microdrive is two and that
ENTER can be pressed to return to the Command Menu, Noté
that the full filename must be specified for this command.
x
If the given file is not found on microdrive the error message
«et Error - not found
is output. Otherwise the prompt
To which file ?
is displayed. The new file name should be specilied in full. IF
the file to be copied to already exists, the message
File exists, Overwrite ?
ts displayed and if you press a ‘ХУ’ ог ‘y’ the file will be
overwritten, othervise you will return to the Command Menu. When
the {ile has been copied the system returns to the Command Menu,
32.7 Exit
When this command is entered the screen will be cleared and the
Sy SEM Will return to BASIC,
\-
4
PANTANRTNANANANNTAACANTnNA RA
q
+
="
+ Le № \№ d_ e FF WW Ww
J_
TTT a пинннЫиА О — o
—
— ICHAPTER FOUR
|
| THE EDITOR
The editor has peen designed with ease of use in mind. It make:
use of the cursos control keys, situated on either side of the
space har, and the function keys on the Left hand side of the UL
keyboard. It also provides a menu similar to the system commard
menu, to allow you to select file saving and 1cading option.
easily.
41 EDIT FILE FORMAT
characters, the lines
These files are calied
Edit files consist of lines of printable
heing separated by the line feed character,
text files. Although the editor only allows you to create ext
files it does NOT check, when loading à file, that the file onl.
contains printable characters and line feeds. However yOu are
sErongly recommended to edit only text files.
edit Lines Can onty be as long as the edit window. However
ehere 15 à special character ‘ес’, which, If it occurs as the
firat character ON a line, will be treated as 3 cuncatenatior
character, When à file 15 \gaded from miccodrive, any lines longer
than the adit window will automatically be split, with cho
concatenation character being inserted at the gplit. When à Fol.
19 saved, a line will De joined to the previous line 1£i tho
coancarenat ion character appears at che beginning of the Line.
if this character ¡5 deleted it causes a permanent split 1n th
Line.
42 EDIT FILE NAMES
rhe editor will allow any file name +9 be specified | SE"
1.1 for valid file names | except a name with the
err or ~ qlp , since names with these extensions Tal
meaning un the Pascal system. If. when the edi=or 1°
for a File name, AN invalid name 15 qiven Or à fil:
\gad a file, à File
segri1ON
extension
a apecial
prompting
рог GCCUTS (for exampie when atrempting tO
with the given File name must existl, an error message Ls
displayed 16 the help/error window and the file name prompt +;
redisplayed.
- 14 -
‚ен
43 EDITING A FILE
}
er
when the editor is invoked [rom the command menu a new screen
appears with four windows - an edit window, In whıch the editiny
of text takes place: a prompt window, in which the editor displays
prompts and receives input 1 for example 3 file name |: à
help/error window, in which error and help messages are éisplayed;
a lift window - the lift facility is described 1N section 4.6- À
menu will then appear on the screen, allowing you ta choose the
file you wish tO edit or to choose TO edit a new Enle- This menu,
called the Editor File Menu, ig described in section 4,4.
When a file has been loaded the edit screen will appear with
the first few tines of the file. The Cursor, a solid green
rectanglé, will appear over the First character of the file. IC a
new file Ls being edited the edit window will be blank, except for
che cursor which will be at che top left corner. The cursor
represents the current editing position IN the file and all
editinq operations take place at the mirecy Post” LON. whether 3
new file is being edited or an existing file 18 beung edited, The
operation af editing the file is exactly the same and 19 described
in the following sections.
4 3.1 Moving the cursor
can be moved anywhere tn the file by using the [Pur
keys which are situated on either side of the spauve
the cursor one
The cursor
curser control
bag on the GL xeyboard. Fach of the keys moves
character position LA the direction shown on the key. There are
several special CASAS which affect The mAvement nf The cuESeT
1) If the cursot igs moved right when 18 48 ar the aml of a (ur +
neues to the start af the next Line.
jy Lf rhe cursor 15 mowed left when урок ar the ho LITT AI of
line it moves TD rhe end nf “he preyvinis Line,
1) If the cursor {5 moved ap or down and the previous of next lune
1% shorter chan the curren” DIF the curso MAYES rey the end of he
naw line.
1) IE the cursor ma. ay off The Tap ar bottom of the screen the
text 15 moved so that Thé печ cargór line 18 TN rhe centre af the
screen. L.É- the wir sep up or down by hall the number mf
tunes On the screen
pamains stationary LE any ATTEMPT dis made to MOVE RT
ar end E The file.
31 The Cursor
Aff the beginning
AAA NA AAMAMAAAAAMAAAANE
¢ FWP UE EE HU
vw
BERK:
4311 Paging
[f the SHIFT key and the cursor up Or CUrsór down keys are
pressed together, the window will scroll down or up by the number
of lines that will fit in the window. The cursor is set to the
middie of the window.
4 1.2 Inserting Text
To insert text simply start typing characters at the keyboard.
Each character is inserted at ehe cursor position, and the
character at rhe cursor position and all characters to the righ’
are shifted right by one Character position. when the cursor 1%
rhe last character on a line and a new line ¿is required press the
ENTER key and a blank line will be inserted below the current
tine, with the cursor at the start of the new line, The editor has
an auto indent facility which sets the cursor under the first
non-biank character of the previous line when a new line is takefn,
Lines can only be as long as the window and any attempt Lo
insert a character which will make the line too long, wiil cause
the (1, to emit a beep and the character will not be inserted.
However che end of line character «an be inserted and if you wish
to have the line longer than the edit window, he can continue the
line by inserting the spécial character ‘ке’ at the beginning oF
the next line. This character 13 keyed in by pressing the CTRL,
SHIFT and X keys together. The editor will automatically remo
this character and the preceding and of line character whan EF
frte 159 Saved.
43.3 Deleting Text
The character to the left of the cursor can be delatod db.
pressing the CTRL Key and the cursor left key together. Th
cursor and all characters to the right are shifted left by an"
character position. This 15 the opposite of inserting A charicter
and 19 useful for correcting Eyping ACrrors AS "ext is bridas
entered,
The character under the cursor can be deleted by pressing th
CTRL key and the cursor right key raogether, The cursor remains |
rte sam: position and ali chacrersito the right of the Cursor 11
ghifted left by one character position. L
Note that the last Character in a file 15 atine Teed chartete”
and cannot be deleted.
[£ the CTRL, ALT and cursor lefrior tight) keys are presse:
together all characters from the rurser position to the start ier
end) of the line are deleted. +
Tm we Te mee СО
mm a ST
—
— rr — A A —
4.3.4 Splitting and concatenating lines
A line is split by positioning the curser at the position in
the line where the split is required and pressing ENTER. This
causes the character under the cursor and all characters to the
right to be inserted below the line.
Two Lines are concatenated by deleting the lire feed at the end
of the first of the two lines. The line feed :5 always the last
character in any line and is represented as a blank, The line
feed 13 deleted in the same way as any other character, using the
CTRL and cursor right keys if the cursor is over the line feed, or
using the CTRL and curscr left keys if the cursor is at the start
of the next line. when the two lines are concatenated all lines
below will be scrolled up by one line. If concatenating the two
lines will make the resulting line longer than the edit window the
OL emits a beep and the line feed character is not deleted.
“However the two lines can be concatenated when the File 15 saved,
by inserting the concatenation character «at the beginning of
the second line. This character 15 entered by pressing the CTRT,
SHIFT and X keys together,
4.3. 7 Finishing the edit session
when you have finished editing the file, or wish to save the
file and continue editing the same file or another file, The
function key El can be pressed to select the Editor File Menu
hier allows the file to be saved, The Editor File Menu 15
described in the next section,
44 THE EDITOR FILE MENU
This menu appears on the screen «hen the editor 13 run from the
Pascal command menu, or when the function key F! 13 pressed. When
the menu is displayed it appears with a number of optiens. Each
option i5 numbéred and 15 aeierted by pressing the required mumber
or 15:19 the cursor up and cursor down keys to step through thé
optiors. The currently selected option 1s always highlighted. When
the required option has been seircted the ENTER key should he
pressad to use the option. In certain cases some of the options
are unavailable, for example the save’ options Cannot be used
when no file is currently being edited, When an option 15
unavailable 1* is displayed in red ( aptions are поста | Ту
displayed in white | and cannot be selected using the numeric or
cursor keys. You can press the Fl key again 1f you want Eo leave
the File Menu and return to the edit window. When you are prompted
for a file name you can just press ENTER to return to the menu.
Each af the options 15 described below.
Fa
о ттт тот ттт
й
mA N RR TR TKM
7)
Eo
4.44 Save and Continue
tly being
) This option 1s available only if 4 file is curren
edited. an existing file is being edited the Eile is saved and
you can continue editing. If the file being edited 148 a new fiie,
the message
save Eo which file
;s displayed Ln the message window and the file is saved with the
given name. You can then continue to edit the file,
If the file being saved is a listing file, none of the error
messayes are saved, but the err’ file 19 deleted since the
complied file has now been edited, and che arror méssayes are no
Y 5 apprortate.
44.5 Save Listing
This option 15 Only available if the edit listing facility is
y being used.
The listing, the file with the embedded error messages, is
saved to 3 file with the same name as the file being edited,
except that the extension iis is used. This option is ugeful if
you wish to print the listing file. When the listing has been
saved you can continue to edit the file,
4 46 Save and Leave
This option 15 only avarlable 1f a fite is currently being
edited. Pf an existing file is being edited the file is saved with
rhe PxiSTiNng File name, otherwise the file is a new file and the
message
save to which file
appears Ln the message window and the file 14 then saved with the
given file name. LE the Fdit listing faciiity is currently being
used the ‘ err file 15 now deleted since the compiled [ile has
J pean pd) red,
When che file his been saved the editor 19 exrted and the
system returns to the Command Menu.
—l
a
3
de
LOA RAMANA RAM MAMA DM
da
¿
4
==
[dd
RP AAO AM MON
ua
4.4.1 Create New File
If no file is currently being edited the edit window is Cleared
you can start editing a new file. IF a file is currently being
edited 1t is saved if it is not a new file, otherwise rhe prompr
save to which file :
dppears in the message window and the file will be saved with the
entered file name,
44 2 Load file
LÉ this option is selected and a File 15 currently being edited
the same procedure is carried nut as described for the above
option 4.4.1, When the current file has been saved, or no file ye
currently being edited, the message
load which file +:
зрреас$ in the message window. The editor then loads the Qıven
file and the edit window appears with the first few lines Of the
file. You can now start editing the file,
If the file name given has the extension pas the ediar
checks if there is also a file with the same name, but with rhe
extension err. If one exista the editor automatically uses tve
rr fte to produce a listing which allows you ro see the arco
messages produced when the specified file vas last compiled. The
Edit listing facility 15 describad in section 4.7.
4.4.3 Save a Copy
This option 15 only avaitsbie when a file rs current, per
edited, The message
save tn whieh Fale
Appears 18m the nessage window and the File is saved wirh rhe ai
File nama. Yon can then continue editing the same file, Note tha
saving a copy with a given file name toes not affect rhe name of
the file being edited, 1.e. the file being edited still has ara
Original file mame,
4.7 EDIT LISTING FACILITY
Г
oa be edited, while
4.4.7 Leave this facility allows Pascal programs to
>) ‚ looking at any error messages produced when the program was last
. This option quits the editor without saving the changes ar: compiled. The compiler produces a File with the extension @TE ,
- + x . x . Ц 1 Я
returns to the Command Menu. IE a file is currently being adjros which contains information about the errors. IÉ you choose to edit
| "1 and an err
the message a Pascal file { a file with the extension _pas — |
| file exists for the Pascal File, then the editor automatically
Lose changes ? | uses the err file to produce à listing, which appears in the
adit window as a normal file. Below each line of the gite which
| | nd | Y. had a compilation error, 19 a COPY nf the line and the error
1s displayed 1n the message window a only if you enter Y or a р opy of the Line and meer 8
y will the editor be exited. Otherwise the edit window wil] be messages. Each error message is
redisplayed and you can continue to edit the file, which cannot be deleted or inserted in the editor by the user.
The Eile may be edited as normal and when it is saved any parts
45 STRING SEARCH of the file enclosed in the ‘y's are not written to the microdrive
file. Thus the error messages are removed when the file is saved.
The string search ts initiated uhen the function xey F2 1 i When the file is saved the err file is deleted, since the
pressed. [15 searches for a given string from the current Tursor arrors wiil no longer be valid for the changed file. Tf, when
position. When F2 is pressed the message saving he file, the ‘gave listing option is chosen ( see 4.4.5 |
the whole file, including the error messages, are saved to a file
with the same name as the Pascal file, bur with the extension
lis.
search for which string
v3 displayed 1n the message window. You should then enter TN
required string. Tf the string 1s found in the text the cursor + \ -
set to the last character of “he string. If the string 19 ne
Found the cursor position remains as it was and a beep sounds. :
FZ 1s pressed together with the SHIFT key, a search 15 made го:
the string specLfied in the last search. If, when the prompt for »
SLE Mg Ls dasplayed, just the ENTER key 15 pressed, vou wil,
immediately return to the editor,
Vd Judd
d
46 EDITOR LIFT
The Lift 13 a means of massing; through a file quickly na
easily. while in normal edit мое tne lift arrow moves up and dns!
18 the cursor 1% moved up and Jown through tha text. The top -'
the Life window represents the top of the file, the bottom 0:
the lift represents the botte of the file and she 1.ft ares
represents the cursor positior in “he Cale,
Jo dd
when the function key Fl} 1s pressed the editor goes into TIT"
mode. Lift mode allows you to -ove “Me lift arrow by using “ne ны;
> ) and down carsor keys | for extra speed use the ALT key and Cursor }
= ip or down 1, Whea FJ is pressed again rhe editor returns to th
normal edit mode with the cursor in the position impliad by the
Mi ifr arrow . This 15 most useful for Inny fi1ies where paging man.
LiMes becomes tiresome
1
U
20 -
Add
пепел пт еле пене мая
и — TT PO LE” W W VW VW W ZE u y J & & YU UY
mm НН
г
— ———ICHAPTER FIVE
LANGUAGE DEFINITION
Computer One Pascal is close to the [SO Pascal standar
specification, with the following main exceptions ;-
l} Procedures and functions may not be passed ag paramerers.
à! T0 has been expanded and modified slightly, in order 9 gy.
the user the ful] benefits of the QL I/0. See section 6.1
Jt The dispose atandard procedure is not supported,
Procedures, mark and release, are Provided
allocated to dynamic variables, See 5.3.6,
{(nscead pw
to release spac.
1) No checking of assignment to the control variable of 4 for
loop 18 made, either direct or indirect ISS1g9rNment, i,e, whether
rhe variable 18 actually assigned to in the body of the 1659 or
whether the variable 15 assigned ro in a procedure or ÉEynorie-
called from the body of the loop,
5} Corns MAY not Jump cut of procedures or functions.
hl The ond of line character | ASCII! code 10 |:
15 returned ah.
the last character of the line of a text Fil
e 14 read, ;
f1 The standard procedures read and write app!
y onli, e.
rextcf log,
In the following sections describing Pagral
PACT Seta described ig Usually given.
Une Prscal is given in Appendix C,
4
the syntax of +-
The full ayntax of COMPRA rn
The notation used wiehin che text for describing the 8yrntax |
Similar to Backus-Naur Form, An example of a rute ja
program = program-heading block * "
This can be read ag "a Program consists of à Proqram-hesdin
foliowed by a block followed by a period”, Special aymbols уг
Pascal, defined in section 3.1, are always enclosed in quotes ın |
rule. Any entity in a rule enclosed in curly brackets (o fro:
indicates that the entity is repeated zero or more times,
- 22 -
Li i a
An entity enclosed in square brackets [ [! ) is optional. If
entities are separated by a vertical bar ( $ J), this une
that one of the entities is selected.
Examples : |
© (1) integer = [sign] unsigned-integer
(2) unsigned-integer = digit [ digit |
13) sign = "+"|7——"
These ruies can be interpreted as follows
[1) an integer is an optional sign followed by an
unsigned integer ВЕ
(2) an unsigned-integer is 31 digit followed by zero or
more digits |
13) a sign is either a plus vr a minus
5.1 FUNDAMENTALS
19: Lai
The alphabet of Pascal consists of letters, digits ecording я
symbols, Sentences are constructed from the 21 phaber accord oe
t differentiat
the syntax of Pascal. Pascal does not | Pr
and lover case letters, except in strings and comments, and they
may be used interchangeably.
The special symbols in Pascal are shown below
+ - / . = <> ¿ > <= >= = ( ) [ ]
] r r - + ”
м Зо to or LÉ 1n ne dv mad per and
end var mil for then E, e file wit | чого
case alse until while begin const labe on лу
repeat downto packed recned program functio
procédure
Computer One Pascal contains four additional symbols
bor hand bxor bnot
it
The words which are special symbols are reserved words and may
be used for any nother purpose.
5 1.1 Numbers
, InNtcduer
Pascal numbers may be either LAtegers or tivo os a
number is a whole number which may be positive, tio 11 receded
The number (a written as a sequence of digits, optionally p nan
by a v9n { + or = E. No other characters must appear
integer, In Computer One Pascal the range of integers is
- 21474836547 ко +214748 1647
LACA
Ta
=
na
Tm
т +
Ve
+
м”
VENU VUE d
do
JU
A ceal number, which may be preceded by a sign, may be written .n
one of two forms.
(1) The number has a decimal pecint, which must be preceded ar
followed by at least one digit.
Examples : 1.2
-34.789
+0.45609
-0.9067
{2} The number is expressed as an integer or decimal number
multipiied by an integral pover of 10, known as the exponent, Th
exponent 15 preceded by the letter E or ‘e’ and an optional
sign.
Examples 2.)E6
54E+5
45.6E-)
0,7682
In Computer One Pascal the range of real numbers 15
+/-{1E-615 to Î1E+615} with B significant digits
5.1.2 identifiers
Pascal adentifiers, which are names used to idancify Jara
incations and pieces of program text, consist of a letter follo=e"
by any number of letters and digits.
Examples : a
currchar
x 4
extreme lylangname indeeed
in Computer One Pascal identifiers can be any length, but anly Li
firar eLght characters are significant. Remember that reserva
words cannot be ased as 1ıdentıFLıers.
5.1.3 String Constants
A Pascal string constant consists of a sequence of charicrter
encio-ed in quotes, If a quote itself? 15 required in a string it
should be written twice. A string -onstant of length one 15 A
Character constant,
‘helio
‘Lt don € know”
Examp tog
y curly brackets [ 1 } 3.
—— o а
- ” ый L «FELT. —. Er
There are a number of characters which have a special meaning when
they are preceded in a string by the . ingle goute character. These
characters are
A: This represents the character line-feed
‘Tr : This represents the character carriage return
‘t : This represents the TAB character
"Pp : This represents the form-feed character
0 : This represents the nut] character
A
These characters are useful for formatting cutput when using the
write statement { see 5.6.2 J,
5.1.4 Comments
A Pascal comment is a sequence of characters enclosed either in
Comments may appear anywhere in the text,
except within an identifier, number or special symbol, and have no
effect on the execution of the program.
Example ( this is a comment + |
) 5.2 PASCAL PROGRAMS
Every Pascal program consists of a program header and a block.
program = program-héader block *_"
The program header gives the program nameand the parameters.
in Computer One Pascal these parameters need плот be specified.
They are tgnored by the compiler.
A program block consists of a number of declaration parra
followed by a statement part.
block = [label-declaration-part]
[eonstant-definition-part]
{type-definition-part |
tvariable-declaration-part)
procedure -and-function-definition-part
statement part
5.2.1 Label declarations
Label -declaration part = "label" labet (“," Label Poo"
Any program statement may be marked by prefixing the statement
with a labe! followed by a colon. The label is defined in the
| declaration part and is an unsigned integer in the closed range Q
to 9999,
RAA AAAMAU AAA AM AMOM NN
=
ME CU
5.2.5 Procedures and function definitions
Procedures and functions are described in section 5.5
5.2.6 Statements
Sratements are described in section 3.4
5.2.7 Scope
In Pascal all declarations have acope. The scope of a
declaration 13 the routine ın which it 13 declared, together with
any rovutines declared in that routine and any routines nested
deeper within these routines, Declarations in the main program,
which are global declarations, have the whole program as “eir
scope.
Qutside ita scope a name 18 UNKENOwN and the same name can be
used LN other declarations. LÉ a name 13 declared within the scope
If a declaration with Che same name, the inner declaration
pvergides the outer one. This i% known as a hole in the scope of
the quter declaration.
Exampir
procedure a ( bb integer: c : real )
| start of scope of a, b and € |
var à rhar ; | start of scope of d |
procedure boy
i this LS 3 hole in the scope of the 1iNteger В |
var Я + Charo oy
{ this 153 a hole 1n the acope of the outer Ad |
begin | body of procedure h |
end | procedure b and ınner J go out of scope here |
| Integer band cuter d back 18 supe here |
begin Po Dady of peocedure a)
end
| b, €, Jd are now out of scope |}
¡E
DANN О TANT NM
5.2.2 Constant definitions
Constant-definition-part = “const” i1dent "=" constant ":”
{ ident "=" constant “;7!
Constant definitions are used to give names to constants.
Constant identifiers help to make a program more readable. For
example ve might define
const 16 = n°;
er = ‘tr’;
to give names to the ascii contral codes line feed and carriage
return. In our program we would then use the identifier It
everytime we want to use the control code line feed,
The use of constant declarations is alse useful for constant
values, which we may at a later date wish to change. For example
implementation dependent constants. It ıs considerably easier tn
change the definition of a single constant 1dentifier than tn
search for and change all the sccurances af a particular constant
in the program.
5.23 Type definitions
Type-definition-part = “type” 1dent "=" type
tident "=" cype "7
[п Pascal data types can be described in the variabi-
declaration part, or may referenced in the variable declaratinn
part using a type identifier, which has beep defined in the туре
definition part. Section 5.1 contains a detarlead 157049565100 orf
data types, describing what standard types are avıllable and how
new data types can be defined.
5.2.4 Variable declarations
vartiable-tefinitinn-part =
var” ident [7,7 1denr ! " type
Г адепт {1"," Ldent | "1" type
Exampia
var Y, № integer
c : real
d : array [1..10] of char
The type may be a standard type, a type description or а турс
identifier. Every variable used in a Pascal program must te
declared ın a vartable declaration, unless 1t 1s prederlarsd.
Note that a variable may not be declared more than once in the
same variable declaration. i.e. the following 1s illegal
var x char;
x : integer;
53 DATA TYPES
асе AU types in Pascal can be highly structured and complex, but
type is ne droite from unstructured types. An unstructured
efine y the prsar |
standard scalar types. Programmer or is one of the Four
5.3.1 Standard Scalar types
The four predefined sca
char. Р 7 far types are Integer, real, boolean ar?
5.3.1.1 Integer type
: A value of typa integer 18 a whole number whose range of values
+ restricted by the implementation. In Computer Üne Pascal i
inreger 1% 4 bytes | o
421474816447, y ong, GLYLAG à range of values 7147483647 ©;
AcitTthmetic Operators wh
teh take ante
+ add
- subtract
* multiply
div whole number division
mod modulo | remainder afrer division |]
Example
H div Y = 7
B mad 5 = 1
5 - 9 = _4
The operators +
Operators and - can he A 1
A Зе US#7 to denote the 519n of th:
Fwamprle - "difference
+2
я +=
aE HTOYIdes a number of srandard functions which may be
a + G'untegérs. The standard functions are described nr
Chapter ?.,
An A
other umber of the standard functions that relate LO LNTèégers spi
VASFrultured types, except reals, are intraoduced below.
The type integer defines an ordered set of values whose range
depends on the implementation. Each value has a successor and a
predecessor { the least value has no predecesscr and largest value
has no successor |) and such a type is called an ordinal type.
Pascal provides the functions suce’ and ‘pred’ со give the
immediate successor and immediate predecessor of an ordinal type.
For integers these functions are equivalent to adding and
aubtracting |.
There exists a standard identifier maxint whose value 15
+2147481647 , which can be used for comparison purposes to prevent
integer overflow,
5.3.1.2 Real type
A value of type real is an element of a subset of real numbers
whose range is implementation dependent. In Computer One Pascal
the range of reals is
+/-=[1E-615 to lE+615) with B significant digits
Arithmetic operators which take real operands and return
real results are :-
+ add
- subtract
: multiply
/ real division
Example :
21.5 + 2.17 = 23.8
8.0 ;, 5.0 = 1.
5,0 - 9,0 = 4,0
The operators * and - can be used to denote rhe sign nf rhe
operand,
Example : “sin {x}
+2,67
Integer types may algo be used in real arithmetic. The
operators +, - and * may be used with one real and one integer
operand to produce a real! result. The operator / may be used with
two integer operands to produce a real result. Remember LÉ the two
operands are integer an integer result will be produced except
«hen the operator 15 /.
Lo
Examples :
т + LT
ый 4
tig Ler A
B
4.
4.
Fg y
5
‚0
As well as the operators described above Pascal provides a
number of standard functions which may be applied to reals. The
standard functions are described in chapter 7.
- #9 -
> E ED AAN se MD A A A A
E — as AR A
Note that real is not an ordinal type and cannot be used wi-n
the atandard functions ‘pred’ and "succ’. Nor can it be used as ;-
array index or base type of a set. |
5.3.1.3 Boolean type
A value ef type boolean is one of the logical truth val...
true or false. True and false dre predefined ordinals su--
that )
pred [ true |} = False
sure | false ) = Erue
5.3.1.4 Char type
А vaive of type char is an element of the OL character ses
The UL character set consists of the ASCII character set, which ::
represented by the ordinal values O ta 127, and the OL Epeción:-
characters, which are represented by the ordinal values 129 =:
255, The full QL character set and equivalent crdinal valse +
(ASCII codes) are given in the QL User Manual. Throughout eb:
manual the character set will bé referred ro as the QL ASCII ser
Li
A value of type chac is an ordinal value, the order;
defined by the QL ASCII codes. Thus Ting bet:
suce EP OA | = В’
pred 1 O 1 = ‘/ since ASCTI code for ‘/' is | less rha-
the code for ‘0’
The standard function ‘ога’ 15 used to map the charicrer sr”
nro a set of NOR Negative integers starting at zero ‘and e
function chr maps the ordinal number i onto the equivale:
character. The set of inteyers onto which ord’ mags rhe aer
tet 15 the equivalent QL ASCII code of each character similar
Tht maps a GL ASCI{ code onto the corresponding character Th...
Sra 1 0 ol = 40
ord i Е + » 49 ato,
che | 48 1 a |
chr { ard (0 ) ) = 0
H
532 Enumerated and Subrange types
enimerared RAN are user-defined scalar types vhose definir
Indicates an ordered set of values by enumeratin ide
which denore the values. ’ a 9 che \denitrs
“type” 1dent = "{" 1dent { *,* ident I
Example :
type colour = { black, blue, red, magenta, green cyan,
Yellow, white )
The relational operators can be applied to enumerated types, as
cap the standard procedures pred, succ and ord. Thus using the
above example
[ green ) = Cyan
[ white ) = yellow
ord { red ) = 7
{ yellow | = 6
Mote that the boolean type 15 equivalent to an enumerated type
[ false, true |
A variable may take a range of values which 15 a subrange of
the value described by some ordinal type. Its type is then defined
to be a subrange of the host type.
subrange-type = constant *..7 constant
The constanta must both be of the same ordinal type.
Example :
age : 1..100
subcolour blue..green ; | using tha = above colour
definitian |
ascii + OD .. "°° : | the ASCII character set |
Each value of a subrange is taken as being of the hast type and
operations on the host type can also be applied to operands of rhe
subrange. Thus the functions nord’, succ and pred can be
applied to subranges and chr’ can be applied to a subrange nf
type char.
Hote that the compiler only allows fifty distinct subranges.
533 Array Type
arcay-type = “array” "|" index-type 1". “index-Eype)+" ]* "af” type
An array consists of a fixed number of components, all of the
same type called the hase type. Each component of the array 19
accessed by the array variable and an index. The type of the
base can be any type, the type of the index must be an ordinal
type,
essere тебе тит,
1
Ld Jd dod dod J UU WEEE SE $8 OB VY
Example
var lengths : array [1..8] of integer y:
identifier : array [1..20] of char ;
code : array [letter] of integer ;
m : array (1,.10) of array (1..20) of char:
The lower bound of the array must Lie in the range 9188608 +
+83868607,
Note that Computer {ne Pascal does not support packed da-3
structures. The compiler will ignore the word "packed" when 1"
appears before the word “array”, “record”, “set” or "Eile".
when accessing Arrays the array index can be an expressiur,
which is of the index type.
Example
lengths {x mod 8] := y * z ;
currcode 19 code | currietter | :
where x is of type “integer and currletter is of sor
user defined type letter .
For multi-dimensional arrays the declaration can ce
abbreviated. For example the array m dectared above ran Lo
declared as follows
var m : array [1..10,1..29] of char
A mulrci-dimensional array is accessed in the same way as i
single dimension array, using a number of indices, For exampla
rould be accessed as follows
mi2,6] :* ‘а’;
m 17] i6] = a’
; [ equivalent to above |
curpoehar = m x, y | :
m (11 [2] := mm |2} £2] ;
If twn arrays are of the same type, (| see 5.3.8 on ey:
compatibility | then it is possible te assign the values of one si:
the arrays to the corresponding elements of the other array ima
single assignment statement.
Examples : _
var x : array [ 1..19, 1..90 ] of char ;
The statement
x [1] := « 12] :
copies 80 characters from x [1] to x (21.
type line = array (1,.80} of char:
var thisline : line :
fulltext : array [1..109) of line:
fulltext | currtine |] := thisline;
In this example ‘fulltext 15 а 15 а hundred line array, each line
being 80 characters, Since thisiine is of type line and each
element of ‘fulltext is of type line the two are assignment
compatible,
5.3.3.1 String arrays
In Computer One Pascal the data structure of type
array (1l..n| of char
ig called a string array and has a “ivther of properties which dr
not apply to other arrays. For rxame © The string
hello there
is a constant string array of type arcay [1..11] of char.
Variables ef this type are atring array variables of length в.
A string array, whether constant or variable 1% assignment
compatible f see S.I.B.t ) with any string array of the same
length.
Example : If we have a variable string array declared as
var Tiny array E1..M) nf char
then ve can write the sritement
city = London 7
String Array, unlike other arrays can be Sed A5
parameters of «rite statements.
Example : writeln f city is , city !
String arrays of equal length may be compared using the relational
operators. These operations use the convention used in dictionary
ordering «hen comparing string arrays,
+ 13 -
опт т ттт апт тет NN
Te ver "ща = Ur we E E + i of Ь М МР “и Là !
Examples
“ABC” < ‘BCD’
ABC € ABD”
The above two comparisons are only true if all characters are the
same case, either ail upper or all lower,
ASCII character set all upper case letters
the Lower case letters. Thus
Aa”
‘2° ¢ ‘mn
XY? € abc”
5.3.4 Record type
If city = "London ' then .......
since when using the
have lower values than
It 13 often convenient to organise a collection of data Ln
which the items are not all of the same type. For this purpose
Pascal provides the record. A record is a structure with a fixed
number of components, called fields. Unlike
need not be of the same type.
an array these fields
cecord-type = “record” field-list "end" “;”
Freld-list = (fixed-part [*:* variant-part) |
variant-part f*;"}]
fixed-part = ident | =," ident | "." type “;”
| ident | ",” ídent | *:"
Example
type person = record
name : array El.
#
type ";" |
20] of char
sex : [ male, female }
age : 1..t70 ;
rnd ;
var p : person ;
p con be assigned to as fol lows
p.name :# ‘Gunn Ewan ALA, a
р.зех := male :
p.age ı= 2 ;
As with arrays, Computer One Pascal does
records.
In addition to fixed record fields, as
ahove, records may also have a variant
variables to be of the same type, but to
"sing the above example we might wish to add
NOL support packed
shown in the example
part, which allows
differ in structure,
a field to the record
Jiving the place of birth, 1f the person is a national, or giving
"he country of origin and date of entry 1E thé person is
foreigner.
The record definition would be as follows
type origia = { national, alien y y
person = record
name : array [1..20]) of char;
чек : {| male, female |;
age : 1.,100 ;
case country : origin of
national iplaceofbirth:array [1..151 of
char):
alien : | countryoforign:arcay [1..15) ef
char;
dateofentry: record
day : 1..1t
year : 70,.90:
math : 1..1%;
end):
end :
The structure of the record is dependent on the value of ‘country
- if country 18 set to ‘national’ then piaceofbirth can be
accessed, if ‘country is set to ‘alien’ then the two fields of
‘alien branch of the variant part can be accessed. The [eld
‘country’ is known as the tag Field.
Exampte :
p.Rame := Savedra Sean ;
p.sex := male ;
p.age := 24 ;
p.country = alien ;
p.eountryoforigin := A country
p.datecfentcy day ı= 27 ;
p.datecfentry. year := 65
p.dateofentry math :> 6
Note that having set the country field to alien at would be
illegal, for this particular variable, to a= empr tn arcess The
‘placectbhirth’ Field, It 15 the resposibility of rhe programmer To
ensure that this dos not happen,
Only one variant part 15 allowed in a record and must foilns
the fixed part of the record. However the variant part of rhe
record may itself have variant parts, IF a freld nf a variant part
is empty the form of the Eiteld is
lab-list : 11
n
RP ANANNAN NANA
m Mm a
N_N A AM
1 4
?
dW WW UE WW TE WW W“w + ES
6.3.5 Ser Type
aet-type = "set" “of” basé-Lype
the base-type must be an ordinal type.
Е le
xem type months = ( Jan, Feb, Mar, Apr. May, Jun, Jul,
Auy, Sep, Oct, Nov, Dec |;
year = set of months ;
A set consists of a subset of elements of the base-type. Thus
in the above example the set year can Consist of any subset of the
twelve months, including the empty set and the full set of twelve
months. In Computer One Pascal sets can have up to 129 elements,
having ordinal values 0..137. Since the QL character values 30
from 0 to 255, the set, set af char, cannot be uded, However t nr
predeclared subrange ‘ascii, which is of type char, has ordinal
values vhich are the ascii Codes 0 to 127.
Sets aro bullt by specifying their elements, qéparated by
commas and enciosed in square brackets. Expressions appearing in
che element specification must all be of the set 3 base-type,.
ample
mem | Apr, Jun, Sep, Hov ] denotes a scr of type year
containing the months having
10 days В
| a..z, A .. LT | denotes set of char containing
only the alphabetic characters
as elements,
The ser [| denotes the empty set, the set containing né elements,
The allow vw operators Can be JS AN SES
r man
. [ntersACtion
- Difference
ногу equality and inequality
пота ser iINClusion |
I Fr tests 1f element ofl base-type is In a sot
Fxamples
16) gives (a
b | - l'a,e | gives | b |
b' | "| a,c, d} gives [ a |
= c
#
+
‹
} qives false
a b |] quves true
a, bi gives true
e. dl qives false
b | gives true
E dl wr de
-
= == — — — — === ы
5.3.6 Pointer Type
pointer-type = """type-ident
A variable which is pointed at by a variable of type pointer
is a dynamic variable. A static variable is one that is declared
in the program and is subsequently denoted by its identifier. Tt
has storage allocated to it during the entire execution of the
block in which it has been declared, With dynamic variables
storage is allocated by an explicit call, from the program, to the
standard procedure ‘new and the variable created by new’ is not
referenced directly by an identifier, but by a pointer to the
variable. Linked lists and trees are easily and efficiently
constructed and manipulated using dynamic data structures,
Although a pointer is bound to a particular variable type by
its declaration, all pointers can be set to the value mil
indicating that the pointer does по? point to anything. Pointers
can be tested for equality with the value nil.
Note that for pointer type declarations only, a type identifier
may be used before it ts declared,
Example
type link = ‘info ;
info = record
number : integer y
next : link :
end ;
The field next is a pointer which points to a variable ef typr
info . Thus we can build up a linked list ef variantes of Type
‘info’, as shown below
var first, per : link ;
first := nil : | 1imitialise to null pointer |
for 1 := 1 to n do
begin
new (| ptr 1; | create a new var of type info |
ptr. number := 1: | set the number fieid of the var |
ptr. next := farst | link in current var to list |
First := BET y
end:
Note that a pointer that has nor been assigned to does ant have
the value nil, but 1s an uninitialized variable,
Dynamic variables cannot be allocated space in the same way 3"
other variables because the space required is not known until cor
time. For this reason Pascal maintains a heap. A heap is just an
area ©Г free storage, which is used for aliocating and releasing
the spare required by dynamic variables, The space, AS mentioned
previously, is allocated using the standard procedure new amt 3s
released using the standard procedures mark and release .
- 47 -
LAN NARRAN UNNRNN LUNUANN ANNA
If we have a pointer te a type t, then the effect of th:
procedure call
лем (р!
15 to allocate enough space on the heap for a variable of type т
and то set p to point to the variable, If t is a record with =»
variant part { see 5.3.4 } the amount of space allocated 15 enoug”.
for the largest variant. 1É the tag fields of the neste!
variant-parts are tl..tn then the call
new (.p, El, ti,..., th]
allocates just enough space for the variants specified by The tar
values El..tn. The tag values must be constants and must b-
contigucus and listed in the order they are declared. The ra:
values are not allocated to the tag fields by this procedure, but
the user should ensure that the correct tag values are alimcate
when the record is used,
FExampie
type origin = ( national, atien ) y:
person = record
name : array {1..8] of char ;
age : l,,100 ;
sex : [ male, female } ;
case country : arigin of
rational : 4 giaceofbireh
arrayl1..8| of chart;
alLen : | countryoforigun
array(l..A] of chart:
dateofentry : reçrrd
day : l..10:
ус: 70,,7960;
men : l..12:
end 1:
en!
чае ро: person
The country field 13 the tag Freld зп ra allucate 155 end!
apare fer a national =e would ase the oll
, new { p, national |
Consecurive calla ta the procedure new allocates
Snniqunus space on the heap, То release space on the heap, th
procedure mark 15 used to det a marker on the heap and th:
procedure release 19 usad ro те] паче all the spac:
allnçatrd since the call to mark . The procedure mark
Yikes a pointer p as a variable parameter and release fakes pos
a value parameter. when a pointer has been marked, all the spac
on the heap allocated after the dynamic variable specifier
15 releascd by a call to ‘release with the parameter р.
- 18 -
Note that if a number of calls to mark” are made, the calls
"ro release should be made with the parameters in reverse order to
the parameters used for the mark calls. Variables must not be
referenced after the space allocated for them has been released.
Example :
type link = “info ;
info = record
number : integer ;
next : link
end:
var p : link : | could be a pointer to any type |
ptr, First : link ;
first :» nil :
{ mark the current heap positinn |
mark Ep:
for i := 1 ton do
begin
new [ ptr } :
ptr” .number := i y
ptr .next :# First ;
first := ptr
end;
[ use the linked list for something here |
| now get back the heap space used for the list |
release (| © ] ;
5.37 File types
Since many computer applications involve storage of large
volumes of data, which has to be retained from one program
execution to another, the dara has to be held on some secondary
storage device, such as a microdrive.
Any stream of information which 13 held on some external
storage medium for input ta, or gutpnt by, a computer 15 called a
file, Character devices such as Keybnards and VDLU can also be
considered as files [or the input and output of tata, alrhoqh
there is no concept of the data being stored.
Pascal allows the user to structure Éiles according ta che typa
of data required,
Example
fl > File of integer;
EZ = File of char ;
13 = ELle nf person:
type
where person is à user defined record.
rm" "sam HAND MN
Y MPA AMM AAA
!
|= WWW LS Oe W U UV EN EJEA y
+”
*
There is a predeclared type in Computer One Pascal called text,
which is a file of char and there are two standard Files, inpc-
and output, which are the default files for reading and writing.
The use of files in Pascal and Pascal [/0 in general ar.
described in detail in Section 5.7.
5.3.8 Type compatibility
Pascal 15 a strongly typed language. In some contexts tun types
may be required to be the same, but not 1n others. Even ıf tc
types are not the same, they may stili be compatible and ir
Certain contexts this may be sufficient, except in the case o:
assignments, where the types must be assignment compatible,
Two types must be the same only for variable parameters y:
procedures and functions ( see 5.9.1.1 +,
Two types are compatible if any of the following are tro
(1% They are the same type
(2) One is à subrange of the other
(1) Both are subranges of the same host type
(4) Both are set types and have the same base-type
(5) Both are string array types with the same numcar of
elements,
Type comiatibatity 13 required in the majority of cases where ta
Or more entities are used together, for axamplte 1n expressinnsg.
Example: Eype El = integer:
El = 1..109n.
ti ard t2 are compatible since r2 16 subrange of e]
5.38.2 Assignment Campatibiinty
The value of an expression expy Of type expe 13 assignamor:
compatible with a variable, a parameter er a funtion ders fr.
ab type wr df any of the following +5 true | Expressiona ar
descrita in section 5,4.1.} à = '
NM vr and expr are the same type and neither 15 a fi,u гу; --
and neither 15 a structured type with a file compo: ont,
"21 vt 1s of type real and expr 15 af type integer er |
subrange of type integer.
(3) vr and expt are compatible ordinal types and expy 16
within the range of possible values of vt,
- 40 =
Lome +.
Ty ——
14] wt and expt are compatible set types and all members of
expval are within the range of possible values of the
base-type,
(3) ve is of type array [E..n] of char and expt is a quoted
string constant containing exactly n characters,
54 STATEMENTS
The statement part of a program defines the actions to be
carried out as a sequence of statements. Statements in Pascal are
exgcuted one after another,
|
statement-part = "begin" statement statement} "end"
5.4.1 Assignment statement ant
The assignment statement is used to assign a particular value
to a variable, The value is specified by means of an expression,
assignment-statement =
( variable-access | func-ident } ":=" expressinn
5.4.1.1 Expréssions
An expression consists of constant or variable operands,
operators and function calls | functions are described in 5.6.2)
AN expression is a rule for calculating a value, where the rules
of operator precedence and left to right evaluation apply The
precedence of operarors |5 given below in decreas1ig order
Operators of equal precedence are on the same level,
hot, bnot
". 7, div, mod, and, band
+, 7, Or, bor, hxor
a, <x, €, >, E, >=, ın
The operators bnot, band, bor and bxor treat integer values 15 bir
parterns. They all take two integer operands, except bnot , which
takes a single operand. The table below uhnws the тес] mf
operations using these operators.
operator action
brot flip all rhe bits of the given integer
band ands the corresponding bits of the two integers.
Thus only those bits which are set in both numbers
Are also set in the result.
bor dors the corresponding bits of the two integers,
setting all the bits in the result which are sor
in either of the operands.
- 41 -
a Jeb TEN PETES Ee EE. Ee mmm НН
bxor "ors” the corresponding bits of the two integers,
serting only those bits in the result that are
set in either of the operands but not in both.
An expression in parentheses is evaluated independently of its
pteceding and succeeding operators.
Examples 2 " ÿ + 4 * (2 * 8] + {4 * 2) a Z4
not à and b = Inot at and b
4 * H / 2 = {4 * A) / 2 = 16
6 + A div A = 6 + |B div 4} = В
6 band i2 = 4
9 bor 5 = Е}
Y bxor 5 = |?
The user must make no assumption about the order of evaluation no!
aperands in boolean expressions.
An assignment can be made co variables of any type except
Files. However the type of the variable and of the evaluate:
expression must be assignment compatible | see 5.2.8.1 1,
Examples
Y
u
: + 4 * B ;
gs := { a... 2 | : s 18 of type set of char
ch := à ; 18 1liegai LE Ch is of type char
5.4 7 Compound statement
A compound statement 15 a sequence of scatements thas ar
axecutrd an the order aun which they are written, The sequence |.
suceoyndrd by the symbole begin and end. The starament-part
a program is a compound statement,
Example
begin
a = 3;
+ 5 3
c :=# a * b
end
Hate that no semi-colon is required after the statement before =o
“ni, singe the semi-colon 15 à Statement séparatar ado Aa GE
part of rhe statement,
5.4.3 Repetion statements
An important ciass of action in programs is the lLomp, tn «hich
+ 4tatoment or group of statements executes repeatedly, subjoct г:
some terminating condition.
5.4.3.1 While statement
while-statement = “while” expr "do" statement
The expression must be of type boolean, The expression 15
evaluated and if the result is true the statement is executed.
This is tepeated until the expression evaluates to false, in which
case the statement is not executed,
Examples
while x ¢ y do x := f{x} + 1 ;
while { a <> * + and { count <> 10 + do
Begin
read { a )
count := count + |
end y
Note that if the expression initially evaluates to false, the
statement i$ never executed.
5.4.3.2 Repeat statement
repeat statement = “repeat” statement [";" statement |
“until” expr
The repeat statment is similar in action to the while
gratement, but the statement part 15 executed before the
controlling expression 15 evaluated. Again the expression must be
of type boolean. The statements are repeatedly executed upral thé
expression evaluates to true. Since the statement part is execured
before the expression, it is always executed at least once.
examples
repeat a := flia) + l until a > bo
repeat count := count + 1: read lc) until c=
5.4.3.3 For Statement
for-stat = "for" variable ":=" init-expr ( to” | "downto” |
funal-expr "do” statement
The variable must be an ordinal type and the expressions must
be of “he same type as che variable. The variable must be derlarer
in the innermost block containing the lenp.
On entry ta the for {oop the control variable is assigned the
value of the initial expression. Each time round the loop the
value Af the control variable is incremented | decremented in the
case of downto | until it 18 greater than ( less than | che
value of the final expression, The initial and final expressions
are only evaluated once, on initial entry to rhe for loop,
я" пп то тот отт
rT
tf the final expression is less than the initial expression
¡greater than in the case of downto), the statement part is not
executed at all. On completion of the for loop the value of the
control variable is undefined and no assumptions should be made
about tts value,
More that Computer One Pascal does not check whether the
control varlable is assigned to within a for loop, although no
assignment should be made to the variable.
Examples
for i := 1 бо п do write { i*1 } :
for day := monday to friday do
begin
readln ( hourswoarked |
F
totaihes = toralhrs + hoursworked
and
{ assuming day 1s a user defined ordinal type |
for x := max downto min do readln [ ax] )
я
Ч
h 4 4 Conditional Statements
I. 13 often necessary to make the execution of & statement
dependent on some condition or value. Pascal! provides two
constracts for this purpose - the if-statement and the
rage-grarement.
Sd 41 If statement
This statement has two Forms
Pla al-statemenkt = "LÉ* expr "then" statement
(21 ıf-statement = “if” expr “then" statement "else” statement
The *xprraston 11 both cases must be of type boolean,
if the expression evaiyates to true, the statement following
the then 1s executed. [f 1t evaluates to false, then in caso 11)
PX continues at the statement following the if statement,
and un rase (ZI the statement following the else is execured.
Éxarmpies +
Lf a <b rhen a := b
1f x + y =" 2 then
begin x a 0 : y 1» 0 end
else z = 0 ;
A nested if-starement of the form
if exprl then if expr? then stati else stat?
appears to be ambiguous. In Pascal this statement is defined to be
equivalent to
if expri then
begin if expr? then stat] else stat? end
t.e. The else 13 associated with the nearest if.
Note that there is never a semi-colon before the else and
that a semi-colon after a then would indicate an empty
statement,
5.4.4.2 Case statement
The case statement consists of an expression | the sejector )
and a list of statements, each labelled with a constant af the
game type as the the selector, which must be an ordinal.
Cäase-stat = “case” expr of”
lablist ":" statement
“end”
The statement selected for execurion Ls the ane whose label +5
equal to the current value of the selector, if none of the Tabla
is equal to the value of the selector an error OCCUrSv.
Examples
case 1 of
I: x сч 0;
] x rx i;
2 xXx TM "do;
Е x := 1 * i * 1
4 + Xx Y LL т À
end:
ase curcehar of
1E, er : neviine := true
a , Bb, " , d° : letter + rrupe
no, 1, 2, 5 : digit oa Tru
mado
Case labels are not ordinary labels and cannot be used in a gore
statement, Also the labels in à case statement must be unique, no
label appearing in more than one branch of the statement.
- 45 —
Am п от т т ттт
Mm Y MPA M
A
PM N MA N NM
JI
Ya,
cuud
y
“ur
virESS ay yyy:
a WU
— I Fa = EEE OT TY
5.4.5 The Goto Statement ¡+
goto-stat = "goto” label
The goto statement is used LO cause execution to Continue ar
"he statement prefixed with the given label. The scope of th
label 15 the entire block in which rt was declared, do Табе} nan
be used to prefix more than one statement,
Mote that the effect of jumping into a Structured statemer-
from outside the Statement is undefined. Further note rh.-
Lomputer One Pascal does not allow jumps from inside a proceed.
Lo a statement outside the procedure,
SOTO statements should be used with care and only im uncam-
gr "“nusual situations, for example when an error is detected,
Example
hequn
1E x <0 then begin error :a true ; goto | eri
| rend
546 The With statement
“nen processing record variables tt 15 quite usua! to refer
Seal fields af the record Within a small region of the Ppregrar
Fur convensence Pascal Provides the with Statement, within whi.
Cacord fied names may be referenced without the record variar
CNE, provides the record variable has been specified ar the -
Of the with statement,
«17h Stat = “рен” raecord-var | "," record-var | "de" SrAafemar:
JET EE
“ar person record
name : array [1..101 of ehar
age : 1..100 ;
sex : Imale, Female):
end
“ich person do
hed:n name := Paul tuas 1 AJE 17 24; чех := male Lh
BET the end of the statement references to fields of the Eso;
“rotary specified in with statement must be made in Full,
|
— =F RE E Оооо
5.5 PROCEDURES AND FUNCTIONS
Pascal, in common with most other Programming languages,
provides a facility for defining a group of actions in the form of
a procedure, to which a name, called the procedure identifier,
is given, The procedure is activated by a procedure statement,
which causes the execution of the group of actions defined in the
procedure,
The use of procedures allows us tn textually divide the program
into sub-unita corresponding to the sub-problems identified during
construction of the program, thus making the program easier ro
understand and hence maintain, It also allows us to define once,
a piece of code that is executed ал" different points in the
Program, thus saving memory space and “ping time,
In section 5.2 we said that a block consisted of a declaration
part and a statement part, and that within the declaration par”
was the Procedure-and-function-definition-part.
procedure-function-definition-parr =
| procedure-declaration | function-declaration |
Functions are dealt with in this section 5.5.72
5.5.1 Procedures
A procedure declaration 1s defined as follows
procedure-declaration = procedure-heading (o hloack | "farward"
The procedure heading congists of the word procedure, Ге 1 1 гум ен}
by a name for the procedure and an optional parameter | gb
Parameters are dealt with larer 18 this section. Fallowing the
heading can be the word “forward” Sr à block. The use of forward
declarations ís also deajt with later in this section. A block 15
the seme as the Program block described carlier and consists uf A
declaration part and a Statement part. Any variables dectared in
the procedure block are lacal ro the procedure and cannor be
accessed outside the procedure Note that since a declaration par-
can contain procedure declarations, proredures can be declared
inside procedures, the scope of procedure names being the same an
the scope of any other variables.
A procedure 19 actived by à procedure statement, which CONSISTE
of the procedure name and a list of parameters, 1f there are Any.
À
| ANANNANANARNANANANOANTARA
Ls
Example :
procedure readanderitename :
const namelen = 30 :
var i : integer":
begin
for 1+ += 1 to namelen do
begin
read (ch )
write | ch )
end
end :
To activate the procedure we would use the statement
readandwritename
5.9.1.1 Parameters
Often 1t 19 necessary to introduce new variables to represen"
procedure arguments and results. These variables are calles
parameters and are defined in the procedure header by specifying a
formal parameter list. The formal parameter list specifies the
name of each parameter, followed by its type. When a procedure
“lth parameters 1s called, the procedure statement must contain
Fhe procedure name and a list of actual paramters. The form of
sach actual parameter is determined by the class of the
vorrespoanding formal рагамтег. In Computer One Pascal there are
. - Ta
ho Value parameters can be considered as input parameters, since
PARDO aby role 16 to pass values into à procedure, The actual
parameter may be any expression which produces a vatue that 1
15919rnment compatible with the corresponding formal parameter.
“hen a procedure 13 called with a value parameter the formal
FALAMECAL 1% assigned the value and while the value of the formal
parameter may change during the axecution of the procedure, rhes
las no PÉfect on the actual рагатмегег. | es
т
Tariible formal parameters are used to denote actual paramerers
пиве values may change during the execution of the procedure.
ah Enrrospandiang actual parameter must therefore be a varitabl.
7° the game type as the formal parameter. A variable formal
HIFAMELPT 15 specified ın the procedure heading by preceding the
paramérec name by the symbal var. `
“hen Specifying the actual parameter liste ın 4 procedure rail
the foliowing rules must be nhserved
Er RE a . 1 TEIN | TTR Re.
(1) The number parameters in the two lists must be the same.
{2} Each actual parameter corresponds to the formal parameter
occupying the same position in the formal parameter list.
(3} Corresponding actual parameters must agree as described
above for value parameters and for variable parameters,
The examples below show a procedure with variable and formal
parameters and some calls to the procedure.
procedure max { var m : integer : «x, y integer ) :
begin
if x > y thenm := x
else m = y
end y
The following calls to the procedure max are legal
max [ size [a], B, 16 }:
max ( maxval, B*"3, 12-6 1;
max ( p”.height, a, b ! ; | a and b are integers |
The following calls to the procedure max are illegal
max ( 8, 16,20 1: { actual parameter for a variable
formal parameter must be a variable]
max 1 maxval, В, ‘Ум’ J: [ actual parameter type does not
correspond to format paramter type |
Hote that a procedure can call atself. ог cal! another
procedure which in turn calls the [first procedure. Such +
procedure is called a recursive procedure.
5.5.1.2 Forward declarations
If a procedure A calls a procedure B, which it turn ralls A
either directly or indirectly, this is called mutual recursicn
This presenta a slight problem in Pascal since the scope rules de
not allow a name to be used before it is declared, and with
mutually recursive procedures one of the procedures must make a
call to procedure «which has not yet been declared, To get round
this problem Pascal allows a procedure to be declared forward,
1.2, the procedure header, followed by the symbol forward can br
placed before the actual procedure declaration itself, In the
forward declaration, the formal parameter list, if there is one,
must he specified and the formal parameter list must nat he
specified for the actual procedure declaration. Hote that Fro
every forward déclaration thers must be a corresponding actu]
declaration of the procedure,
-— —— "E ЧН ий |
mm
i
-
70. IM ANA MA MAN + æ A
E MD =
a
Er EP EN E, a оо
example : procedure a ( var X,y : integer | ; Ebruard :
procedure by
bagin
at 3,5) : ! call to forward declared proc !
end :
procedure a ; (NOTE parameter list must not be repeat.
begin
pw : | call procedure by
end 3
5.5.2 Functions
A funcrion is a special form of procedure which descrioes |
computation and produces a single value as a result. The type 1
rhe result must be a scalar or pointer type. However, whereis »
procedure 15 activated by a procedure statement, a fÉfunctinn >
artivated by a function designator from within an expression. °°
result nf the function contributing to the final value APO ta
XpressloOn,
A function dactaration 15 simitar to à procedure declarara
hub following the ferral parameter i1st the type of the res..."
specif Led.
Example
Eunction max lo Xp у LaTeger | упоецес
Me funcrran identifier 15 used J1thin the fun-tion body 72 1-7 '
the resyit of the computation, within the be dy oF the fF
there must he at feast one assignment of a value of the ro 7
type to the function identif.rsr. Tf during execuabp N
assignment 15 MOT execured the result af the Bunt
une net,
Example
Function max | x, Y integer | integetr ;
begin
IE x > y then max 2 x else max :5 y
ena:
The function body, as with the procedure body, 13 à block at <>.
therefore contain declarations nf variables, procedures, finca
etc. Parameter passing ts Che same for functions as procedures | |
the rules stated for procedures also apply to functions, |
dote that although the function identifier 1s assigned to, 1E
cannot be treated a5 an ordinary variable and any use of th»
function identifier in an expression will result 1n a recursivo
call to the function.
tf a function alters the value of a variable which ia known
outside the function, this is called a side-effect of the
function. Care should be taken with side-effects, 3ince if the
altered value appears in the same expression as the function
designator, the resultant value of the expression will depend on
the order of evaluation of the operands. For example if the
variable a, which is in scope outside a funtion f, ts altered
inside the function f then
E Lu) + a may not give the same value as a + F (tx)
side-effects should he
For this reason Functions «ith
avoided wherever possible.
6 INPUT AND QUTPUT
Every computer program manipulates data and there must be
some means of supplying the program with dara and rece1ving
results from the program. Data can be input from devices such as
microdrive cartridges and keyboards and can be output to devices
such as microdrive cartridges and VDUs.
Pascal uses an input stream and an output stream to obtain and
deliver information and, to a large extent, the type of device on
which the information is held, is immaterial. Any stream af
information held on an external device, for input to, or output
from a Pascal program, 193 a file. Nore that à keyboard can be
considered as a file since 1E can supply a program wIth 8 stream
of information.
5.8.1 Input
A Pascal read statement takes the form
read | file, variable-list )
For the moment we shall only consider the file input which as
predeciared in pascal and is the default inpot file. In Computer
One Pascal the input fila is From the QL keyboard. For the
standard input file a read statement has the farm
read | input, variable-list } or
read | varianle-list |
"лот
LA AS A em Tene TEE HEM
Since the input file is thé default file it can be omitted from
the read statement. The variable list is defined as
variable-list = variable { “,” variable |
The variables must be of type integer, real, char or a subrange of
type 1nteger or char, and are written as sequences of ASCII
characters which conform to the numbers and string constants
described in section 5.1.
“he affect of the read statement is to assign to each of the
variables in the list, values from the input stream. [fa variable
v 18 of type integer or real, à sequence of characters
representing an integer or real number is read, leading blanks
and end of line characters being skipped. All numbers read must be
sepatated by blanks or end of lines, If у is of type char, the
next character in the input stream 19 assigned to wv, If the next
character 13 the end of line marker, the standard function
egin | input |
hocomes true. However the character line-Eeed | che (19) # 45
still assigned to v Г СЁ. standard Pascal which assigns a blank ro
v J. The function eoln will only teturn true LÉ the character
anctountered $ the end of line marker. Note that the values
earauntered in the input stream must be assignment compatible with
"ne variables in the variable list, otherwise an error will occur.
A special form of the read statement 18 provided Lo skip over
rhe remainder of a Line. The sratement 138
readin
eadin can also rake a list of variables,
read + vi, v2, УВ; 15 equivalent to
rex 4 vl } ; read [ v2 ! : read Г УЗ;
Ach
read do xi, vv, YI 1 ¡ readin ; LS equivalent по
ге п 1 vil, +2, Mb Eos
Example : The statement
read | integeri, integer?, charl, char?2, ceatl, stringl |
with the follawing input
6 28XY 1,67 abr
LS équivalent to
integeci :7 16 ; integer? :e 28 ; char] : X ; Char? := Y
reall := 1,67 ; stringl += ‘ abe ; | stringt of length 4 |
tetas le dde le SP — 11
The statement will also read the following input correctly.
16
tBXY
1.6 abc45
The 45 will not be discarded and will be used next time a read
statement is executed. However, if the statement had been a
readln and not a read, the 45 would automatically have been
skipped over after the other values had been read.
5.8.2 Output
A Pascal write statement takes the form
write [ file, output-list |}
For the moment we will only consider the predeclared [ile
output, which like the input file, is the default and need not
be specified in the write statment.
The statement
writaln
may be used to output a new line character and has the more
general form
writeln | nutput-list !
which causes Che new line to be output after the output-list The
output-list 1s a list nf output-values, separated by commas. The
output-values, which are expressions, must be of type real,
integer, string-array, boolean or char.
Examples : write { For=zy = , 8*5 )
will output Forry = 40
writein € AM 1: write | 621"721; write | жут E
will output ABC
truexy:z
The exart number of characters output for each value ja determined
by the way the value 15 expressed,
output-value = expr | *:" Freti-width 1 *:" Eraction-part | |
Field with and Éracrion part must he expressions of type integer.
The fieid-width specifies the number of characters spaces Sed to
write cut the value, When an output value 1s written with mn
Field-width a defautt field-width 18 used.
„ 53- a
п зто то ттт т я + т
u
+
i:
TT TW Wow WW ОК © yv a ud Le
For Computer One Pascal the following default widths are used
type default width
integer 10
reai 16
char 1
string The length of the string array
boolean 4 or 5 [ for ‘true’ or false |
[E the actual value to be Output requires fewer characters char
the field-width an appropriate number of blanks is output befor.
the value, If the specified field-width is too small for integu:
or real values the field width is increased to the minimy-
required, For a string or boolean the right-most characters ar
truncated LÉ the fieid-width is too small,
The fraction-part of the output-value may only be used whe
outputting real numbers and specifies the number of character,
Ifter the decimal point. If no fraction-part is specified toh
value 15 output LN floating point form. Thus if no fraction-pas-
ts specified rhe output would be of the form
У. 45АЕ +0}
If the fracrion-part was ? the value would be cutput as
145.60
Remember that there are a number of special characters which
help to format output (see 5.1.3),
50 far we have only looked at the standard input and My Dat
Files, We shall look more qenéralty at Pascal files.
56.3 Files
As arnted in section 5.1.7 a Pascal file can be declared to hn
Af any component type € | except a file iself or a srr cture wire
Aa file Fieid 1.
Type © = Êile of t :
The declaratinn sf a Cite E automatically introduces -a buffer
"Migable E. É can be considered аз a window throvgh whicr
“xLsting components of type t can be read, or new components oa
буре E van be written, The buffer variable Component LS the ant,
\runadrately accessible component of the file E,
Pascai files are sequential fileg, т.е. the fail.
components are either read or written in Strict sequential order,
and reading and writing to a file cannot be interspersed.
when the window {° has moved beyond the end of a file the standard
end-of-file function
eof 1 ff)
15 true, otherwise it 15 false,
The following standard procedures exist for file handling
attach { f, fname ) « Computer One Pascal uses this procedure to
associate a file with a filename. Fname 15
a string-array of any length up to
forty-one characters which qives the
name of the file. The file can be a
microdrive file, a console, a screen or
any other named device, for example the
serial port. Consoles, screens and other
Character devices should be declared as
textfiles (see 5.6.3.1).
atcach ( £, 'MDV2 myfile dat )
ettach ( É, SCA 512x7256a0x0” |
Example
reset ( f | - This sets the buffer variable to the start of the
file and, except for console fites, assigns the
first component to the buffer variable Е”. If the
file ts not empty еоЁ (ft becnmes False,
otherwise it becomes true and E” 15 undefined
Atrach must have been used to associate this
Eile variable with an existing file.
rewrite ( É |) -This procedure is used before first wrıtıng го à
file, The current value of (ag replaced by the
empty file. i.e, the contents of the file are
erased. Eof {€F) he-nmes trie and Fr ES
undefined. Attach must have been used tn
assoclate the file variable with a nen-exisrenft
File.
get ( E ) - This procedure advances the window to the next
component af the file. If no next Component
EXLSTS eOf [f] becomes true and É” is undefined.
put ( É 1 - This procedure appends to f the value of €”, after
which eof (Et remains true and f” is undefined,
close [ E ) - This procedures closes the file, after which the
attach must he used to associate the file with a
hame before it 15 used again,
delete | fname ) - This procedure deletes the named file.
IANA MNN ARAN AR NAL NAAN NARA DN
|
ay
uw “€
a
E EE E
Example + Suppose we have a file of records, the declaration of
the record being
type person = record
name : array [1,,8)] of char:
sex : [ male, female ) ;
age : 1..100
end :
and that someone whose name 15 K.Jones has been married and we
wish to change the name in the record to K.Smith., Since Pascal
does not allow reading and writing to the same file, we have tr
read the records from one fila, change the name of the TeQqui red
record and write the records ro a new file,
program changeñname y
type person * record
name - array [1..8] of char:
Sex : ! male, female | ;
age : 1..100 ı
end ;
var pfılel, pfıle2 file o£ person:
ger : person:
bein
arrach | afilel, mdv2 persons” |) +
reset | ptilet | | prepare the file For reading |
ırrach 7 píitie2, mdv? persons?” | ;
rewrite | pfıle? 1 | prepare the file [or writing |
while nov eof + pfilel + dea
egin
per 1: p£ilel”
Jer L pfilel 1 ; .
with per de
vf (name # EK Janes | ага (sex * Female] chen
name 1" К. бт
NETISI m per
pur © pfılel |
ed
sirse 1 pfriel Y ; closs | pfile? } :
and
5. 6.3. 1 Text files
A text File is a File whose components ‘are characters. tn
Pascal there 13 a predeclared "ype defined as
type text = file of har
text files are usually divided anto lines separated by control
characters, In Computer ne Pascal the line separator character 1s
the ASCIT control code 10 line feed $. The standard input and
Output‘ Files described earlier are predeclared textfile
(dentifiers,
Le) TT ie PEE TE TR
Like other tiles, textfiles must be prepared for writing using
the standard procedures ‘attach and reset Or rewrite’. Note
that reset and ‘rewrite must not be used for the standard
input and ‘output files.
The standard procedures ‘eof’, ‘get’, “put” and “close may also
be applied to textfiles. Likewise a textfile E has an associated
buffer variable E”, Note however that when using
reset from a character device E, such as the keyboard, f° is not
assigned the first component of fF, since the buffer variable
cannot have the next input component until it has been entered at
the keyboard.
For a character device, such ag a keyboard, eof (f) is always
false,
The function ecin (Ff! returns true when the current character
available is the end of line control character, In this case rhe
character line-feed | = chr 41011 13 assigned to the variable of
the read statement.
The standard procedures read’, write‘, ‘readiln‘ and
‘writein’ can oniy be used for textfiles, As with the standard
textfiles, ‘input and ‘output’, ‘read and ‘readin’ can only be
used to read variables of type integer, real or char and the
output procedures ‘write and writeln can only be used to write
variables of type integer, char, boolean, String and real. There
is a standard procedure page which outputs a new page chararter
{ ehr (12) } to a textfile. This procedure is useful when the file
is a print file,
functions which allow yeu to make full use of the windowing and
Other 1/0 facilities en the DE. Thrse procedures and
functions are described in chapter 6,
Computer One has a number of predeclared procedures and
5.6.4 1/0 Errors
Computer Qne Pascal detects errors which occur in [Lon
Operations. However, it 1s the users responsibility to check fry
this. There is a predeclared integer, toresult”, which rontains
the error code after an input or output operation has heen
performed. ‘Toresualt can be inspected by the user program. A
value of 0 indicates that the operation completed successfully,
otherwise the error code indicates what the error was. A lisr af
the errors and their causes 18 given in Appendix D. Note that wher
Checking far an error condition the following must not be used
if ioresult <> Y then write | ISEESULE = 7, ioresublt |
since the operation to write the error code will corrupt the
value. Instead, loresult should be assigned to another variable
and that variable should be used in the write statement.
- 53 -
MAMA MAAAANATAAAANAMMMM |
1€
"
Ч
e:
FE
A EL
9%
E € E E We E
ко м Фо © © соб VW I UNE
mn!
|
/
STANDARD PROCEDURES FOR THE QL
| CHAPTER SIX
This chapter contains a descri
| ption of the redeclare:
procedures and functions which have been added со Computer ons
Pascal to enabi
Pascal. £ you to make full use of the power af the QL frer
The following typas have been predeclared and are used as
parameter types for some of the oroc :
described procedures and functions to be
type address = 0, 1048575 ; { = 2°20 - ||
colour = { black, blue, red, magenta, green
yellow, white } ;
dreg = array (0..7| of integer ;
arég = array [0,.5] of integer
cyan.
2.1 QL 1/0 AND GRAPHICS PROCEDURES ANO FUNCTIONS
The foliowing procedures correspond to the procedures availabia=
LA SuperRasic, Note, however, that all the parameters nf che
functinns must be specified. Most of the procedures take a File of
“har which has been opened as a console or a screen Fact he
Lnfcimation on these procedures can be found by tack in u th
jiocedure name ¿n the KEYWORDS sectian of the Qu user-mansai, ALI
af the procedures which take a fi
MT Е E à € lle parameter set the a :
toresult variable described in 3.6.4, pratestores
For any procedure which takes a file name parameter, a s®rim;
array Y LengtA Up to 41 characters may be used Characters ue
3 1e 1r$t balnk in the string are used, L{ the procedure
Iperates on a window the ope i
: eration takes ace r dr
arrachedd tn the specified file. place wn the vando-
Th the following three procedures the value of stipple 1s
the range D..1, For values outside the |
bits of the given integer are used,
Ln
range only the bottam tr
procedure paper | var À file : maincol, contrastcel : colour;
stipple : integer |:
Sets a new paper and strip colour for the given file. The paper
colour is used by the cly procedure and will remain 15 effect
until rhe next use of paper with this file.
procedure ink [ var Ë : file : maincol, contrastcol : colour:
stipple : integer ) ;
Sets a new ink colour for the given file. This is the colour
in which any text output to the window will appear.
procedure strip [ var É : file: maincol, contrastcol : colour;
stippie : integer } :
Sets a new strip colour for the given Eile. This is the
background colour for any text written to the window . It 15
rather like highlighting the text.
procedure window ( var f file : width,depth,x,y : integer ) :
Allows the user to change the size ar position of the window. The
four coordinates are specified 1n 'i1xels and the position 15
relative to the screen origin.
procedure border ( var £ : file; width : integer
maincol, contrastcol : colour ; stipple : inter
Adds a border, in the given colour, to the window. For subsequent
operations on the window, except another border operation, thé
window size is reduced to allow space for the border,
erocedure cls [ var É : File; part : integer |
Clears the specified part of the window, The part cleared will De
get to the colour set with last call to paper for this window.
where if part = 0 the whole window 15 cleared,
if part = | the part above the cursor tine 15 cleared,
if part = 2 the part below the cursor line :5 cleared,
ntherwise the whole window 19 cleared,
procedure at | var f : file; Lineno, columno ; integer ) :
Sets the print position in the window. The next text written to
the window after the call will start at the specified position.
Position 0,9 is the top left corner of the window.
nnnnnnannnn
ттт тт
RNNANNN
|
|
"
4
E
ls VE VE TU
procedure scroll { var f:file; part: Integer; numpixeis: integer -:
This procedure scrolls the window up or down the specified number
of pixels,
«here 1É part » 0 the whole window is scrolled,
LÉ part = | the part above the cursor line is scrolled,
LE part = 2 the part below the cursor line is scrolied,
otherwise the whole window is scrolled
procedure pan {var [:file; part: integer; numpixels integer |:
Pans the window the specified number of pixels,
where 1f part = 0 the whole screen is panned,
¡E part = 1 the whole cursor line is panned,
1f part = 4 the right end of the cursor,
cursor position i5 panned,
otherwise the whole screen is panned,
including “he
procedure under | var f : file; on boolean | ;
Turns underlining on in the window, 1f the on parameter 15 trje.
[f the on parameter 1s false underlining is switched off,
procedure over ( var É +: file; switch : integer ) -
Selects the type of printing
until over is next called,
required and cemains in + ec:
where 1É Switch = 0 characters are printed with the strap --' 3,»
as background,
Lf switch = | characters are printed with rhe paper 79 pur
as background,
TÉ switch = -1 characters are printed cover the pra; ms
contenta of the window,
SOfherewilse switch is assumed to be zero,
procedure flash | var € + file: on boolean |
Tirns rharacter flashing on in the window, if the an DALAM ae à;
true. If the on parameter 15 false flashing is switched €:
Flash isa anty effective in tow resolution mode.
procedure casiza var f£ file; width, height Integer |
sers the new character size for the window.
width param width in pixels height param height ın tral,
3 6 0 10
1 В | 20
2 12
1 16
- 60 -
_——.
procedure recol ( var €: file: el,c2,ed,cd,e5,¢c6,c7,¢8: colour à:
4
Recolours all the pixels in the window,
where €! 15 the new colour for al! blue pixels
Cd is the new colour for all red pixels
ci is Che new colour for atl magenta pixels
c4 is the new colour for all green pixels
c> is the new colour for all cyan pixels
c6 is the new colour for all yellow pixels
cf is the new colour Éor all vhite pixels
cB is the new colaur for all black pixels.
The following nine procedures are graphics procedures. The
graphics origin of a window is (9,8) and is the bottom left corner
Of the window. The origin can be altered using the ‘scale’
procedure, All positions are relative to the graphics origin and
Not tae the current graphics plot position.
procedure arc [ var f : file SM, 5Y, fx, fy, angle : real |;
Draws the arc of a circle in the window from the start point
19X,Ssy! to the finish point (fx, fy). The angle” parameter is the
angle subtended by rhe arc.
procedure block | var f + fije
mátn, conrrast
wIdER, height, x, y
colour ; sErpple
Integer
integer |
Fills a block of the specified width and height at the specified
(Xy) position in the window
+
procedure gcursor | var fF : file ; X, Yı XCel, yrel : real )
Positions the screen cursor at the position (xrel, yrei)
relative to the graphics position [x, y). Note that xrel and Y CP]
are specified im the pixel coordinate System and x and y in the
graphics coordinate syaetem.
procedure cursar [маг € : file : x, y : real |;
Positions the screen cursor at the specified (x,y! position, x and
Y being specified in the pixel coordinate system,
Тя
R NM
AAMT ANT AM
R
сосков уе Зее уф
© $
e
© QW & © &
и
\'
procedure ellipse ( var f: file; x, y, radius, eccentricity,
angle : real )
Draws an ellipse at the specified (Xy! position ın ene
window. If the eccentricity parameter is | a circle is drawn,
( See under keyword ‘Circle’ in the OL User Manual y,
procedure graËiil ( var £ : file; £ill : boolean |) y
Switches the graphics fill” on or off, If the value 18 Er...
shapes are filled when drawn, | See under keyword Fill ami
User Manual |). 5
procedure line ( var £ : File ; sx, sy, Ex, Ey : real |:
Draws a lina Ё сот the specified start point (аи, зу! to the Finis
point (fx,fy) 1n the window,
procedure point { var £ : file ; x, y : real } ;
Draws a point at the specified position f(x,y) in the window.
procedure scale ( var f : file ; scalev, x, y : real 1
Alters the scale factor of the window, The default scale Lo
190. i1.e. the window is divided verticaliy into 190 units. Tn
position (x,yt specilies the graphics origin.
pronrocduce mode € resolution : integer | :
Gers tha resolution of the screen and the number of colours "hoy
ran be displayed,
“hete LÉ resolution = 8 or 256 resolution is low,
LÉ resolution = 4 or 512 resolatien 18 high,
H'her#1ise resolution 18 low
prorelire baud | rate : ıntener |
тега the Baud rate for communication via the two aerial channel;
rth channels are set to the same baud rate, Allowable vales fur
the Hand care are
18, HN, 600, 1200, 2400, 4800, 3600
The haud rate 19200 can be used for transmitring only. The effsr»
vs undefined for other values,
——r
. function inkey ( var Ё : file; duration : integer } : char ;
Waits for the given duration for a character from the given file
f. The character, if input from the keyboard, will not be echoed
on the screen. The duration ia specified in fiftieths of a second.
6.2 MEMORY ACCESS PROCEDURES AND FUNCTIONS
The following procedures allow access to memory, with the
exception of the function byte, and should be used with extreme
caution, since ANY area of memory can be accessed.
function byte [ whichbyte: integer; from : integer) : integer
Takes a values in the range 0..) and selects that byte value from
the given integer, Byte 0 is the most significant byte of the
given integer,
procedure call { add : address; datareq : dreg ; addrreg : areg |:
Calls a machine code subroutine, whose start address 15 the
specified address. The ‘datareg and ‘addrreg arrays contain the
values which will be loaded into th 7istera d0-d7 and at-a5
The types 'dreg” and areg are prede. ¡dred array rypes. Calling
this procedure causes the registers to be inaded from the arrays
and a JSR instruction to be executed. The machine code routine
should return using sn RTS instruction. The stack pointer value
(at) immediazely before the ETS must be rhe same value as on
entry. The stack beneath this must NOT be changed in any way. Un
return, the arrays datareq and ‘addireg contain the values
“hich were an d0-d? and ad-añ when the machine code subroutine
finished.
procedure Fill o coant : integer; from : address; ch: char |
Fills count bytes of memory with the character ch starting at
the specified address,
procedure move | count © oanteger ; from, tto - address ) y
Moves count bytes from rhe address from to the address tro
попала тата
‚р
gL
function peek ( add : address ) : integer
function peekw { add : address ) : integer
function peekl f add : address ) : integer
The three functions return the byte, the word apd longword at the
specified address, Addresses are rounded down to an even boundary
For peekw and peekl,
procedure poke { add : address ; val : integer )
procedure pokew ( add : address ; val : integer )
procedure pokel ( add : address ; val : integer )
The three procedures poke the given value, a byte, word or long
word into memory at the given address, Addresses are rounded down
кз an even boundary for pokew and pokel. For pokew and pokeb the
teist significant vord and byte of the given value are poked 1nto
Memory.
Function lar | vartable- name | : addreas y
Aerurns the address of the given variable. The variable may be of
any type.
procedure gethytes | var E: Erie; count: integer; addr: address J:
ers the specified number of bytes from the given file and pues LE
Li memory starting at the given address. This procedure sers the
1resull Variabie.
procedure putbytes { var É: fale; count: integer: addr: address |;
feapres "a the given file, the specified number af byres, SEartind
at Ehe quen Address,
proscmbire shyres Lo opame : filename; start +: address;
length : integer |
Saves fo the given file the number of bytes specified by length
ami starfing at the given address. If the file already exists 1t
will Le NYecH»Itten. -
procedure ihbytes [o name : Erlename ; start address ) y
Loads the specified fıle into memory at the given address,
“3 OTHER OL PROCEDURES AND FUNCTIONS
procedure beep [ pitch, pitch2, interval, duration, step, wrap.
rand, Fuzzy : integer ) :
Activates the QL sound functions, The best way to to use this
procedure is to experiment with different parameter values. The
range of values for each of the parameters 1% as follows :
duration : -<32769,,12767
pitchl : 9..255
pitch? : 0,.7255
wrap : 0..15
interval : 0,,15
step +1 ~8..7
Fuzzy : 0..15
rand : -32768..37767
procedure bell ;
Causes the QL to emit a short beep,
function isTY : boolean ;
Returns true if the TV option was chosen vhen the QL vas reset.
function islowres : boolean ;
Returns true LÉ the TV or monitor being used is currently un | сл
resolution mode.
function digit { ch : char ] : boolean
Aeturns true if the givers char is a digit, 1.8. 1É rhe char Le an
the range 'L'., 9 . Ir returns false otherwise.
function letter ( ch + char } : boolean
Returns true if the given char is a letret, lower or upper caso,
false otherwise.
function tower | ch : char Y : char :
Returns the given character in lower case. If the character 1% not
a letter the function returns the given character,
iaNnNaahanannmananTmtamamTheuurmnmnmia
¥
$
E
т
YS Ww WwW J
E.
function upper { ch : char | : char
Returns the given character in Upper case. IF the character 18 nor
a letter the function returns the given character,
procedure randomise { seed integer |;
"rovides n seed for the random number generator,
functron nd tr integer | integer
Returns a random number
between 0 and r-1.
Function rad ( degrees : real } : real
Converts the given angie añ degrees ton radians,
function leg radians : real to real
Converrs the given angle ın radians to degrees,
procedures halr
ALES exocutian of the brogram,
GALE rho ak rey the qrvan nurher af seconds
proceda aid justclnek | sers inmtager |
AdlS tha given number al seconds ro the clock.
Fant poe per abi Je AFA
Per arts the co] vk ,
Вр ESS OM
—— |
CHAPTER SEVEN
STANDARD PASCAL PROCEDURES AND FUNCTIONS
This chapter contains
procedures and functions
implementations,
7.1 FUNCTIONS
Fn name Argument
type
abs Integer or
reat
arctar Integer ar
real
che integer
cos Integer or
real
eof file
exp Integer or
reat
In integer or
real
odd integer
ard ordinal type
pred ordinal type
round real
a description nf the standard Pascal
to be Found
Action
Abso + value of
arg,
Arctangent of
arg.
character whose agil
code is the arg.
Cosine of arg,
true 1f end of file
reached
e бо power arm.
natural log af Arg,
true if arg. 15 odd
ordinal value of arg.
aredecessor of ar.
round to nearest
integer
- 67 =
ınthis and most Pascal
type of result
Integer mr
real
real
har
real
boolean
real
real
boolean
intager
sama ordinal
type
integer
E к о д AA
n Action type of real
| Ёп name Tae t YP Proc name Argument Action
-D type(s)
7 san integer or sine of arg. real . Co € ; start of file.
Co real reset file positions file huffer to
-*5 ; ile, and prepares 1t to
: rewrite file creates the file,
о Sur integer or square of arg. integer or accept output.
= real real
= , x Ï | в.
sqrt integer or square root of arg, real write textfile and writes data from the list to the fii
=D real value list
) ; he list to the file
in: writeln textfile and writes data trom Er
— sues ordinal type Successor of ary. type ordina. value list and terminates it with an end of line.
teunc real truncated value of integer | )
y arg.
1.2 PROCEDURES
Proc name Argument Action
= typeis)
J get File assigns the next component of the fi
3 to the buffer variable.
mark pointer marks the position of the pointer
E the heap for use ny rhe ге | оз
procedure.
Er new po:nterand Allocates storage on the heap "oa
nprimnal Tags dynamic variable of the type prints:
в by the pointer.
: paqe textfile Writes a new pare character dent
e to the given file.
put file Appends the contents af the sai:
wih. buffer of the fil» tn rhe file
ad read texcfile and Heads data Ltems from the falle ive
- variable List variables in che lise.
# readin rextfile and Similar to read, bur moves to noxt
5 variable list of line indicator.
a release pointer releases all space on the heap from xt.
- current top of rhe heap down to th
porntec which was used on the mar.
Y cal \ -
> Ad
- 69 -
пупа
An
"a
ПН,
PANTAT
ha la
|
‘чи
-
ue
Saar’
F
че Фес
и
{
BIBLIOGRAPHY
Pascal from BASIC
Introduction to Pascal
Pascal User Manual and
Report
Programming in Pascal
SrÉtware Tools in
Pascal
Specification for the
Computer programming
Language Pascal
APPENDIX A
P.J Brown ( Addison-Wesley |
Welsh & Elder [| Prentice-Hall |]
Jensen 5 Wirth | Springer-Verlag |! COMPILER ERROR MESSAGES
P.Grogono ( Addison-Wesley |
Kernigan ¢ Plauger ( Addison-Wesley | —
British Standards Institucion
BS 6192:1997
This appendix lists all the compiler error numbers and the
corresponding messages.
I: error in simple type
7: identifier expected
3: ‘program’ expected
4: 1 expected
5: + expected
6 illegal symbol
7 error in parameter list
8 ‘of’ expected
7 {7 expected
10: error in type
tt: | expected
12: "| expected
13: end” expected
Г
r
F
a
=
я
+
т
=
14: ; expected
15: integer expected
16: = expected
17: ‘begin expected
18: error in declaration part
19: error in Field list
20: . expected
21: * expected
50: error is constant
Hi: := expected
572: ‘then expected
УВЕ until expected
54: do expected
55: ro / downto expected
SA: error in factor
59; error in variable
191: identifier declared twice
102: low bound exceeds high bound
101: identifier not of appropriate class
104: identifier not declared
105: sign not allowed
A 106: number expected
— чан. wm | йе
anna A MMA TATNANAMANNAnNANAN
E
107:
108:
199:
E10:
itl:
Lh3:
Lid:
115:
116:
tit:
119:
120:
| 21:
ia:
121:
124:
125:
Ar
| 2%
| 30:
Ка:
ЕЁ:
11:
| 34e
LAS:
вЫ:
Li:
| LA:
LU +
ГАО:
EE
e
141
| 44 -
[45%
im:
EAT:
Li IM!
incompatible subrange types
file not allowed here
type must not be real
tagfield type must be scalar or subrange
incompatible with tagfield type
index type must be scalar or subrange
base type must not be real
base type must be scalar or subrange
error in type of standard procedure parameter
unsatisfied forward reference
forward declared: repetition dÉ parameter list not allowed
function result type must be scalar, subrange or pointer
file value parameter not allowed
forward declared function; repetition of result type not
allowed
missing result type ın function declaration
f-Enrmat for real only
error in type of standard function parameter
number of parameters does not agree with declaration
type conflict of operands
expression is not of ser type
taata on equality allowed only
strict inclusion not allowed
file comparison not allowed
Lilegat type cf operandis)
type of operand must be Boolean
set lement type must be scalar ór subrange
set element types not compatible
rye af variable is not array
ındex Куре is not compatible with declaration
type of variable is not record
Куре of variable must be file or pointer
illegal parareter substitution
Ellegal type of Loop control variable
Lilegal type of expression
type conflict
assyynment of files not allowed
label type 1nzompatible with selecting expression
subrange bourds must he scalar
poste x type must not be integer
assypgnment ro standard function is not allowed
rr such freld in Enis record
t pa ertor im read
ALGTUAL parameter must be variable
Conkral variable must not be declared on intermediate lave]
multicdefined case label
bno many cases in Case statement
missing corresponding variant declaration
teal or string tagfields not altowed
pravions declaration was not forward
again forward declared
parameter size must be Constant
multidefined label
multideclared label
undeclared label
169:
169:
171:
177:
178:
180:
201:
202:
203:
205:
296:
207:
250:
251:
25%:
261:
262:
104:
198:
395:
undefined label
error in base set
standard file was redeclared
assignment to function identifier not allowed here
multidefined record variant
control variable must not be farmal
error in real constant: digit expected
string constant must not exceed source line
integer constant exceeds range
empty string not allowed
integer part of real constant exceeds range
label too long
too many nested scopes of identifiers
too many nested procedures and/or functions
teo many errors on this source jine
further errors surpressed
too many subranges
alement expression out of range
implémentation restriction
not implemented
эпопеи помпа ттт НН
EE 0
¥
Erre
YE
и
À J a
Œ
y e Eee
ee
x : oe
—
——
s JUE à
ды
: . >
| APPENDIX B
RUN-TIME ERRORS
Thi4 appendix gives all the run-time error messages and cher
possible causes.
I. Nut of Store - this error Le Sutout when their is no space left
for dynamic variables on the heap or there are
too many nested procedure calls, causing the
stack to run out of space,
Instruction -
4. Unknown An unimplemented standard procedure or
function has been used.
1. Aritttimerirs Mverflo» - An ınteger expression has a value greater
than maxint or less "бам -maxint
or A real expression has a vatue outside rte
range cf reals,
1. Пума by лего - An attempt has Been by to divide by zero.
+ Mitte expected - A read statement, expecting an integer or
a real value received an invalid value,
Poramp 8 [7 x 19 an integer the statement
toad [ow]
will cause this error ¿FP the input 15 xy?
ho Vale бб range - AR attempt has been made ro index an
ATray with 3 value nutside th array
bounds
or an attempt has been made to à assign
which 15
altowed
a value to a variable
outside the range of values
for that variable.
or the value of the selector expression
gf a case statement was not equal to
any of the case statement labels.
==. — ао
array [1..10] of integer :
x : 1..20 ;
Example :
5 1 12 outside index range 1..10 |
a [2*6) := x
- 12 ; 1 0 outside range 1..20 }
x ı= 17
An attempt has been made to access a dynamic
7. Nil pointer -
variable using a pointer with a value nil.
Example : type person = record
sex ( male, Female } ;
age : 1,.100 :
end :
var p = "person
p:= nil ;
Pp .age := 20 ; { this causes the error since p is nil ]
The standard procedure new should be used to allocate space Гог
the dynamic variable and to point p to the variable.
В. End of file - An attempt has been made to read from a File when
eof [1 É ) was already truc. 1.8. an attempt En
read past the end of the file.
DD» NN nn mx nn Mm MT MM MM ch Th TN 3 (т. M mn T T N T T Mn Ut |
AERA
CTT evr FTO RC CR YEE YY EW
“APPENDIX C
COMPUTER ONE PASCAL SYNTAX DIAGRAMS
Syntax diagrams provi
syntax of a Programming
drajram ra very simple -
fallowing the Arrows af a
13 syntactically correct.
language, The
LÉ you can mak
Syntax diagram
tn the diagrams names
that are in rectangular boxes refer >
ather svyatax diagrams : symbols or words in Circles or ovals ar.
the basic symbols of the language. The Name on Left hand side
mois defining.
the diagram Says what syntactic Entity the diagra
—Cm) O
Example
Frrim this diagram
reserved word
tidentifrers,
En rad hy a
Pound the
LE can be seen that
2 program consists of -.
Program”, followed o
Ptionaily hy a lise ro
Separated by commas and enclosed ¿a brackoen
SeML-cnlaon, a block and 3 périod The arras TO.
brackerad tdentifiar | 154 indicates "har rhe tiene Fy.
list mead nmr pe Specified. The part of rhe diagram describing re
venti fier | gr
INdicares that there Can
be any number of
"IA ME,
у Чел та бега separatng |,
Fire Full Syltax of Computer One Pascal ys Fiven on the followin
payes.
ETE
la bed
decias rios
y Md fri
Feria Le
и
ы = сы Вы баб га Чон
>
—— ubprogrem deflnidos 3
e
er Oe
_ ¡ET ee) Oo"
©
фонт К Пай fa)
CD vtt
et reer wr ea ce
посол
— DE um )—
Ea E me =
эпопеи помню
LULLUVYUULLELUVLGULPYLUUO]
a
aa
o
9
o
3, |
(
"= |
bjr
Prato
=
is
at
—— (RECORD) a Мам Est -— (©)
declara ia
wie PL ear
—.
=
| ¿
©
ey
eee ]
ac ЕЕ
directi
a 252 a BIAan las 222) а A
- 19 -
- 18 -
8 a À
E FE
Ne Y +
En
EN
so f=
——()—
_— — (oro yf ее) —— -
A NANMMMAMAMA TAN MA AN A À NM‘
ir gr
oo -
oreo
—
—
+ 83 -
+ LEC - - E À
“ut EL
eT —]]]—
SYSTEM ERRORS
-APPENDIX D
This appendix Jives the QDOS в
umber given for each message
predeclared variable ‘loresutt
an 1/0 operation.
Number Error Message
- | act complete
<= Invalid job
w our of memnry
"à QUE OÉ range
- buffer nverflou
"A Channel] not Span
— mt found
° 8 Already exists
-4 LM use
- |0 dal af fıle
- 11 drive full
-12 har] dew) re
| YIANRRMLSS 1 0n er roy
14 Lormat failed
in ai parameter
ystem error messages. The error
| 13 the value to which the
LS SEC when an error OCTIUES durimo,
Possible Cause
An 1/0 operation did
ADE =
before it timed Out, pme lets
pe QL has no memory available
Ardmeters for creati |
* LG a wind
invalid values, 7 e
The 1mput 15 ton
er
but fant q than the
Specified chann
File dues not e
microdri ve,
ALLEMPE EC create a File thar
LT EV"
el has not been opened.
X1St or no cartridge ar
exists. * ready
The specified F
he Lle ts already being
The last component of a fla
already been read.
Microdrive Cartridge ts full,
Specified device Ames not exist.
hag
16 "1 9r changed medium
- | МНОГОЕ 1NM exprassion
mA ICLYhmer Lo overflow
17 AOL implemented
д read only
Cartridge 15 write protected,
- 64 -
mere
INDEX
Address, predeclared type 58
Aceg, predeclared type 58
Array Type 31
Assignment compatibility 40
Assignment statement 41
Attach predeclared procedure 55
Available memory 3
Boolean type 10
Case statement 45
Char type 10
Close predeclared procedure 55
Colour, predeclarted type 58
Commands 7
Comments 25
Compile command a
Compiler errors 9,71
Compiler options 10
Compound statement 47
Concatenation character 16,17
Conditional statements 44
Console window 7
Constant definitions 26
Copy command 1?
Data typea 28
Default microdrive a
Delete command 17
Deleta predeclared procedure $5
Directory command 11
Dreg, predeclared type 78
Editor 14
Edit command 8
Enumerated types 30
Errora
Compiler 9,17
1/0 57
Run-time 11,74
System Ad
Expressions 41
Exit command 13
File names 7
Piles 39,54
Pile type 39
for statement 41
Forward declarations 49
- 8% -
AARNANARUAAAMNNANAA TH NN
Na?
и
mm
Functions
Standard
QL specific
Get standard procedure
Goto statment
Graphics procedures and functions
Help window
Identifiers
IE statement
Input and Output
[7/0 errors
Integer type
Label declaration
Machine code routines
Mark standard procedure
Maxint
Memory access procedures
Menu
System menu
Editor menu
Menu window
New Standard procedure
Mumpbers
Qutput
Parameters of procedures and functions
Pascal Syntax
Pointer type
Procedures
Pur standard procedure
UL Graphres
OL windows
Read standard procedure
Вела | type
har«rt types
Release standard procedure
Repeat statement
Wepetition atatementg
Reset standard procedure
Rewrite qatandard procedure
Run command
Rin-timea errors
Scalac types
Ser type
Startup
Statements
- #6 -
50
67
58
55,68
46
58
7
24
44
sl
57
28
25
6)
17, 38,68
29
37,318,668
23
53
48
22,76
17
47
55,68
58
17,138,668
41
47
55,69
35,69
tl
11,74
28
36
41
Г
LC
E LACA Mr JU A app
|
1
sl она
||
Sering arcays
String constants
Subranges
System errors
Text files
Type compatibility
Type definitions
Types, data
variable declarations
while statement
Window procedures and functions
With statement
- 87 -
33
24
31
Ba
56
40
26
28
26
43
58
16
Mm
~~ TT OY MY OOM Th EMR ANN
">
/
广告