Professional Documents
Culture Documents
02 Whole
02 Whole
by
\,: \'i:L )
TABLE OF CONTENTS
Page
LISÎ OF TABLES vl
SI]MMARY x
DECLARATION x1
ACKTIO!ÍLEDGH"fENTS x11
Chapter
I a INTRODUCTION I
1.1 Coroutines I
1.2 Past Appllcatlons for Coroutines 6
t-
I
I
2. PROGRAI'IMING I^¡ITH COROUTINES 9
3. I Introductlon 2T
ii
Chapter Page
4.2,4.1 IntroducËion 58
4.2.4.2 Extenslons to the Sequence Control Model 60
4.2.4.3 The Sequence Control Operatlons 65
4.3. 1. I IntroducËlon 75
r-1L
Chapter Page
5. I Introduction L57
6. I OvervÍer¿ 169
iv
Chapter Page
7 coNcLusroNs 191
APPE¡IDICES L99
REFERENCES 229
v
LIST OF TABLES
Table Page
vf
LIST OF FIGURES
Figure Page
4.L2 Two Algol 60 Fragnents \úith Ehe Same Data Cont,rol Structure B3
vli
Ffgure Page
v11i
Figure Page
1x
ST]MMARY
Coroutlnes, although known and dÍscussed for some years, are often
regarded as glving rlse to poor program structure and fnefficlent
progran executlon, and are not wtdely avallable in programmlng
languages. This thesls describes a top-down methodology for programmlng
wiÈh coroutines, r¡hich ls based on the exLensLon of the notlon of
hierarchical program st.ructure to cover programs contalnlng eoroutlnes.
The support and promotlon of thls methodology formed Part of the
motivation for the desfgn of a progranmtng language wlËh coroutlnes;
thfs desLgn lras also motlvaÈed by a desire to experiment $tith the
provlslon of a coroutlne facility 1n the framework of a modern, general--
purpose prograrnming language. Among the goals of the language design was
the encouragemenE of a close correspondence between the staEic, textual
atructure of a program wrlÈten ln the language, and lts structure aË
run-time.
The programnlng language ACL has been lmplemented, and some aspects
of this lmplementatlon are also brlefly discussed.
x
DECLARATION
Ttrls thesfs conÈalns no materLal whl-ch has been accepted for the
award of any other degree or dlploma 1n any unlversity and, to the best
of rny knowledge and belLef, contalns no naÈerial previousl-y publtshed or
written by another person, except where due reference ls made Ln Ëhe
text of the thesls.
C.D.Marlfn
16th Novenber 1979
xl
ACKNO}'ILEDGEMENTS
xil
CIIAPTER I
INTRODUCTION
1.1 CorouÈines
I
vLew that coroutines are some speclal kind of procedures ¡¿lth "oúm
variables" (see, for example, Fisher's dlscussion 1n t43l); the contrary
vlew Ls expressed later 1n thls chapter thaÈ procedures are a special
form of coroutines.
2
called ttcommunicatlon variables"; wrlÈlng a value into a communlcation
varlable is held up until any prevlous value has been consumed by all
modules for whlch the variable provides values, and reading a value from
a communicat.ion variable is held up untll any prevlously read value is
replaced by a new one.
3
argument.. Ttre generaÈor then produces Èhe flrst output and calls the
subprocess; after applyíng ltself Eo an ouÈput, Èhe subprocess'calls the
generator, slgnalllng elther thaL it requires another elernent from the
sequence, or thaÈ no further values are required. In the former case the
generator wlll return control to the subprocess after the production of
the new value, and in the latter case lt wtll return control to the
superprocess, it.s task complete. The subprocess and superprocess execute
1n one context, and Ehe generator in another; thus' an amount of context
switching attends the transfers between generator and subprocess. Durlng
the phase that the generaÈor is producing values to whlch the subprocess
applies ltself, the former can be regarded as subordlnate to the latter
and the relatíonshíp betnreen them can be regarded as asymnetric, being
that between a calling and a called routine. The fact that the generaÈor
executes in a different context from lts caller, and that Ehis context
fs saved between successlve calls, gives Ehe generator a coroutÍne-llke
behaviour. The relatlonshíp between the generator and the superProcess,
on the other hand, is more l|ke that between a procedure and lts caller,
sfnce the generaÈor restarEs the production of values from the seguence
each tlme thaË it ls called by the superprocess'
From these orlglns, the term rrgeneraÈor'r has come to be used fox a
coroutine whose behavLour ls rest,rlcted 1n that lt returns to lts caller
'(Lnvoker) on completion of its Ëask. Ilowever, a generaÈor is st1ll a
Coroutl-ne, in the sense that the values of local data ar.e reÈained
between calls, and execution of a generator always continues from where
ft left off when 1t reEurned from the previous call. The "semicoroutine'l
facflity of the Slmula language[32] and Èhe "semí-s¡mmetric coroutine
lfnkage" described by llang and Dah1t152l both provide a slmllar caPa-
b1l1ty Ëo generators.
A procedure can be regarded as a form of coroutíne which has
further restrlctlons on lts behaviour, ín addiÈlon to those for a
generator: 1t j-s a generator which starEs r.¡ith a fresh set of local data
and comnences executlon from its first statement (instrucEíon) on each
occasÍon thaÈ it l-s called, but becomes suspended (in the coroutine
manner) 1f it calls another subprogram, having it,s execution resumed at
the polnt of thaÈ call wlth the same local data values when that
procedure returns.
4
Thus, the relatlonship between coroutJ-nes, generators and
procedures can be viewed as one of imposing more and more restrictions.
Thls leads to the vlew, also expressed later tn this thesis' thaÈ the
cholce of one of these Ehree for a parÈicular subprogram being designed
represents a declsion about the expected behaviour of that subprogram'
1n Èerns of r¡hich of the resÈrl-ctlons (if any) apPly'
5
of coroutines.
In the remalnder of thl-s chapter, the term "coroutlne[ r¿111 be used
to cover both coroutines and generators, excepÈ where generators are
speclf ically excluded.
The coroutine faellity of Siuula lras Èhe main reason that ít was
used for the SCRABBLE Crossword Game program described by Shapiro and
Smlthtl33l. In thl-s program, the subprograur v¡hich performs searches to
find words which can be forued using the current seÈ of tlles was made
as a generator; this means that lt can return to lts caller after a
6
certain number of such words have been found, but that the search can
later be resumed if more words are required for that same set of tiles.
poËentlal uses for coroutlnes are described and classified
Numerous
by Sevclktl32l, t,hese uses comJ-ng from a number of applicatLon areas,
such as business data processing, Èext ProcessLng' simulatlon, and
varlous kinds of daÈa structure manlpulatlon.
It has often been saLd that there are few prograuming languages
wlth a coroutlne facllity; for example, this comment ls made by
Floydt46l, Grune[59] and SevciklL32J. As lndlcated in the survey of
Bobrov¡ and RaphaeltfSl, one group of languages which provides a number
of examples of coroutine facl-llties fs thaE concerned wiÈh artlficial
lntelllgence programming; those artlficial intellÍgence languages
containlng a coroutlne facility include CONNIVER[145] ' SAILlL26,L40) '
TELOS[89, 148] and 2.PAKll07, 10Bl .
7
fntroductfon of coroutlnes lnto APL.
8
CHAPTER 2
(2) the data control structure of the program, using the data control
features of the language, and
(3) the data structures used in the Program' using the language's
data structurl-ng facilities'
9
EVery progranmer r.rritfng a program in a hlgh-level language assigns
some struc¡ure to the data manipulated by the prograrn; some data items
are composed of constltuent parts arranged Ln a manner significant to
the progranmer; others consisÈ of a slngle data Ítem, buÈ these have an
fnternal structurer so thaÈ the same string of bits occurring l-n two
fÈems may have completely different interpretaÈions. It is the purPose
of Ëhe data structurlng facilíties of a language to allor¿ the expression
of fhls structure whích the programmer has deslgned for the program's
data. In some programml-ng languages, referred to as 'rstatically typed",
the sËrucÈure (or Ëype) of data is clear from the statlc program text'
elther by declaration or from some other evidence; ín programs r¡ritten
in such languages, ft is possible to deduce the tyPe of any expression
fn the prograü' by an examlnaÈion of Ehe program text'
10
program text reflect the structure of the computaËionr', and he then
lnvesÈlgaEes the consequences of this deslre, wíth respecÈ to sequence
control at t,he staÈement level. Corout.ines have a reputaEion for being
more dynamlc Èhan some other klnds of subprogram unit: for example, the
coroutlne transfer command ttresunett has been líkened to tta go t.o command
wlth a moving target'r L82J, and dynamlc (rather than statlc) scoPe rules
have been descrlbed as rtuseful for coroutíne programming" [621 . There has
traditionally been a larger gap between static and dynamic st.ructure ln
the case of coroutine programs, than r¿ith programs not lnvolving them.
One of the maJor aims of the work described in thís thesis was to
investlgaÈe ways of programming wlth coroutlnes, and coroutine
facllltfes for programmíng languages, whlch minimlze the difference
between the sËatfc and dynamic structures of a Program Ínvolvlng
coroutines; stated anoEher way, Èhe afm 1s to make the dynamic structure
more obvious from Ehe statlc structure.
11
group), and in Èhe members (if any) of those subrograms ln which 1t 1s
accesslble; in other r¡ords, access to an item is resÈrlcted to the sub-
hierarchy encompassed by the ltern's defining subprogram. In practice' ft
1s desirable to be able to restricÈ access to items even furEher' by
specifying that only a subset of the members of a group nay access an
item whfch could have been accesslble to all of thern. lhe principle of
opaqueness may be regarded as dellmlting the maxlmum accessibllity of an
item, and effectlvely hldes the lnner detail (both data structures and
of a subprogram from subprograms
ttoutsldett it'
Subprogram componenEs)
to the rrÍnf ormatl-on hiding'r criterion
used by
This is simllar
Parnastl20] 1n decomposing systems into modules¡ and is used by
declarlng ltems as lor¿ down 1n the hlerarchy as possibler so Èhat the
smallest number of subprograms 1s perrnitted to access it, whl-le sÈill
Lncluding all Èhose which musË have access to 1t'
L2
control.
As a program strucËure deslgned usLng Èhis nethodology evolves
dynamlcally at run-time, elementary subprograms catervate into groups'
Just as they do durl-ng the deslgn of the program. A subprogram
catervates by creaËing the members of the grouP; the caEervaÈing
subprogran Ls regarded as becoming a member of the group, and is known
as the ttbosstt subprogran of the group. The latter is clearly always an
elementary subprogram, slnce any subprograms 1t creaÈes become further
members of the group, and it equally clearly is the first member of the
group to be created, since there ls no group when 1È 1s creaÈed. As w111
be seen, ln additlon to creatlng the other members of the group, the
boss of a group frequently also coordlnates the execuÈion of those other
members.
follows:
13
point.
The result of ls a serles of networks,
Èhe program deslgn process
1n which the nodes themselves may be neÈworks, and for each arc 1n these
neÈworks there is a transfer conditlon. The PaÈtern of passage of
conÈrol into and out of all nodes is then studied, by examining the
transfer condltions; any nodes for which these transfer conditlons
lndicate that the corresponding subprogram 1s called on Èo perform a
partÍcular task, and then returns to its caller' can be speclalized to a
generator or a procedure. As menÈloned in the previous chapter, this
speclalizatlon 1s deslrable, slnce lt provides informatlon about the
expected behavíour of the subprogram - lnformation r¡hlch may be useful
to someone atternpÈÍng to understand Èhe program, or to a Èranslator
program, for the PurPoses of oPÈinizaÈion. The choice belween a
generator and a procedure requÍres more lnformatl-on than Just Èransfer
conditions, and Ís based on whether or not Ëhe subprogram must retain
lnformatLon about lts state between returnlng and subsequently being
called again.
I4
not chargeable and hrords of more than twelve let,ters are considered
overlength. The result of the processlng ls to be a neat lísting of
the telegrams, each accompanied by the word count and a message
lndlcatlng the occurrence of an overlength word'
15
In additlon to Èhe buffer, whlch is shared primarlly between nodes
2 arrd 3, node 2 must have access to thq inpuÈ file and node 3 to the
output flle; all of these data structures are also made avallable to the
boss of the group (node 1) for the purposes of initializatlon and
termlnatfon actions. The data sharlng relatlonshlps in the network can
thus be summarized as:
1r2: lnput fflei Lr?r3: buffer; 113: ouÈput file
The transfer conditlons for thls network are derived from its
structure and from the stated functlons of its member subprograms; these
transfer condLcions are as follows:
(1,3): lnltial start-up
(3,2) the buffer needs filllng
z
16
transferred to a subprogram (t'5tt) whlch Processes a slngle telegram;
node 5 calls on node 4 r.rhenever a new word is regufred, and transfers Èo
node 3 when the r¿ord "ZZZZ", slgnifying the end of thl-s telegram, is
detected. Node 4 slnply exEracts a word from the buffer and recurns
control back to its caller (node 3 or 5) when Èhis 1s done; if the end
of the buffer is encounÈered as the word is being bul1t up' control is
Èransferred to node 2, which f1lls the buffer. The network for this
group has the sÈrucÈure:
to2
from 2
to I
from I
Notlce how thl,s diagram l-ndlcates Èhat nodes I and 2 have no
knowledge of the inÈerna1 details of Èhe grouP; to them the entlre group
1s known sirnply as node 3. For example, when node 2 has filled the
buffer, and returns control to node 3, 1Ë Ls node 4 to which control
acgually passes, since it rvas thls member of the grouP knov¡n as node 3
which was lasÈ active.
T7
blank. The following diagran shows thl-s network's relatively simple
s trucLure:
to2
from 3r5
to 3r5
The data sharing ir.t the above neÈwork can be described as f ollows:
1B
the nodes ln that neËwork happen to adhere to thls restrictl-on. The
reason that this ls done, raÈher than slmply leaving the subprograms as
coroutLnes, ls that 1f the fact thaË a subprogram exhlblts this 'rret,urn-
to-callert' behavlour 1s expressed in the program text, it can be used by
a reader of the program (to aid in the process of understanding the
progran), and posslbly also by the language Processor (to optinize the
executlon of the progran).
19
Table 2.1 Caller-Callee RelaÈl-onshlps 1n Figure 2' 1
20
CHAPTER 3
3 .1 Introduction
The motivatfon for designlng a nerr programming language was that
there are relatlvely few languages wiËh a high-level coroutlne facilfty
(as distlnct fron languages in whlch coroutines can be simulated), and
thaÈ those languages which lnclude such a facllity are almosÈ invarÍably
the so-called t'advancedtt programming languages. As such, Èhese languages
also contain a number of novel features not concerned wl-th coroutines¡
examples of such features are the class prefixLng and slmulation
scheduling features of Simula[16], and the data base faclllty of
TELOStSgl. The pre,sence of these advanced features tends to make sinple
coroutlne programs (those employing the usual features of a procedural
programming language, as r¿ell as coroutl-nes) dlfficulÈ to wrlte' read
'and debug; in addition, the efficlency of the implementation of these
languages ls often much less than that of familiar programming
languages.
2T
The next sectlon enumerates the goals of the language deslgn, by
descrlblng some criteria by which Ehe final product should be judged'
The following sectfon descrlbes a methodology for programmLng language
desl-gn whfch results ln the deslgn of an abstract descripÈlon of the
semantics of each of several aspects of the faciltty belng designed.
Thus the semantics of the whole language will not be descrlbed, buÈ only
that part related to coroutlnes; the remalnder was borrowed from a "base
languagett. In fact, a class of languages is described by the abstract
deseripÈfons of the various aspects of the facility, slnce they could be
used to add the factlity to a number of existing programning languages.
The chotce of the parttcular base language used is explained ín the lasÈ
sectlon of this chaPter.
22
do noÈ allow the accgrate expressJ-on of a wide range of data
control structurest
(5) the set of feaÈures provided |n the language should be as small
as possl-b1e, while st111 allowlng the succinct exPressfon of
solutions to a wide varieËy of problems, and these features
should be sinple and readily understood; in partlcular, Èhe
temptatfon to introduce other ttadvanced" facillties noÈ related
to coroutines should be avolded,
(6) it should be possible for an implementation of the language to
ensure the secure execution of any program written in the
language, by enforclng all of the restrLctions of Èhe language,
and
23
the flrst four crlteria take precedence over the flfth (expresslon
and comprehenslon of structure ls more lmportant than minÍmality or
slnplicicy), and
the sixth criterion has higher prioriÈy than Èhe seventh (securlty
1s rnore important than eff l-ciency).
24
given a syntacElc form and ernbedded ín the base language. Furthermore,
the design of the semantl-cs of the coroutine facilíty was divided into
the deslgn of that of three aspects of the facllity' corresponding to
the three aspects of programs dÍscussed in Chapter 2: sequence control,
data control and data strucÈures. It turns outr 1n practice' ÈhaÈ
programming language features can be conveniently divided into those for
the description of each of these aspects of programs, and that the
deslgn of feaÈures r.rithln one of these aspects is relatively lndependent
of that of the other two aspects. The categotizatlon of language
features inÈo these three groups is similar to the notfon of 'rconÈro1
separatÍon'r described by Lemon et al. 1921, in which only two categories
are used: one for the "data-relatedrr components of a language, and one
for the ttconÈrol-related" components.
For each of the three aspects, the following steps r+ere taken:
(1) fl-rst,ly, an abstract model of this aspect was designed,
(2) next, the nodel for thfs aspect hras used Ëo compare previous
proposals and exlsting languages with Èhe facíl1ty of interest'
and
25
independent, sub-tasks; they also meanÈ that the descriptlons 1n terms
of the varíous models were siuple and facflltaEed tTre process of making
comparísons.
Stanat and McAllLster ÍL42) deflne a model as "an analogy for some
obJect or phenomenon of ínteresÈrr and the three models used 1n this
thesfs all represent analogies. They do, hol¡everr Var1z greatly in the
extent to whlch they are "formal" or rrmaÈhemaËical'r. The model used in
the design of Èhe data structures aspect of Èhe coroutlne facility
consists of a partlcular (lnformal) vlew of the data structures required
to support coroutÍnes, buÈ thls Idas adequate to make the necessary
comparisons, and to descrlbe this aspecE of the proposed coroutine
faellity, 1n an abstract Iùay; 1n fact, very líttle ls saíd about daÈa
structures, since most of these were borrowed from the base language'
rrrith the addition of only those necessary f or corouti-nes. The models
used 1n the design of the other aspects are both more formal: ín facÈ,
they are both ttoperaËiona1 models'r, in ÈhaÈ conputations are represented
as, sequences of transformaÈlons on lnformatlon strucËures and the
semantlcs of a partícular language feaËure is described in terms of the
effect that tts execution has' on the inforuaÈion structüEês. The result
1n all three cases \ùas, however, the Same: an absLract description of
that aspect of the proposed facility. The design of the semantícs of all
three aspects of the proposed facillty is described 1n Chapter 4.
t{hen all three aspecEs of the coroutlne facllity had been designed
1n the above manner, a syntax consistenÈ \üiÈh the base language was then
developed. As Hoare has sald[67], the design of syntax is not a trivial
or arbitrary aspect of language deslgn, and 1t deserves Ehe greatest
care. However, 1t ís lmportant thaÈ the design of a language's syntax be
entfrely separate from that of its semanEics: PremaËure commÍtment Èo a
partlcular synËax ís one of the maJor mechanisms by whlch arbitrary' or
unconscious, decisions are made about the semanLics of a language'
26
sequenclng kind of coroutines r¿hich are belng consldered fn this
thesis,
( il) the language must be such that programs consist of textual unlts
(called blocks) over the whole of whtch Èhe same set of names,
with the same set of interpreÈations, is known - such languagest
whtch will be deflned later to be block-strucÈured, have Ehe
advanEage of allor¿ing the programmer to fact.otLze the sÈate space
of a program lnto ueanl-ngful subspaces, whtch greaEly alds the
development process and improves the readabillty of' the final
product, and
(i11) Ëhe language should require the declaration of all names used 1n
a program (apart, perhaps, from a seÈ of "predeclared'r names) and
such declaragions should indicate, to some exÈentr the kind of
quantlty for which that name is to be used that ls, the
language should be statlcally tvped.
27
(2) lts set of sequencecontrol primitfves at the statemenÈ level 1s
powerful, and encourages the producÈLon of subprogram units whose
lnternal structure ls lucld,
(3) lts set of data strucÈurlng feaÈures fs snall but qufte
expressÍve, and
28
CHAPTER 4
29
date, languages allowing expllclt namlng of subprogram lnstances
(usually those of coroutlnes or processes) have achieved lt by provlding
an rtinsLance referencett data type (data strucÈure), variables of this
type conÈalning a reference to an lnstance. Consequently, ft is possible
l-n such languages to have several fnstance reference variables conÈaLn
references to a single lnstance, aÈ the one time'
30
that the programmer should be afforded the opPortunlty to sÈaÈe such
lnformatlon (and to have 1t checked).
InÍÈ1ally, an lnstance varlable cofitalns Èhe value ttno-Ínstance",
lndlcatlng thaÈ lt does not contaln an lnstance; a predlcate ls provlded
whÍch accepts any lnstance varlable and evaluates to elther
tttrue" or
ttfalse", dependlng on whether or not the varlable contafns an lnstance.
Also, a procedure ls provided whlch ttdeletes'r an instance by seEting Èhe
corresponding lnstance varlable to 'rno-lnstancett. Another predicate
provided in the language fs one whtch evaluates Èo t'truett only ff the
lnsËance varlable provided to 1t contains Ëhe currently executfng
lnstance. Clearly, the two predicates and the procedure accePtr âs
arguments, lnstance varÍables of any tyPe.
31
4.2 A\e Semant s of the Sequence Control AsPect*
4.2.I IntroductÍon
Thls aspect of the design ls concerned only with sequence control
between subprogram instances. Features concerned r¿íth sequenclng between
staËements and groups of statements, and sequencfng wlthln expresslons,
w111 not be discussed; Ln fact, such features were borrowed from the
base language. Furthermore, slnce the discusslon will not be concerned
rvl-th data control, it ls assumed that any ldentlfiers referred to ln
seguence control operatl-ons are accesslble.
Since there are no differences between procedures and functlons ln
Èerms of sequence control effect, funcÈlons w111 not be consÍdered
separately ln thls section; any argument applied Èo procedures may also
be applled to funcÈions. Siuilarily, arguments applled to coroutines and
generators may also be Èransferred to subprograms whlch have the same
sequence con¡rol effect, but whlch return a value (that ls, r¿here the
calling expression ylelds a value), where such subprograms exist in a
language . Also, t.he so-called "anon¡Imous " blocks of some block-
sÈructured languages (for example, A1gol 60 tll2l ) w111 not be considered
separately from procedures, because of their sequence control
sfmllarity.
The remainder of this section f s organLzed in a manner v,rhich
reflects the steps acÈually taken ln the deslgn of thls aspect of the
corouÈine facilfty:
32
4 .2.2 T:he Sequence ConErol Model
The first two primltlves above are also present in the sequence
control model. Notlce Èhat instance reference variables are used in Èhe
model, whereas fnstance variabl-es have been chosen for ACL. Instance
reference asslgnment and mulÈiple references to lnst.ances are both
necessary in the descrlptlon of sequence control operatlons' and Èo
allow thern ln the sequence control model is not inconsistent with the
declslons made 1n the design of the semantics of the data sËructures
aspect of ACL, since l-t ls stfll possible for Èhe desfgn of the other
aspects of the proposed factltty to preclude the user program havlng
access to more than one reference to an lnstance (whtch ls
effectively the same as havfng lnstance variables).
33
Instead of the single recelver variable of Stanton's model, the
sequence control model regards each Ínstance as havlng tkTo ínstance
reference variables. These are the "mastertt variable' whlch fs used Èo
record statically-derived relat.lonships between lnsEances, and the
rtcallertt varlable, which 1s used to record dynanlcally-derived
relatlonships. In addltion, the ldentlfler t'currenttt can be used in
descrl-pËlons of sequence control features to obtain a reference to the
eurrenÈly executlng lnsËance. Consequently, Stanton's thlrd primltlve is
not Lncluded tn Èhe sequence control model, iÈs effect being obtained by
eLther ttattt"a. current.mastertr or tt=ttat current.callerrr, dependlng on
circumstances. The familiarttdoÈtt noÈaElon 1s used, as shown, to refer
to attrLbutes of instances.
As will be discussed in detall in Sectlon 4.3.L.2, storage
management. is elose1-y related to data control, and hence is of little
interest here; since Stant.on's fourth primitlve is purely concerned ¡vith
storage management, it ís not lncluded in the sequence control model.
Although, the ""r""grt' primitive is also related to sÈorage management
evengs, lt has effect.s whlch are of interest in rnaklng comparlsons
between the sequence control effects of varlous features: iÈ
rrestabllshesrr (but does not necessarily al1ocaÈe storage for) a nelv
instance of a definltlon, and it sets the conËlnuatlon polnt of that
l'nstance to the beglnning of lts definlti-on.
(4) Ëhe condítlonal and repeË1tlve statements' and the loglcal and
34
relatlonal operators, of Pascal r¡111 be used in obvfous ways Èo
express declsion structures \illthln descrlptlons (keywords w111 be
1n lower case letlers and underllned, sinllar to the prlmiËlves
described above) ' and
35
operatlon of Stant,on's model ls another example of an undl-rected
transfer operatlon.
Clearly, thls roodel is considerably nore formal than that used in
the desfgn of the FemanÈlcs of the data structures asPect; Èhis reflects
the greater diverslty of sequence conErol features in the coroutlne
facilittes to be compared, and Lhe greater number and complexlty of the
decislons to be made 1n the design of thls aspect'
Sluula
Thls section will demonstrate how the sequence control model can be
used to descrfbe succinctly the coroutine factlity of an exlstlng
language, and wlll indicate how some prevlous descrfptíons of the
trclass" facility of Sirnrla have been misleadlngly naive' Those
propertles of the SÍmula facility whlch hlnder Ëhe writing of simple.'
clear coroutlne programs axe tdentified once an lndlcatlon of its true
nat-ure ls given.
36
A very slmple deseriptlon of sequence conÈrol ln Slnula is given by
StanÈon ln 11431: tt 1s that a Sinula class may behave as a coroutlne or
as a generator, dependlng on whether lt is enÈered Vla a ttresumett or a
trcalltt, respectively.
passes through
call(b) ttendtt
resume (c)
call (d) detach
resune (e)
37
begln
ref(A) a; ref(B) b; ref(C) c; ref(D) d; ref(E) e;
class A; begln detach; call(b); ... call(b); ... end;
class B; beeln detachi ..o resune(c); ... resume(c); ... end;
class C; begin detach; ... detach; ... call(d); ... end;
class D; begl-n detach; ... resume(e); ... end;
class E; begin detach; . .. detach; . .. end;
a:- neÍI A; b:- nerv B; c:- new C; d:- new D; e:- new E;
resume(a)
end;
3B
lnterest 1n thts sectlon), and control enters the instance at its
beglnning. Ilrrlng the ensulng lnltlalLzatlon phase, the lnstance ls said
to be executÍng in the 'faÈtached'r gtate. The evaluatlon of the creating
expresslon is completed when elÈher a ttdetach" Ís executed by the
lnstance, or the instance reaches lts "@tt; fn the former case' the
lnstance ls now l-n a 'rdetachedrr state, and ln the latËer r lt is
ttterminaÈedrt. To record the state of a class lnstance' a new varlable ls
defined for each such instance, called 'rstate'r; thls varíable can take
trdetachedrr and tttermlnatedtt.
On any of the Values trattaChedtt,
39
Control wfll return to thts definltlon, at the süatement after rrenter
Att, when Èhe inltlallzaElon phase of the creaÈed lnstance fs complete
(regardlng the execution of "nel¡ dtt as a macro expansion 1n the objecÈ
Ln whlch 1t occurs), because of the effect of 'rdeEachr', as explained
below. A reference to the newly-created instance will then be returned,
as the value of the expresslon ttnew d".
Theeffect of a I'detachrr in an attached instance is to cause the
lnstance to become detached and control enters the instance to whl-ch
this one is attached, given by lts caller varlab1e. This covers not only
the case of creatíon, buÈ also Èhe case where an lnstance is ttcall"ed,
thts latter prlniËive being descrlbed later. If the instance is a
detached componenÈ of a quasl-parallel system' tt is suspended and
control returns to the main program of this quasl-parallel system' as
lndicaËed by its master variable. In Eerms of the model, Èhe effect of a
t'detachtt is:
detach = { lf currenL.state=attached
then I current.state+detached; enter current'caller ]
else enÈer current.master )
Frornthis definÍ-tlon, it ís clear that the "statett of an lnstance
acts as a swftch determinlng whether a "detach" causes conÈrol to pass
t-o thaÈ lnstancets rrmastertr or 1ts ttcallertt.
resune(f)={enterl}
The primltlvettcall" also has a parameter, say ttit', referring to a
detached instance whlch Ís a componenÈ of a quasl-parallel system. Thls
primLÈlve causes the lnstance indlcated by "Í" to become attaehed to Ehe
instance contaínlng Ehe t'calltt (not.ice the slmllarity Eo the
lnitiallzation phase during lnstance creatlon), control enters the
Lns¡ance referred to by "1tt, and thls lnstance continues execution. In
terms of the model, thls ls:
40
calt(1) = { 1.callerêcurrent; l.stateêattached; enter i }
The effect of reachlng the "endtt of a class lnstance 1s the same as
terninated:
41
l-n the t'detached" state, and hence thelr caller 1lnks are not depicted
(since these have no meaningful values ln that case).
P P
I 3
P
2
42
the lnstance to whlch control is transferred, 1n a manner slmllar to the
one descrlbed above; slnce the preflxed block 1s no\ü the acÈive
component of fts quasi-parallel system' a sub-tree whose rooE ls a
componenL of this system nohr becomes suspended. A
ttdetachtt from ¡vithin
an attached class lnst.ance (or a procedure on its assoclated stack)
causes the tnsÈance to beco¡ne suspended and the lnsÈance lndicaÈed by
lts caller varlable, which may be an instance of any kind, to be
entered.
43
trdetachtt), and
coroutine or a generator.
44
"ca11" is used to good effect slnce no dlstincË1on is made beÈween the
flrst ttdetach" encountered dynamically, and subsequent ones. Although
elegant once flnally understood, the operaÈion of this program is
difflcult to deduce and equally difflcult to descrlbe; ParÈ of thls
difficulty ls due to Èhe fact that some of the ltnks ln Èhe parse tree
generated during the computaÈion are expllclt, fnstance reference
variabl-e lÍnks, whereas others are "attached Èorr llnks implfclt 1n the
computatlon before references to the corresponding lnstances have been
returned (since ttlnitiallzationrr is noË yet complete) - Thus it ls clear
that part of the dlfftculty arislng fron (1i) 1s, Ln fact, due to (r);
however, even 1f the difficulty ln (f) Itere overcome' clearer programs
would probably result fron restrictlng the kinds of transfers of conÈrol
out of an lnstance during lnltiallzatlon.
Various other coroutlne facl-litfes will now be descrlbed using the
sequence conÈrol model, but ln less depth Èhan was the case 1n the
precedlng deseripEfon of Sfmula.
45
The two ma|n sequence control operaÈions 1n Gentlematl's system are:
I = ( l.caller <-current; enter f
INVOKE )
RESUMEi=(enreri)
Ln which rrfrr ls a reference to (that 1s, the copyname of) a coroutlne
lnstance. These operaÈions elearly corresPond to Simula's ttcall" and
t'resumett, respectfvely. Ttrere is no primltlve operation correspondlng to
ttdetachtt, buË the caller aEtrlbute of an fnstance is expllcÍtly
available r.rlthin that instancer âs the coPyname varlable "CALLER";
hence, the effect of a'rdetachtt can be achleved by ||RESUME CALLERIT.
rri-rl
where rrreseE(1)tr simply seÈ.s the continuaÈlon poinÈ of the lnsÈance
to lndicate the flrst (executable) sËatement in the correspondi-ng
deflnition. In these definlti-ons, it is assuned Èhat one lnsEance of
every subroutine definitlon (with the same name as the subroutlne
deflnltion) is created prior to the commencement of Program execution.
CorouLÍne PASCAL
46
regards executing programs as conslsting of cycles of lnstances' all but
one of whl-ch are suspended; the actlve cycle, called the 'roperatlng
chaln'r, Ls the one which conËaLns the main program and the ttprocessor"
(the execut.l-on envlronmenÈ of the entlre program). The varlous coroutine
sequencing prinltlves are then regarded as having the effect of deleting
eycles from, and/or addlng cycles to, the operating chain'
Following llang and Dahl's model, Coroutlne PASCAL does not have the
concepÈ of quasi-parallel systems, nor of any statlcally-defined
sequence control relatlonships beÈween lnstances. I{hen describing its
features with the sequence cont.rol model, the ttcallertt at.tribute of an
instance w111 be used to record Ëhe slngle dynanlcally-defined
relatlonshÍp between lnstances. There ls no staEic distlnctlon between
coroutines and procedures ln Coroutine PASCAL, thls being a dynamic
dlstinction determined by the "sËatusrt of an instance. The staEus of an
Lnstance is always one of the followÍng:
47
ACTP ACTC ACTP ACTC ACTC
SAC
4B
The najor sequence conÈrol operaÈlons of Coroutlne PÀSCAL are the
followfng:
CALLi={Aêi;repeat
Á, +cal1er;
A.
lf A.status l¡.Ctp then A.status <-ACTC
Ps!4 A=l;
A<-t.caller; i.callerêcurrent; enter A )
DETACHi={A<-current;
rvhf le A # i do I if A. status =ACTC then A. status <- SNAC;
A+A.caller l;
L.staËus <- SAC; A + i.caller;
l.callerêcurrent; enÈel A )
RESIIME f = { A+i; repeaÈ
A <- A. caller;
lf A.status +ACTP then A.status <-ACTC
untll A=Íi
A<-current; while A.status lAcTc do A<-A.caller;
B <- i.caller; 1.caller +A.caller;
A.staÈus+SAC; A.caller+current; enEer B )
t'i" are
In the flrsÈ of these, the Lnstances ln the cycle lndicated by
inspected and any coroutine lnstances acqulre the status ttACTCtt; afÈer
this has been done, the cycle fs slmply appended, by the polnt indicaÈed
by "ltt, t.o the end of the operating chain, and the lnsÈance whfch hras aÈ
the ttËalltt of the "CALLrred cycle (glven by tti.callertt before 'TCALL i'r)
ls entered. The second operation descrlbed above Ís a ttmulËi-level" form
of Slmula's "detach" (also, fndependently, suggested by R¿ulefstI25I);
rritr and
tÈ sl-nply breaks the operatlng chain between the instances
tri.callertt, the former becomlng the head of a nerr suspended cycle and
the latter galnlng control. The lnstance t'Ítt, whlch musË have status
IIACTC" bef ore
"DETACH i", has l-ts sEatus changed to rrSACrr; any other
fnstances on the ne\,ù suspended cycle r¿hlch are actlng as coroutines have
their status changed to "SNACT'. In CorouÈine PASCAL' the ldentifier
ttSELFtt refers to the nearest corouË1ne lnstance Èo the currently
executlng insÈance on the operaElng chaln (t'SELFtt indlcates the
currengly executing lnstance 1f lt 1s a corouÈlne lnstance); thus, the
effect of Simula's "detach[ can be obtafned by ITDETACH SELF". The ffnal
49
operation above, TTRESUME", flrstly seÈs the staEus of all coroutine
fnstances on the cycle belng ttRESUME"d to "ACTCrr, and Èhen the nearesÈ
coroutine lnstance to the currently execuÈlng lnstance 1s located (in
fact, a search fs no¡ necessary Ln the actual lnplementatlon' since lt
is recorded in TTSELF'|), this lnstance beeoming the head of a suspended
cycle aft.er its status has been changed to trSACtt, and the head of the
I'RESIJME''d cycle (that is, rrirr) belng appended to the oPeratlng chaÍn;
2.PAK
50
reference to the creaÈor, to enable a reÈurn after lniÈialization
processing. Notice Èhat t.he above descrlpt.lon states that the reference
to the creaÈed lnstance is returned before Èhat tnstance 1s enEered for
Ínl-tialization, unllke Èhe sLtuation in Simula; this is lnplied, but not
clearly stated, by Me1li in [107]. The sequence control operations
lnvoke 1 { 1.caller+current; enter L }
detach = { ent.er current.caller }
51
Table 4.1 A Comparison of Sequence Control ln Simula and 2.PAK
SL5
and lnstances created in thls manner may then be used as generators vLa
the palr of operatlons:
resume 1= ( t.caller+current; enter i )
52
where rrrrr is once agaln the transmitted result. Notlce thaÈ the major
way Ln whlch 1r thls facility dlffers from that of 2.PAK' Èo which ls
slmllar ln nany other respects, ls that the slmmetrlc coroutlne Ëransfer
opera¡lon ttr.È"rn ... to .. .tr does not pass on the obllgatlon Eo return
to a caller (called a ttresumertt in SL5).
starEi={enterÍ}
53
Control is passed among the varlous coprocedure lnstances through
the use of the following statemenÈ:
srüapf={enteri}
and control may reËurn to the bodY of the cooperatlon through the
executlon of a rrreturntf statemenÈ (or through the LermlnaÈion of a
coprocedure, whlch has the sane efflct):
s4
statement) has the follorrlng effect:
Saianíeml's Cogroups
55
descrlbed by Pritchard and, once agaln' means that the grouP of
coroutines behaves as a Procedure.
Another slmllarity between the above three schemes is that the only
means of Ëransferring control among the members of the grouP is a sfunple
coroutine transfer, there belng no provlsÍon made for the establishment
of a generaÈor regime
56
lnstance) .
TELOS
57
A ttsrsp".tdtt event sEatement ln a coroutlne or overseer lnstance
returns control Eo the appropriate event handler aÈ the polnt of call;
ln terms of the sequence control model, Lts effect ls descrlbed by:
Suspend e = { current.caller.suspender <-current;
enter currenÈ.caller )
ln which tte" ls the event ldenÈifier, whose purpose was explained above.
The LdenÈlty of Èhe instance executlng the above statement is recorded
1n a varlable, called "suspendertt and lntroduced ínto Ehe model for the
descrlption of TELOS, of Ehe l-nsÈance t,o r¿hlch the statement passes
conËro1; thls lnformation nay be used by the standard procedure
ttResumett, whtch has the following effect:
4.2.4.1 Introduction
The startlng point for the deslgn of the sequence control features
of ACL was the vie¡¡ that procedures, coroutines and generators all
represent dlfferent patterns of sequence control behavlour, and thaL fn
5B
speclfylng a subprogram in a progranlning language, a Programmer should
be able to state which of these behavlours ls exPected. SpecÍfically'
these three klnds of subprograms are Eextually dfstlngufshed from each
other (unltke the sltuatlon ln languages such as SL5 and Coroutine
PASCAL)
59
The main program lnstance w111 be regarded as a coroutine lnstance
for the purposes of this dlscusslon; 1t 1s elementary If. there are no
coroutlne or generator lnstances creaÈed by the program, but ls caterval
if any such lnsËances exist.
Because of some data control restrlctlons dfscussed later ln thís
chapter, there is a close correspondence between the static nesting of
coroutine and generator definitions in the text of an ACL program' and
the dynanic grouplng established by instances creating other instances.
Slnce grouping 1s a statically-derlved relatlonship, 1t w111 be
represented via master variables in the sequence conÈrol descriptions:
the rnaster variables of the members of a group fndÍcate the boss of Ehe
group.
1n whlch Ehe dashed arrolrs represent caller llnks. (In Èhls and other
representations of dynamlc program structure, the "Citt are coroutine
instances, the ttGltt generator lnstances, and the ttPitt procedure
fnsEances; recall that the main progråm lnsÈance Ís regarded as a
60
coroutine lnstance.)
The structure of executlng ACL programs w111 be depicted via
rrmaster treesrr, in whlch the lnstances of the prograB are arranged ln a
tree based on the master llnks among corouÈ1ne and generator lnstances.
In such trees, the master llnks will be depl-cted as stralght solid
arrows, Èhe active lnstance of a grouP wfll be indicated by a curved
solid arrov¡ from the boss of the grouP, and the stack of procedure
lnstances associated wtth a coroutine or generaÈor instanee will be
deplcted as above. (Compare thfs Èree rePresentatlon wlth the
representat,lon of Simula run-Èlme structure 1n Figure 4.3. ) For example,
Ffgure 4.5 depÍcts a master tree qrÍth the caterval coroutl-ne l-nstance
ttCltt as lts rooÈ; notlce that "C2tt is the active member of "C lt', ttC4tt
that of ,rC.rr, and ttG5" thaÈ of t'Ch". Notlce also that lt 1s the boss of
Itcrt' which ls lts actlve member.
61
lnterrogaË1ng that of "IZttl. 1n general, a set of lnstances becomes
suspended and another set of lnstances becomes acElve' Ehrough the
adJustnenE of active llnks. Si-nce "ir" Ls an insÈance of a coroutlne or
generator, Lt may have some lnfrastructure, and iÈ ls necessary to find
whfch of the lnstances eomposing this lnfrastructure actually galns
control. The lnstance to which control ls acÈually transferred when a
coroutine or generator instance rrirr is entered is referred to as the
ttlivett insËance wfthtn rrltr and is denoted "llve(1)tt; the algorithm for
lts computatlon 1s given l-n Flgure 4.6. In thts algorlthm, "top(i)"
evaluates to a reference to the procedure lnsÈance on top of the stack
assoclated wfth Èhe corouÈ1ne or generator lnstance |tirr (if thls stack
1s empty, a reference to rrltt ítself ls returned). The algorlthm 1s
wrl-tten 1n a notaÈion simllar to Ëhe sequence control model, and the
value of "live(1)t' is the flnal value of Ëhe variable t'l1ve". The
computatlon of which lnstance gains control sinply lnvolves startlng at
the l-nstance rrlrr (which 1s a coroutlne or generator lnstance), and
followLng the actfve links until an elementary lnstance' or a caterval
lnstance l-n nrhlch the boss ls actlve, is encountered; the requlred
lnsÈance ls then that on top of this fnstance's sÈack of procedure
l-nstances (or the lnst.ance ltself , l-f the stack is empty). For example,
the lÍve lnsËance r,rl-thin "Clt' of FLgure 4.5 1s ttP3t', and that within
rrP2rr.
.tlGltt is
lfve + 1;
rshlle (live.actlve#nil) and (live.actl-ve# l1ve) do
62
stack of procedure instances Ëo whlch ttlttbelongs (tf trlrr is a coroutlne
or generat.or lnstance, 1t yf elds a ref erence to rrlrr itself ) . The
variables "s1tt and tts2" are local Èo the algorithm definitlon.
s1 €head(tt); s2 ês1i
l-f s'LZ=lô.mast.ef
then susp (- sr
else I whlle sl.master # 12.rnaster do
I + s1 i sl ê sl.master ] i
s2
1f s, = i. then gugp ê So
LL
63
a group whose boss Ls on thaÈ master chaln. Ttre "whilerr loop in the
algorlÈhm follows the master chaln out of I'head(11)" unËll an 1nsÈance
(tt"ltt) is found whose master is the same as that of "L2", and also
records the prevfous lnstance on the master chain in t'srtt as the chain
ls followed. When the two master 1lnks coLnclde, Ëhe two cases above can
be separaEed:
tf. tt"ltt does not refer to tri2rr then these lnstances are dlfferenÈ
members of the same group (their master varlables indicate the same
tnstance), and the subt.ree wlth ""1" as lts root (which contaÍns
ttil,'wiËhin it or associated with lt) becomes suspended; for
example, lf ttP3" in Flgure 4.5 executes t'gg C5t', then Èhe
subtree with t'C4tt as tts roog becomes suspended (s ince
ttsusp (P3, C5
) " has Èhe value
t'C4t') by changing ttC2. acÈlvett f rom
ttc4" to rrc5rr.
,
A degenerate version of the first alternative occurs when "lr" 1s
in fact t'head(il)tt (conslder, for example, the execution of ".tt!tt G5"
wlthln "Prt' in Figure 4.5); ln this case, "susp(11,í2)t'always yields
tti2.master.activetr is changed f rom tti2tt to "ízt' ; 1n oËher
"iz" , and
words, no change ls made to the actlve variables of caterval fnstances.
64
closely textually encloses that of the procedure; thls 1s anoÈher of the
means by whlch a close corresponderrce between the program text and its
behavlour at run-tfme ls ensured: lt will always be clear, from the
program text, to which corouËl-ne or generator such sequence control
operaÈlons app1y, even lf they occur 1n procedures. To allow the
descriptlon of this aspect of ACL' the sequence control model is
augmented by the addition of:
65
appropriaÈe at the time. Another advantage of expllcl-t creatlon of
l-nsÈances 1s that lt allows the members of a group Eo be created in an
order, posslbly varying, speclfled by the programmer; a dlsadvantage of
explicit creaÈion 1s that 1t does noL conÈrlbute to a close
correspondence between statl-c textual structure and the structure of the
executl-ng program, in that the number of members ÈhaÈ a group wÍll have
at run-tirue will vary and hence wLl-l not be clear from the text' as lt
would wíth tnpllclt creaÈlon. In partícular, whether coroutine or
generator ln ACL ts caterval or elementary 1s a dynamic' rather than a
static, property.
Coroutine and generat.or instances are creaÈed in ACL programs uslng
the operatlon:
IC d = { A+create d; A.naster€-encl(current);
A.caller <- susp(currentrA); return A;
encl(current).active êA; enter A )
in r¡hich the master varíable of the created insËance ls set to indicate
the boss of the group to which that l-nstance nolr belongs; thls boss will
be the creatfng lnstance 1f the latter is a coroutfne or generator' or
some other instance if Èhe instance creatlon operaElon ls encountered in
a procedure insÈance. The caller variable of the new instance 1s used to
'record a reference to Èhe subtree (or slngle instance) v¡hlch is Ëo
become suspended v¡hen the tt.nlgt Arr actlon is encountered, transferring
control to the ne\{ instance for lnltlalizatlon processlng; thls
reference allows the lnltial-ízLng instance to behave as a generator and
for execuÈion to carry on wíthln the lnstance actually lssulng the
lns¡ance creatlon operatlon, after the new ínsÈance has conpleted its
lnl-tiallzation phase. NexÈ, the expressLon "IC dt' (again, thls bears no
relatlon to the actual syntax of ACL) evaluat.es to a reference to the
newly-created instance; this ls done before the instance begins lts
initializatlon, to avoid the difficulty descrfbed earller for Simula.
The actlve varlable of the boss of this grouP is then adjusted to
fndicate thaE the new instance 1s the actlve member of the grouP, after
whlch the fnstance 1s entered, and tts Lnl-tlaLlzation phase beglns.
66
and that lt creates a furÈher coroutine lnstance ttC6". The effect 1s to
transform the masËer tree of Tigure 4.5 lnto thaÈ sho¡¿n 1n Flgure 4.8:
"C6" becomes a member of the group of whlchrtCr" is the boss¡ the caller
variable of Èhe new lnsÈance ls set to lndicaEe "C4" (the root of the
subtree suspended when "Prtt executes I'enter C6"), and the actlve
varlable of. "Crtt 1s changed so that l-t lndicaÈes "C6rr.
ct
G c
I 2
G C: c c C
2 4 6 5
G3 G G P
4 5 3
67
Consfder, as an example, that the lnstance 'rC6'r ln Figure 4.8 were
Èo execute a TI operatlon; the effect would be to erase the cailer link
f rom |tC6tt to "C4", and to set the actlve variable of "C2" to lndicaÈe
ttC4tt, thus suspending ttC6" and resumlng the executlon of the caterval
lnstance ttC4tt. The resulÈ of resumÍng this structure 1s that executlon
conElnues wtthin ttP3tt, at the statement after that whlch caused the
creaÈlon of the lnst.ance ttc6" (slnce t'P3tt is the llve lnstance r,¡iËhln
the subtree with root ttC4tt).
1n whlch "ctt must refer to a coroutlne instance such that the transfer
from ttcurrentrr to "ctt conforms to Èhe prlnclple of opaqueness; the above
operation sinply transfers control to the specified coroutlne insËance'
havLng correctly adjusted the relevant active varlable. Ttre complication
fn doing the latter arlses because of the need Èo dlstíngulsh between
three different cases:
a Ëransfer from the boss of a group to one of lts members,
6B
group ¡shose boss Ls on Ëhe chaln of acEive Lnstances whose head is
the maln program itrstance.
The difference between the last two cases ls the difference¡ sâyr
between rrP3lt 1n Flgure 4.5 executl-ng rrCT C4'r (neanfng thaË Èhe boss of
tta4tt'" group should gain control) and iÈ exeeutfng ttCT C5 tt (a simple
transfer of conÈro1 to the instance specified).
69
and the case that the rooE of the sÈructure becoming suspended is a
member of the same group as Èhe target lnstance. After the approprÍ.aEe
actlve varlabl-e has been changed, control is transferred Ëo the t.ârget
LnsÈance.
70
control ls returned by this operatLon ls rrencl(eurrent)"; fts caller
varl-able l-s inËerrogated and then set to "n11", Ln accordance wlth the
scheme described above for preventlng the formatlon of rings of caller
l1nks. The adjustment of actl-ve variables requires Ehe case of returnÍng
to the boss of the generator's group (the ftrst alternatlve ln the test)
to be distlngulshed frorn the case of returnlng to some other member of
fts group (the second alternative).
7L
ACL's I'fR operation 1s sl-mllar to Simula's ttdetacht', and the effect
of the ttmultl-leve1 deÈ.ach'r of CorouÈ1ne PASCAL can be obÈalned by
applytng the CT operaÈ1on to a corouÈlne lnstance further up the master
tree along the chain of active llnks, which results ln the boss at that.
level gaining control and the subt.ree which rüas its actlve member
becomlng suspended. Ttris use of the CT operation produces an effect
sfmllar, but noË ldentlcal, to thaE of a series of MR operations belng
executed by the lnstances on Èhat chaln of active links. Unfortunately'
thls technlque cannot be used l-n the case of generaÈors, but another way
of obtainlng a "multi-level deÈach'r in ACL (which can also be used w1Ëh
coroutines) ls for an MR operation to be executed by a procedure defined
l-n the definLtlon corresponding to Ehe active member of the group Èo
whose boss control should pass.
72
ttcallertt.
73
The sequence control effect of the termlnaË1on of a procedure
lnstance ls the sane as Èhat of the PR operaÈ1on; the effect of a
coroutine or generaÈor lnstance terminaÈlng 1s the same as that of the
l"IR operaÈion (that 1s, control passes to the boss of the appropriaÈe
group). In additfon, the terminaElon of a coroutlne or generator
lnstance causes the corresponding instance varlable to acquire the value
frno_instancett. The appllcation of a CT or GC operaËíon Èo an lnstance
variable with Ëhe value 'rno l-nstance" results in an error (at run-time).
Non-local Jumps ("gototts whose target statemenÈ ls outslde the
subprogram ln whlch the Jurnp sÈatement occurs) are precluded by data
control design declsions to be discussed later, and so transfers of
control between subprogram instances ln an ACL Program can only be
achieved using the seguence control operatLons descrlbed above.
74
4.3 The S ntics of the Data ConÈrol Aspect
4.3.1.1 Introduction
A.s already mentioned ln Chapter 2, the data conËrol features of
programming languages are concerned wÍËh Ehe specificaEion of restric-
tlons over which data structures are accesslble ln varlous Parts of a
program; ln other r,rords, they give a Progranmer conÈrol over where
references to daËa items can and cannot occur in a progran' Such
features may also allow the prograruner to restrlct the conÈexts 1n which
accessf-ble ldentlfíers may appear, thus resÈrictlng the klnd of access
to the corresponding ltem.
Informatlon blnding, deflned by Elson[40] as rrassoctatlng synbollc
references with intended obJects", represents a vlew of daEa control
whtch has enJoyed some popularlty. Various representaElons of
fnformatlon bindÍng have been suggested; one of these ls the binding
diagran of l.legner t 155 L shown 1n Flgure 4. t0 , which gives the
relatlonshlp between names, references, cells and values' The name 1s
the trsymbolic reference'r referred to by Elson, and 1s typically an
ldentlfier; the cell 1s the hardware locaÈions occupied by the value'
and is thus synonymous with a hardware address; the reference ls a
ttsoftware addreSstt: for example, a Polnter to An actiVatlon record,
along with an offset' Data conErol ls concerned ¡'rfth the name-reference
relatLonship and with making changes to such relationships; on the other
hand, reference-cell relatlonshíps are handled entlrely by the storage
nanager. Restrictions on Ehe kin<l of access allowed to a variable amount
to protecting cell-value relationships from change'
name
POSSeSSeS
reference
refers to ce11
conÈains
value
Ftsure 4.10 l^le gner's Binding Diagram
75
The bindlng tfrne ls deflned by Jones and Muchnlckl8l] to be the
polnt in the processing of a program at trhlch each relatlonship ln
Flgure 4.10 becomes flxed, or bourid. No two authors agree on the set of
possl-ble bindlng tlmes; the followlng llst ls proposed by Jones and
Muchnick, and glves some ldea of the wfde range of PotenEial blndlng
tlmes: compilation, loading, beginning of executlon, block entry, and
explicít sLaEenent time.
As already lndlcaÈed, daÈa control facllltles allow Ëhe prograutmer
to restrlct access to data or subprogram items; the reasons for wanting
to restrict access may vary from prograûrmer to progranmer' and from
program to program. One reason for utllizing Ëhe data conÈrol facillties
of a language 1s that lt is then possible to reduce the number of
progran varlables whlch need to be consldered when htriting or attemptlng
to understand a partlcular sectlon of a program. Thl-s is related to
DlJkstra's vlew, expressed fn Chapter 10 of [36], thaÈ the net effect of
a program component can be vfewed as a movement ln the subspace (of the
state space of the progran) spanned by the few variables that are
affected by it. The desÍre to reduce the number of dinensÍons of thls
subspace, 1n order to lmprove the couprehensibllity of the componenË'
and to have the program text give some clear indicaÈl-on of the nature of
thls subspace, leads Dijkstra to introduce an expressive set of daËa
'conÈrol facilltles. However, data control speclficatlons prescribe the
varlables which might posslbly be affected by the program component, but
not those r^rhich are actually affected; thus, the subspace described as a
result of using the daÈa control features of a language (lncluding those
of DiJkstra's proposal) maY, in fact, have more dimensions Èhan the one
originally sought by Dijkstra. This use of data control Èo subdívide the
state space 1s one of Ehe advantages of those programming languages wlth
data control facllities, for, at the other end of the "p."ttrr*r'nthe
lnterface between every two consecuËive lnstructions ln a machfne code
program consists of the state of the entire machine"167l.
76
the scope of each procedure deflniÈlon the lnformatlon requlred to
determlne the course of a computat.lon by thaE procedure'r, and the effect
of hfs proposal ls that itglobal data objects can be proÈected from
unlntended aecesses by a procedure, and that thl-s protect.lon does not
depend on the correcLness of the code of the procedure bodytt'
77
program and data ltens are going Eo be used, and Eo have these
assertions checked. Fisher [44] Puts |t slrnply, by saying that "the
safety of programs ts enhanced by requiring speclficaElon of the
prograümer's intentfr. Clearly this view of data control is related to
the proÈectionlst vlew, in that the programner's intentions, as stated,
can be checked againsÈ his actual behavlour, and thus provide some
degree of protectlon, or securlty. The dffference ls, hov¡ever, that we
wl11 be concerned wlËh how well data conÈrol facilities allorv the
progranmer Lo express the desired daEa control strucÈure (the lntended
paËtern of use of identlfíers) of programs, rather than l¡lth provldlng
data control mechanisms which force the programmer to tlghtly control
access to Èhe attributes of a subprogram unit (by' for example,
enumeratlng all other units whlch may access each of them), when he does
not wish to do so (when he is noÈ sufficlently aware of the intended
pattern of use).
7B
and I,I (wrlte), and the kinds of access are:
Gtven expresslons of the same tyPe (ln Èhe usual sense), the
following |tgreater than or equal to"[80] relationshfps, based on subset
relationshlps, can be enumerated:
RI,{>RO > NA
and hence the followl-ng bindlngs (assignrnents) are the only ones allowed
by the blndlng (assignmenÈ) rule:
(Ì'IA,NA) (Ro,NA) (RW,NA)
(R0,Ro) (RI,¡,R0)
(RtI,RW)
1n l¡hich Èhe noÈatlon tt (old, new) " is used to denote these t'blnding
pairs tr.
79
Probably the most wldely known example of automatic reallocat,l-on of
fnaccesslble storage is the usual irnplementation of A1gol 60
(disregardlng "ortn" variables): the blocks of an A1go1 60 Program,
includlng any procedures whÍch are called, are always entered and left
ln a strictly last-ln-first-out manner, which permlts reallocatlon of
storage to be accomplished by stack technlques. Thfs is only posslble
slnce, Ìvhen an A1gol 60 block ts exfted, all of the local daÈa ltems of
that block become permanently lnaccessible; except for ttowntr varlables,
new variable lnstances w111 be created for those daÈa ltems lf ever Èhat.
block Ls agaln entered, and hence the old varlable lnstances are no
longer requlred. It is worth noting at this point that there are no
expliclt references to block instances 1n Algol 60 and related languages
(such as Pascal), and that lf nultlple instances of blocks exlst, lt is
the most recently creaEed one whlch becomes parÈ of the coriÈexÈ of any
block insEances whlch have access to items of that block. As ¡¿as noted
ln SecËfon 4.1, it, turns out ln practlce that thÍs "latest acEivatlon[
rule, rather than allowing access to variables of oÈher of these
nultiple lnstances, is a vfable one, and that expllcit references to
lnstances are not needed. Explicit references to instances ls one asPect
of certaln languages l-ncorporating coroutlnes which can lead to storage
management schemes whlch are less simple than the sÈack technÍque.
(1) the storage 1s deallocated upon exlt from the block - thls ls
knor¡n as the deletlon strategy, and
BO
poLnters to varlables belonglng to lnstances; the situatlon may arlse ln
such a language where a pofnter variable belonging to the context of an
actlve lnstance polnts to a varlable of an lnstance whlch has been
exl-ted - ff the deletlon strategy has been appll-ed, the sËorage for that
lnstance will have been deallocated. In the case of an attenPt to
dereference the polnter varlable, the run-time sysÈem may detect an
atÈempt to access a location outslde the stack area (the dangllng
reference problem), or the polnter may indtcate a location lnside the
stack, wÍthln a subsequently allocaÈed instance (the imposÈer
environment problern). ImplementaElons of such languages may use the
deletion straËegy, elther to gain the efflclency of a run-tirne stack or
because Èhe hardware offers little choíce (see [116]), and Èhen impose
restrfctions on the use of pointer, Iabel and procedure values Lo
prevent the occurrence of the above problems. These restricÈlons require
the addition of run-tlme checks, the various alternaÈfves for which are
descrlbed, in detall, 1n 124).
All of the discusslons of rrretention versus deletlon'r cited above
recommend. the retentlon sËrategy, sÍnce 1È precludes the danglÍng
reference and lmposter environment problems from ever occurring, and
since 1È can be shown t15l that an i.mplementatÍon of the retentlon
strategy usíng a partial reference count systen fs, for a certain class
óf programs, approximately as time-wlse efflclent as an implementatlon
of the deletion strategy with the appropriaËe run-time checks.
Although ACL does not conEaln features such as procedure variables
or polnËers to varlables 1n instances, the retentlon versus deletion
argument, ls relevant Ln that lt rras decided that coroutlne lnstances
should be retained until they can no longer be enÈered and their
aÈtributes are no longer accesslble - thaÈ ls, a retentlon strategy \{as
adopted. Ttre manner tn which the retenÈlon strategy has been implemented
w111 be discussed later in thls thesis.
81
all, ln that no reference to the varlable can occur thereln. In order to
avold the added complicat.lons of ldeas such as "passfve scope" and
"vlrgintt variables (those not yet inltlallzed), and reJectlng the notion
of fnplicit l-nltlallzatlon for all varlables (as is used, for example,
1n Sinulat33l ) slnce iE nakes "a11 sorÈs of nonsensical Programs
artiflcially into legal ones" [36] , the concePt of an ttundefi-ned"
variable (one that has yeÈ to be lnlttallzed) ls admitted ln ACL and
consideration of initlallzation wíll be omltted from our discussion of
data control. Followíng from thls decÍsion, the relatlonshlp between
data control and sÈorage managenent can be viewed in Èerms of the
following events occurring for each varLable:
(A) openlng of Èhe scope of access for the varlable,
82
Fleure 4.11 A Partlal Ordering on Events
Temporal
Concerned wlth a Variable
(a) (b)
FLgure 4.12 Turo A1 go1 60 Fragments with the Same
83
block lnst.ance 1s acquÍred f rom oEher blocks, and some is ne\t
Èermlnology lntroduced for that block; 1f the new termLnology lnvolves
references Èo variable instances whlch had not previously been
accesslble, then some allocatlon of storage may be requlred. In adoptlng
block structure for ACL, no assumptions are belng made aË this sEage
abouÈ data control between blocks; in particular, the scope rules of
Algol 60 may noÈ necessarlly apply to nested block structure, lf nesting
Ís indeed present.
The possiblllty of multlple insËances of a slngle block deflnltlon
Lmplies the use of actlvation records as an lmplementaÈlon scheme; ln
the general case, these actlvatlon records will contain sequence control
fnformation (either a returD address or a continuatlon polnt) and data
conÈrol Lnformatlon (such as where to ftnd non-local variables, lf
access to non-local varlables is posslble). The contexË (or environment)
of executlon of a block fnstance, eonslsting of Lhose data items which
are accessible in the instance, ls contained l-n an ordered list of
activatlon records; the scope rules of Algol 60, for exampler glve rfse
to a pa-rtlcular choice of whlch activatlon records are to be on the
llst, and to a partlcular orderÍng on Èhem. The ordering speclfies the
order tn whlch the search of a part,icular idenÈlfier 1s to be conducted
at run-time, although 1t may be posslble to conduct thl-s search, 1n
'ánttclpatlon, during conpilatlon.
The maJor advantages of block structure are as follows:
(1) iÈ ls essentlal to the factorizatlon of the state space of a
program lnto subspaces¡ âs described by Dljkstra (see Sectlon
4.3.1.1) , and, as such, leads to the produetlon of betLer
programs t
84
4.3.1.4 Scope Rules
85
1s, accordlng to DtJksÈra, that the composer of an lnner block needs
only to be aware of the global narnes 1n the surroundlng conÈext Èo which
he is actually referringr but thaÈ any other global names should not
restrlct hln ln the freedom of chofce of his own names with local
slgnlflcance only. Barron[9] cites as an advantage of the redeclared
identlfler rule, the fact that lt gives "at1 elegant way of providing
default declarationst'. The first rule, descrlbing the ldea of nested.
scope, has Èhe advanÈage, accordlng Eo Hoare[67]' that lt glves rise to
a ttclose correspondance between the statically vtsible scoPe of a
vartable ln a source program and the dynamlc l-ifetine of iËs storage
r¿hen the program is runrr.
These scope rules have, hor.rever, cone ln for some sharp criÈicisn
Ín recent years, the best known of whlch is probably the paper of I'Iulf
and Shar¿t1661. I^Iulf and Shaw clte the following unsaEisfactory aspects
of A1gol's scope rules:
(1) side-effects,
86
Another widely found crltÍclsm of Algol's scope rules is, l-n fact,
due to a fundarnental property of all totally ímplicit scope rules: that
1È l-s not poss1b1e, merely by examinlng (in lsolatlon) the text of a
block, to know the complete vocabulary of identlflers accessible 1n that
block. This has been found to be unsaElsfactory by a number of authors.
For example, DiJkstrat36l Proposes that a complete descripElon of a
block's possible lnterference with the state space of Ehe surrounding
block (by enumerating at the head of a block all of the ldentifiers
r¿hich Èogether form its 'rtexÈual contextrr) should be given, whích would
ll¡nit the amount of text whích would have to be sÈudled when a global
variable had been lnterfered with ln an lll-understood manner.
KleburËz[83] makes a slmilar suggestlon, but for dlfferent reasons: as
already mentioned in Section 4.3.1.1, he contends that the verlflabflity
of programs can be lmproved by having available in the texÈ of a block'
all of the informat.ion necessary to determine the effect of thaÈ block.
There have been a number of proposals aimed at rnaking Algol's scoPe
rules more expllcit and a detailed comparison of some of these will be
found ln Section 4.3.3.3.
87
names are the same (the funcElon ldentifier). In addiÈ1on to belng more
expllcl-t, these forms of data control dlffer from (static) scoPe rules
in that they are more dynamic lf there are several calls on a
subprogram, wlth dífferenÈ actual parameters, varlous daËa control
relatlonshlps may be posslble between the calling and called blocks'
depending on which call acEually takes place.
BB
There are a number of htays of carryLng out the process of
rrsubsÈltutl-on'r mentloned above, and of lnterpretlng references to formal
parameters ln a subprogram btock: these are the varlous parameter
tr.ansmlsslon mechanlsms (or modes). For example, Jones and Muchnickl81]
dl-stinguish slx such nechanlsms: call by text substitutlon, eall by
name, cal-l by reference, call by.value, call by resulÈ, and call by
value-result. The varieEy of parameter transmission mechanlsms reflects
some of the many uses of subprograms:
89
the case wtth, for example, call by reference and call by value.
(d) Finally, parameter transmlsslon ls a useful daÈa control device
1n a block-structured language with Algol's scope rules (or a
more explLclt varlant thereof), ln that lt allows access to an
item to be extended to a block whl-ch would not have access via
the scope rules. In other words, the superlmpositlon of parameter
passlng on scope rules allor¡s the speclfication of more
speclalized data control structures. A fragment of a Pascal
program, íllustrat.lng this use of parameters, 1s shown in Flgure
4.13; ln thls example, the variable ttactual" is made accessible
1n procedure rrcrr and procedure rrarr (ln the latter, under the
name ttforroaltt), buÈ not. in procedure
ttbtt.
procedure a (var
fornal: T);
begln .. . end { of a };
procedure b;
procedure c
var actual:T;
besin .. . a(actual) end{ofc};
besin .. . end { of b };
Ffeure 4.13 An Example of the Use of Parameters to Construct
Speclalized Data Control Structures
90
procedure and functlon parameters enable the Èransmlssion of the
name of a procedure or function to a subprogram, so that lnvocaÈlon vla
the formal parameter idenLlfÍer may result ín the i-nvocaÈlon of a number
of dLfferent subprograms, depending on the value of Ehe corresponding
actual parameter. The Pascal fragment of Figure 4.L4 lllusÈrates the
dtfference bethteen passing the result of a functí'on invocaÈlon Èo
another subprogram, and passing the name of a function: the flrst
parameter of the procedure rrptr is a value Parameter and hence the
occurrence of trfrr as an actual paraoeter causes a call on the functlon
rrfrr and the value of the result of thls call ls passed to "P", within
whlch thls value is available under the name rrirr. The second parameter
trfrr iS encountered
Of ttptt, hOWeVef , iS A |tfUnCtlOntt pafameter and when
as the corresponding actual Parameter, iÈs name ís transmitted to "P";
whenever rrgtr is referenced wlthln ttPt', its actual value ls treated as
Ëhe name of a functlon, and thus
ttfrr is called'
91
parameÈers) and not copylng (varlable paraueters), enabling him to trade
space agafnst Èlme. An lnterestlng hybrld beÈween value and RO reference
parameters is the "consÈ't Parameter transmisslon mode suggested by
Mltchell and l^Iegbrelt I I 10 ] : Èhe parameter fs passed by value, but the
value of the formal parameter may not be changed in the called instance
- Ëhls mechanism is not entlrely equivalent to RO reference, in Ëerms of
effect, especlally 1n the context of coroutlnes'
One difftculty wlth the procedure and function transmisslon modes
of Pascal 1s that nothlng l-s speclfled about the parameÈer llst of such
a formal parameter, and thus complete compile-time checking ls noÈ
possible (see, for example, the discussion ln t1561). PASQUAL, for
example, demands the speciflcatlon of the number and types of the
parameters of all procedure and funetlon Parameters 1n a formal
parameter list, and hence all lnvocatlons of a formal procedure or
functl-on parameter can be verified for consistency with all
corresponding actual paraneters' durlng compÍlation'
92
the external varlable 'tatr Ís RI{ accessible in procedure rrPrr under two
names ("at' and "btt) and hence the principle of disjolntness is violaÈed;
thls has been overcome fn Figure 4.15(b) by changlng the formal
parameter to tta". Notlce that the more expl1clË forms of scope rules
discussed ln the last subsection obvlate the need for such Èrlcks ' by
allowf-ng the programmer to express the fact that the external variable
should noÈ be lnherited into the nested block 1n thls case. Also, as
discussed with respect to Euclld ín [151], expllcit inherltance enables
fatrly slnple detectlon (by the translator durlng compilatlon, and by
the programmer) of mosË violations of the princlple of dlsjolntness, by
rrextended
ensurlng that the same tdentifl-er does not occur twlce ln the
parameter list", consisÈing of the (RI^I accesstble) actual parameters for
a partlcular call, concatenated to Èhe llst of ldentiflers expllcltly
inherlted (wtth RI{ access). lÏhis does not, for example, detect cases of
an array element being aliased because the indices in two array element
expresslons occurrlng as (Ri,I accessible) actual parameters happen to
have the same value aÈ run-Ëlme - such sl-tuations can only be detected
by a run'time check.l
besin ... p(a) ... end besin ... p(a) ... end
(a) (b)
Fleure 4. 15 Avoldin g VÍolatlons of the Principle of Disjolntness Which
were Due, in part, to Access via Scope Rules
93
substltutlon do not, for example, have the above properËy and hence
thelr use leads Lo programs r¿hlch are more dlfflcult to comPrehend.
94
relatLonshlps, the definltlons of data control features presented in
this thesis wtll be complemented by some examples, and Èhe data control
behaviour of Ehese example program fragments ln execution will be
explicated through the use of pict.orial snapshoÈs of the data control
structure of the executlng programs. the method of contrucLlng these
pictorl-al representaÈlons of data control strucEure, whJ-ch are a
development of those presented by Èhe author ln t1011, will also be
explalned.
Unllke the sequence control model, the data control model 1s not
specl-fic to the task of descrfblng coroutine. facllities, but rather 1s a
model of data control for languages r+hlch exhlbit block structure' as
that term was defined in Section 4.3. I . 3, and for whlch expllclt
declaration of identlfiers (say, aÈ the head of a block) J-s requíred' As
with the sequence control model, the advantage of employlng chls model
in the design of the data control aspecE of ACL l1es in the fact that lt
deals only with Ehe concePts of LnteresÈ in designlng this asPecË'
abstracË1ng a\üay from lrrelevant detail. In the context of data control,
examples of lrrelevant detalls are the Eype and value assoclated wl-th a
varlable identlfier.
For each block lnsEance, a list of all of the identlfl-ers usable
llst'l
.wlthin that block lnstance 1s defined; this 1s called the "knortn
for that block instance. IË ls divlded lnto two parts (etther of which
may be ernpty) : the "RW l1st'r and the 'R 0 llstr'. This dívlsion
corresponds to a distfnctlon bet¡¿een the kinds of contexts in which
known ldentlfiers may occur during Ëhe executlon of that block instance;
the former 1|st contafns ldentlflers corresponding to RI^I accessible
items, and the latter those of RO accessible iÈems. Associated wÍth each
block instance (and hence rvtth each known llst) is a unique ídentifier'
whlch fs asslgned in some language-specifle manner.
For a block lnstance "btt, the knov¡n list, the RW l1st, and the R0
l1st, wtll be denoted KNOI^r\, RWb and ROO, respectively. Lists such as
these are sald to have entries, and these entries ate sald to contaln
names. These names are not necessarily single identlfiers, but may be
expressions consi-stlng of a number of fdentifiers an<l llteral constants;
a primiÈ1ve predicaLe
fdentifter (n)
95
Ls provlded whl-ch evaluates to tttruett if the name t'ntt 1s an identifier,
and to t'falsett otherwise.
Rtr'l list
known
11st
RO list
.which denotes the entry ln Èhe given llst which contaLns the given name;
care must be taken to ensure thaE an expresslon of the above form does,
fn fact, yield a unlque reference to an entry.
Two klnds of known list entries are dlstinguished: deflnlng and
non-deflning. Definlng entries are reserved for the names of ltems whlch
are defined ln the block correspondíng to the known l1sÈ in which Ehe
entry occurs; these ltems rnight be defined by expllcit declaration or
fuop1icitly, as ln the case of Pascal's value parameter (see 1aËer) '
lNotice that a defining entry for a varlable name in an lnstance's known
list implies that the acÈlvation record for that. instance w111 conEain
the storage allocated for that variable.l Non-definlng entries are used
to hold names whlch sirnply "stand fort'items defined 1n other blocks. In
the plctorÍal representatlons of data conErol relationships ' names
contained in defining entries will be preffxed by an asterisk ("*"),
whereas Lhose in non-defining ent.ries will not.
96
The creaÈÍon of list enErles is achetved by the prlmitlve
Lnsert(nrLrk)
whlch creates a nerl entry in the líst 'rL" (at its end), and the name "ntt
fs seÈ lnto thls entry; the kind of entry created is elther definlng or
non-def lning, depending on whether
rrkrr has the value rrDtr or "N",
respect.ively. For example, I'inserË("rR%rD)'r creaÈes a definlng entry in
the RO list of Ëhe lnstance rrbrr and sets the name ttxtt lnto the entry'
t,Rott) from the entry "er" Ëo the entry ""Z", 1f the latter is a definlng
enÈry, or to the enÈry lndicated by the llnk leading out of "u2", if it
ls a non-definlng entry. The existence of a l1nk emanating from any non-
defining enEry is assured because of the use of non-deflnlng entries: to
hold names standing for names defined in other inst.ances - consequently'
they are always ltnked to a deflnlng entry. Thus, 'rlinkrr must. establish
97
a llnk directly to a deflnlng enEry.
ttat' has
For example, conslder a program in whleh a block lnstance
RIù aCCess, under Ehe name
ttytt, to an item called ttxtt defined in a block
lnstance rrbrr (the f ormer siurply sÈanding f or the latEer) ' Now, the
actlon ttflnk(z of KNOI^IN., y of RtrIrr RO)", where 'tztt is contained in a
definlng entry, does not, establish the data control structure of Flgure
tty" itt tta" represents
4.L7 (a), but rather that of Flgure 4. 17 (b) r since
tlztt
a non-defining entry. The relatlonship flnally establtshed betr¿een
ttytt in ttAtt as
in ttctt and ttxtt in rrbrr Was made possible through the use of
an lntermediary, but this lnformatlon is not consídered relevant to the
data control structure of Ëhe program, and is not recorded. (Notlce that
Lt 1s not specified 1n Figure 4'17 r*rhether "ztt 1s RI^I or Ro accessl-ble in
ttctt.
)
b
*¡ *x -ì
I
I
I
I
I
I
I
I
a a
I
I
I
v I I
I
I
I
I
I
I
I
c c I
I
I
*2 __t _J
(a) (b)
Fisure 4.17 Transmj-sslon of Access vla an Intermediary Identífier
98
to fntermedlary ldentifiers (although they w111 not be present ln the
ftnal daËa control structure) must conform to one of the cases of Figure
4. 18.
t-
I
I
t-
I
I
I
I
The f irst t!,Io cases, (a) and (b) , represent the Èransmisslon of
access to an lten whfch fs RI.I accessible l-n the instance shown; Fígure
4.f8(c) represents Èhe case where the item ls RO accesslble 1n the
lnstance. In terms of the discussion of Sectlon 4.3.1, the three cases
correspond to the following binding paÍrs, resPectfvely:
99
whlch evaluates to a reference to the entry lndicated by the l1nk
leadlng out of the entry I'e". IÈ 1s a property of the model that at most
ttet',
one llnk leads ouÈ of an entry; if there 1s no llnk emanating from
then itfollow(e)rr evaluat.es to the argumenÈ tte" iÈself '
The algorlthrnic descrlpÈlons of data control features will have a
slnllar form to those of sequence control descrlpÈlons:
(1) each descriptlon will be delirnited by curly brackets "{"'}",
(2) the acÈions comprislng a single description will be separated
from each other by semicolons ";tt,
100
control descriptlons, fdentifiers conslstlng of a slngle lower case
t'tyP"", and Èhe
letter will be used for these local varÍables; Èhelr
fact. that they are loca1 variables, should be obvious'
4.3.3.1 Introductlon
This sectl-on wtll descrlbe daÈa conÈro1 ln some programmlng
languages whtch do not have coroutlnes, as well as thaË in programming
languages wiEh a coroutlne facillty. The reason for thls is the facÈ
that data control has generally receÍved little aEtenElon in the design
of coroutine facilities in the past and consequenÈly their data conÈrol
aspecË tends to be noE as lnnovatlve as their sequence control aspect.
The lnteresting and innovative ideas ln data control are ofËen to be
found 1n languages wlthout coroutlnes, and these ideas, where relevant,
are dlscussed in tliis sectlon. One programming language wiÈhout
coroutlnes whlch ls di-scussed here ln some conslderable detail 1s
pascal; Èhe major reason for examining Pascal to thls extent is that
data conËrol in ACL o\¡res rnuch Ëo that 1n Pascal, although they also
dlffer J-n signlflcant \^¡aYS.
4.3.3.2 Pascal
101
feaÈures apply to all of these classes of ldentlfler. Labels in Pascal
programs are denot.ed by unsigned lntegers, raÈher than by idenÈiflers,
but the accesstblllty of labels ls also governed by data conErol
feaEures, and hence unslgned integers denoÈing labels will be regarded
as identlflers for the purposes of this discussiorr. Any unsigned
integers appearlng by Èhemselves in representations of known lísts may
be assumed to be those of labels.
Another use for ldentlfiers ln Pascal ls to denoEe the fields of
records, to allow the selection of a particular field of a record
varlable; these ldentifiers wfll not be included in the known lists of
Pascal block instances, as they are noÈ regarded as being part of the
vocabulary of the instance, but rather of that of the record variable
concerned.
ldentlfier rrlrr.
102
known llsts for fnstances of that block; tf roultiple lnstances of the
block occur, or are expeeted, this naüe ls subscripted' eomroencing at.
one.
Block exlt will simply lnvolve the deletfon of the known lfst for
that block lnstance, and of all of the ltnks leading out of it; it Ís a
property of the descrfptlon of data control ln Pascal thaÈ no llnks will
be leading lnto that known llsÈ when Èhe deletfon occurs. This ls
because known llsts (corresponding Èo block insEances) wiJ-l be created
and deleted in a last-in-fírst-ouÈ fashlon and Èransmlsslon of access
prlvilege is always frorn a pre-existing l1st Èo a newly-creaEed one.
103
(b) vA\: a ltst of Ehe formal value parameter names for the block'
(c) VAR6: a list of the formal variable Parameter names for Ehe
block,
(d) PRo$: a l1st of the formal procedure parameter names for the
block, and
(e) FUNC6: a l1st of the forual function parameter names for the
block.
The primltlve
actual (e)
(name) of KNOIIN.
L¡
r04
Èhat Èhe known llst of the currently executlng lnstance w111 always be
boÈtommosE l-n a slngle column of known llsts'
Now, each of the d.aÈa conËrol features of Pascal listed above will
be treated in turn. For the sake of consistency in the varÍous
algorfÈhmlc descript.lons, sÈandard meanings are assumed for the
followlng names:
. ttcalledtt is Èhe name of the lnstance belng entered,
Lo'ca1 Declarations
105
The actlons taken by Èhe evenE descrlbing the data control effect
of local declaratlons are simply to lnsert a deflnlng entry for each of
the locally declared names , in elther the RI^I ltst or the RO ll-st,
dependlng on lts class. Ttris event ls
Value Parameters
106
of Èhe above definltion). Once Èhls entry has been lnserted, 1t must be
connected via an RO link to Èhe actual paraueter entry, to aIlor¿
initlallzatlon of the implicltly defined loca1 varlable. There are'
hor¿ever, t$ro cases r¡hlch require specLal attention (if neither of these
occur, then the formal parameter enEry ls simply linkecl' vfa an R0 link'
to the actual parameter enÈry); Ehese speclal cases are:
the actual parameter to a formal value Parameter
name correspondÍng
ldentffter need not itself be a stngle identifier (1t rnay be any
expresslon of Èhe appropriate type) or 1È may be a standard
ldenÈifier (such as ttfalse", see Flgure 4.31) 1n either case,
there may be no enÈry ln Èhe known list of the calling instance
which contains the act.ual parameter name, and
107
of the effect of block exft (which currenÈly has the sole effecE of
deletlng the. entlre known l1st for the l-nstance whl-ch 1s ternlnating);
deletlng these entries is more dífflcult ln the case of ACL, since lt is
possible for one of these entrles contalnÍng a parameterized name to
have more than one llnk leadlng to lt. In vierp of these disadvanEages'
Èhese entrfes r¿ill noE be deleted, and their occasional presence ln a
known l|sË after their usefulness has ceased, will be tolerated.
108
Drocedure (f I: Tl;f 2zT2;f3: T3);
p
D rocedure q;
consq a2 = .. . i
var al : T1;
begtn .. . p(al ,a2ra1+a2) end; {of q¡
*al *al
*a2 *a2
¡t (a 1+a2)
_t_ ¡tf
I
I
I
*r2
L- *f3
(a) (b)
FÍgure 4.20 Data ConÈrol Structures Occurring durLng the Execution
of the Fragment of Flgure 4.19
Note that the access privilege to Ehe actual parameter entries '
granted by "q" í-s, ln each case, consistent l^¡ith the principle of non-
l-ncreasing privilege; the access privilege to the first actual parameter
corresponds to the binding pair (RI^I,RO) and that to the oÈher actual
parameters correspond to the binding pair (R0'RO). Notice also Ehat' in
this slnple example, the acËual parameter entrles are all deflnlng ones;
if any \dere non-defining enÈrles, then the link from Èhe correspondlng
formal parameter entry would lead Eo a (deflning) entry in a known list
other than that of the calling lnstance.
Varlable ParameÈers
109
described by the event:
110
*¿ *6
(a) (b)
Figure 4.22 Data Control Structures Occurring durlng the ExecuÈlon
of the Fragment of Figure 4.21
111
must be tn the part of the known list of the calling lnstance. Agaln,
RO
the 1lnk established 1s consl-st.ent wl-th the prlnciple of non-lncreasing
privileger the relevant blndlng palr being (RO,RO).
The program fragment of Ffgure 4.23 conÈalns examples of both
procedure and functlon parameters, and Figure 4.24 depicts some aspects
of the daÈa conÈrol structure v¿hlch night be exhiblted by a progran
conËalnlng thls fragment, before and after an insÈance of procedure "q"
ca1ls procedure ttp". Fi-gure 4.24(b) shows Ë\.to non-definlng entries
inserted into the RO ltst of Ehe called instance, whlch contain the
formal parameter names, and are RO linked to thelr respectlve acËual
parameter entrles, in this case located in (the Ro ltst of) the calling
ins tance.
*ap *aÞ
*af I
I
*af -t
I
I
I
I
I
I
I
I
L fp I
ft _)
(a) (b)
Ffgure 4.24 Data Control Structures Occurring durlng the Executlon
of the Fragment of Figure 4.23
LT2
Scope Rules
Fleure 4.25 Tt.e ParElal Orderlng on the Events Comprislng the Data
Control Effect of Block Entry 1n Pascal
113
Any ldentlfiers lnherited vla the scope rules stand for items qrhose
definlng entrles occur ín the kuovrn lists of lnstances oÈher than
ttcalledt'. As with the other cases of 'rsËand-inrr idenÈlfiers discussed
prevlously (variable, procedure and function parameters), a non-deflnlng
entry ls fnserted in the same part (RW or RO) of the known llst of
t'calledtt as the correspondlng entry resldes 1n the known list of
t'deflner", and the ldentlfier by which the ltem is known in ttdefinerrr is
lnserted 1n this neï{ eritry. The two enÈrles are then llnked using a link
of the same kfnd as Ëhe part of the known llsts to which they belong.
The deflnitlon of S contalns two loops: one whlch scaris Èhrough the
RhI l1st of ttdeffnertt and another which scans through lts RO list. Not
all names present ln the RI^I 11st of "definertr, but not in the known list
of 'rcalled", are inherlted - the method used for modelling the return of
functlon values (see later) lncludes the lnsertion of a deflning entry
in the RI4I list of Ëhe function lnsËance, and Ëhe name in this entry
should never be inherited by a textually enclosed block lnsEance. This
l-ntroduced definlng entry, in fact, holds the funcLion ldentifler' and
hence the Èest for r'¡hether to lnherit a name from Rl,trU"fLner includes a
test. for ¡¿hether the name'1s that of a function. (Recall that the
legttírnate enÈry for the function entry will be in the RO llst of the
functlon lnstance, if at all.) In scanning Ehe RO list of ttdefiner",
ánother exception must be remembered: any enËrles which have been
Ínt,ro<luced into this list because t'deflner" has called subprograms wlth
actual value parameters which r+ere noE slruple identlfiers (see earlier
dlscusslon) should noE have Èheir contents inherlted lnto ttcalled".
These entries are excluded from the actlons of the second loop 1n the
definition of S via Èhe test "ldentifier(n)", which will fail in the
case of any name surrounded by parentheses.
(a) paraneters are used to transuit access privilege from the calllng
to Èhe called instance, whereas, 1n the case of the scope rules,
this transmission is from an instance of a textually enclosing
rr4
block to an insÈance of the lnmediaÈely textually enclosed block'
and
label 1; const c = ;
type T = , varv:T;
{of q}
115
P
*l *l
rtg *c
*T
I
*T -l
* ,!q -{-r
rl
ll
ll
lt
tl
l¡
l¡
L *c Ir
¡l
¡l
tl
tl
ll
ll
*l lt
T -Jt
q ____l
(a) (b)
Fieure 4.27 Data Control Structures Occurrlng durlng the Executlon
of the Fragment of Ftgure 4.26
116
constant as an acÈual value parameÈer w111 cause the lncluslon of
tt (true) tt or tt(f alse) tt in a def lning entry ln the calllng
lnstance's knovrn list, because of the deflnitlon of the event V.
functlon f 1: T1
vdr f L;TZ;
begin ... end; {of ff}
f unction f.z(f 2: T2) : Tl ;
begln .. . end; {of. f.2}
117
F = { if class(deflnltlon) =functlon and
follow(deflnlt,ion of RO"alled) = definltlon of ROUuftner then
I lnsert (def lnttlon rRWcall"¿,D) ;
lfnk(def lnitlon of RW."ll.¿, Ì¡hole of KNOhrN"aller, RW) I )
118
Drocedure p;
functlon f:T;
begln end; {of f)
Drocedure q;
begin .. . f ... S!4; {of q¡
begfn .. . q ... end; {of P}
r- *f *f
T
I
I
*q - --r
I
I
I
I
I
I
I
I
I I
I I
I I
I I
I
I
I
L_ f. f I
I
q q
-à
L- r.
q __l
(a) (b)
Ff-sure 4.30 Data Control St.ructures Occurring during the Execution
of the Fragment of Flgure 4.29
A Conplete ExamÞl.e
119
progran p (outpuË);
end; {of f}
procedurq x(var. p l: integer);
begln p1:= f(crue) end; {of x}
L20
*b *b
* Ewo * two -l
*f
*¡¡
*f
*¡¡
ìttt
rl
I
I
I
x l1 I
l¡ I
l¡ I
b I
ttJo -i I J
f - -¡J
x I
(a) (b)
*b *b
*Èwo -1 *Èvo I
--'l
*f -t *f
rt¡¡ -tir rt¡¡ a
I
I
¡l
tl I
x ll x I
rl I
I rl I I
tl b I
¡l __!
tvro -f1 à I
f --|-t f --¡-ì
x -ri I
x I
-
I
It ( I
Èrue
r
I
* ( true) I
I
I
I
I
I
I I
I I
I f I
I
I Í. I
I I I
L *b I L *b I
*f I
I
*f I
tlro -l -J
J
two
f
--r- -1
I
r
x -J x
r
I
* (faIse)
I
I
Í2
I
L *b
*f
Èflo
J
f
x
(c) (d)
Fisure 4.32 Data Control StrucEures 0ccurring durlng the Execution
of the Program of Figure 4.3 I
Slnce the actual paramet.er to Ehe funcElon instance 1s trfalset' in
the second case, that lnsËance ("f2") then termlnaLes, eausing Ehe
deletion of the known l1st labelled ttf¡t'. Next, the oÈher functlon
lnstance termlnates and lts known list ls deleted, followed by Èhat of
the Lnstance trxrr, and finally that of the rnafn program lnstance.
r2l
4.3.3.3 Exp liclt Scope Rule Schemes
L22
Table 4.3 The Characteristlcs of Varlous Statlc Scope Rule Schemes
Algol 60 tfl2l I I I
DUkstra [36 ] I I E
Gannon [48 ] S N E
McGra¡,¡ t105l S s I
I I I
ASPEN t 157 ] I I I
G s E
Euclld IBBJ G I I
I I E
t23
three columns; furthermore, his proposal allows a block which has access
to an l¡em to permÍÈ lt to become accesslble (with certaln klnds of
access) 1n speciflc fnner blocks, and Èo also permtL lE Eo become
accessible (probably with a different kind of aceess) in all- other
blocks known to that whfch already has aceess'
and proposals contain not only some form of uore
Some languages
expliclt scope rules, buË also make use of (fufly) lmpllclt scope rules.
For example, McGrav's descrÍptlon of Èhe data control facllities for a
language conÈalning concurrent processes lncludes a 'rrestrlctf'
sta¡emenL. If an item, accessible wlthln some block, ls mentloned in a
restrlct statement ln that block, then it is made accessible only ln the
fnner blocks named in that staÈement (thls corresponds to the flrsÈ set
of enÈrles ln the table)i if, however, the ftem is not mentioned in any
restrlct staËemerÌts in the block, then its accessLbÍllty 1n lnner blocks
is subjecÈ to a default set of (impllclt) scope rules (the second set of
entrles fn the table). In ASPEN, the normal- Algol 60 scope rules aPply
to procedures (the first set of entries), buÈ tt |s also possible Èo
deflne ttpackegst', which are used to compose data abstractions, and
access wtthln packets, to ltems deflned ln other packets, follows the
scheme described in the second seÈ of entries for ASPEN.
Dfjkstra's proposal).
A number of the proposals for explicit scope rule schemes described
1n Table 4.3 allow various kinds of access to be specified' For example,
ttvar" and "readonlvtt
Euclid, whlch ts based on Pascal, distinguishes
access, and Wilcox descrlbes eight 'fcurrently recognized" kfnds of
access for ASPEN (and the classes of identlfíer to whlch each kfnd is
appllcable) .
L24
Notice that, although Èhe set of data conErol sÈructures
expresslble vla any of Ëhe kinds of more explclt scope rules ls still
rest.rlcË.ed, conslderably rnore such sLrucÈures are possible than wÍth
Algol's scope rules. For example, l.lulf and Shaw's complaint that
ttoverlapping definitions" are noÈ expressible (see Sectlon 4.3.f.4) has
been overcome in all cases: the various data ltens to be shared between
subsets of the set of procedures can be declared globally to all of the
procedures, but then access only allowed in Lhose procedures in which lt
ls required.
In his proposal for more explfclE scoPe ru1es, Kleburtz also
lntroduces 'rnamed cells" to allo¡¿ the data control for a grouP of
fdentffiers to be speclfied eollectively; such a feature would possibly
help to reduce the verboslty of programs written in a language with
expllcit scope rules. In Kleburtz's system, 1t is also posslble to
partitlon such a cell 1nËo smaller ones when it l-s lnherlted into lnner
blocks.
r25
Slmula has thaE of Algol 60 as Lts sÈarÈ1ng point: the nesting of block
deflnltlons (lncludl-ng Lhose of classes) ln a Simula program results ln
the use of A1gol 60's scope rules in the lnterpretation of names. SÍnula
procedures and classes may both have parameters; parameter transmlsslon
to a class lnstance occurs at the time that ttre lnstance is created,
rather than at any other time (such as when a ttresumett or rrcallr' is
executed). The possible parameter transmlsslon modes for a Slnula
procerlure are value (call by value), reference (call by reference) and
narne (call by nane), whereas for classes only the fLrst two of these are
avallable.
Apart from the precedlng data control features, which all follot¿
A1go1 60 reasonably closely, there are two other daÈa control features
in Sirnula whl-ch are quite novel: prefÍxlng with a class identlfler, and
remote accessing of class attrlbutes. Ttre ablllty to prefix a class
definitlon with the ldentlfler of another class allows the constructlon
of hierarchfes of classes, in whtch the atËributes of one class may be
used ln Ëhe definition of anoEher lov¡er down the hierarchy; prefixing a
block (that is, an anon)¡mous block) wÍth a class ldentlfier allows the
concepts deftned fn that class to be used 1n the block. Tkre abllity to
access the aÈt.ributes of a class instance from outslde thaÈ class
(t'remote accesslngtt) 1s provided in Simula via'rremoÈe identlflers'r
'(uslng expressÍons of Èhe form ttl.atr to access the attrlbute ttatt of the
fnstance rrlrt) and "connectlonrr (similar to Pascal's t¡1th statement); 1n
fact, because of the lack of a mechanfsm fn Sfunula for passing
paråueters to an instance after its creatlon, remote accessing 1s very
useful when wrlElng coroutlne programs 1n the language. A dlsadvantage
of Slmulats remote accessfng ls that it encourages wLde lnterfaces
between subprograms and also that it ls noÈ possible to prohibit access
to an attrlbute of a class by other instances outside that class.
PalmetI17I has recommended Ehe additlon of a "hidden'r speclflcation to
Sfmula, to glve a progranmer the abllity to lndicate thaE certaln
attributes of a class are not to be accessible from outslde the body of
that class; a nodifled form of Èhis proposal has been incorporated into
at least one lmplemenËation of SlmulatlTl. A number of other languages
wlth a coroutine faclllty, such as 2.PAK[107] and TELOS[89], have
adopted the remote ldentifier form of remote accessing Ëo enable access
Eo coroutine aEtributes, buÈ none of these has also lncluded a means of
L26
protecting such attrlbutes from unwanLed external access.
L27
ft to be elther t'publle" or ttprivate", and only the f ormer klnd of
identifer can be l-nherited from iÈs deflning block. SL5's other data
control features lnclude the ablllty to transmlt values on the execution
Of ttresumett and trreturnrr StaEements, and the ablltty to uSe remote
accesslng to refer Eo Ehe ldenËlfiers of oEher envlronmenËs (lnstances).
The dynanlc nature of lts data control features, particularly the
dynamlc scope rulesr ls conslstent wlth SL5's dynarnic approach to
aequence control (see Sectlon 4.2.3), and it widens the gap between the
textual struc¡ure of an SL5 program and lÈs structure durlng executfon.
4.3.4.1 Introductlon
The slgnlficance of Èhe groupfng of corouEines and generators
resulting from the progranming methodology described 1n Chapter 2 ls a
data conÈrol sfgnificance: 1t reflects "maximaltr data sharing relation-
shlps among program components. Thls maxlmal sharíng relationship ls the
princlple of opaqueness, also discussed in that chapter: access Ëo an
item ls restricted to Ehose subprogram units comprising the sub-
hierarchy encompassed by the subprogram ln whlch the ften ls defined. It
Ls clear then that data conÈrol plays an important role in the
prograuming methodology descrlbed in Chapter 2, and that 1t ls important
that the data control structures Benerated as a result of applylng the
methodology should be accurately expressible tn ACL'
T28
The data control features of ACL will, of course, be descrlbed
usfng the dat,a control model, wíÈh the asslstance of l¡hich they \ùere
designed. Not surprislngly, these descrlptlons r¡111 be slmilar in many
respects Èo those of Èhe daÈa control feat.ures of Pascal (see Section
4.3.3.2). Identiflers are used 1n ACL to refer to all classes of ltems
to which they refer 1n Paseal, and they are also used to refer to (the
defLnltlons of) coroutlnes, generators and generator functlons (the last
of whLch l-s a kind of subprogram unit to be explained shortly); as in
the descriptlon of Pascal, labels are regarded as idenÈffiers. The
prlmÍtive
class (n)
actual (e)
r29
The asslgnment of names to known llsts ln the descrfption of data
control ln ACL {s stmllar to Ehat used 1n Èhe description of Pascal: the
deflnl-tlon ldentiffer of the subprogram to whose instance t,he known 11st
corresponds 1s used, and subscripÈs are used to distlngulsh between
nultfple instances of the same deffnltlon, where urultiple instances
occu¡o In the ptctorial representatlons of the data control structure of
ACL programs, the bottommost known ll-st can be assumed to be that of the
currently executlng instance, unless another ls explicitly tndlcaËed.
Onceagaln, the following names wlll have standard meanings in the
data conËrol descriptlons:
. rrcalledtt is Èhe name of the insÈance belng entered,
. trcallertt is the lnstance whose acÈlon caused Èhe entry of "calledtt
(through the former executlng PC, IC, CT or GC)'
An explicLt seope rule scheme hras chosen for ÂCL; thls declsion was
made slnce such schemes allor¿ the descriptlon of the maximal data
sharlng relationships of Èhe princíple of opaqueness, whlle allowing the
expression of more complex data sharing arrangements within the
resÈrlctions of this princlple (such as those described for the solution
of the Telegrams Problem presented 1n SecÈiot 2.4). The scope rules of
ACL are statlc ones, because of the design goal of a close
correspondence between static textual structure and dynamic run-time
structure for ACL programs.
As illustrated by the discussÍon of Section 4.3.3.3' there ls
conslderable varlety ln the expllc1t scope rule schemes which have been
proposed to date, and in the cholces available to Ehe deslgn of such a
scheme. Examinatlon of prograns wrltten uslng the varlous scherres shows
r30
that those r¿lth a hlgh level of expressiveness also tend to be verbose,
whereas those r¡hlch are succinct (such as A1gol 60's lmpllclt scope
rules) do not allow Ëhe expresslon of a sufflciently wlde range of data
control structures. Uslng the classlflcatlon system ernployed fn the
comparfsons of Sectlon 4.3.3.3, the compromise between succfnctness and
expressiveness adopted for ACL can.be descrlbed as:
131
every block, and they have their standard meanlngs 1n all blocks in
which Èhey are noË deffned to have some other meanlng; standard
ldentifiers may not be expllcitly lnherited inÈo a block. As with the
description of data conÈrol in Pascal, known lÍsts in the description of
ACL programs do not. contain standard identlfters unless they are defined
to have other than thelr standard meanlng, or are required as actual
parameters. One parEicular need for lnherltlng varlable ldentlflers
through a number of levels in programs vrritten in languages r¿lthout a
coroutlne facillty (such as Pascal) is obvÍaÈed Ín ACL: it is not
necessary Èo use global. variables Ëo communlcat.e between different
l-nstances of the same procedure or functlon, since t.he subprogram can be
wrLtten as a generator or generator functlon in ACL, and the varlable
declared loca1 to lt (with the aÈtendanE increase ln security) . In fact '
experience with ACL has shown that siËuations do not often arlse ln
which 1t is necessary to ínherit an identifler through block levels ln
whlch access to the ltem 1s not really required.
(a) LOCA\: a list of the names declared locally to the block; thl-s
ltst includes the identlfiers of procedu::es and functions
declared 1n the block, and those enumeraÈed in any scalar tyPes
declared 1n type or variable declarations in Èhe block,
r32
If rrbrt is a maln progrâm lnstance, Lhen boÈh INHROS and INHRI'I6 are
empËy for a legal A,CL program, since there is no block outer to an ACL
main program block.
prlvate(e)
insert(nrL,k1rk2)
which creates a nert entry 1n the list "L", the entry belng deflning or
non-deflnlng depending on whethet ttkltt has the value rrDrr or
rrNrtr and
133
Local Declaratlons
The result of this evenÈ ' as wl-th the corresponding one ln the
descripÈion of Pascal, is the lnsertlon of a definlng entry (in this
134
case, tt fs also necessary to speclfy whether lt Ls prfvate or
herltable) ln etther the RW l1st or the RO l1st of the lnstance belng
entered, depending on the class of the identlfler, for each of the
ldentiflers ln LOCALcalled.
and consequently that Èhe vartable does not have the same type. ln the
tr.fo blocks (that ís, its tyPe is dynamf c) . Programs exhibiting thls
behaviour tend to be dlfftcult Eo understand, and can contaln confusíng
errors (for example, the statement "v:= b" in the lnner block of Figure
4.33 would result l-n a type confllct error).
135
_!ype. T = (arbrc);
g v:T;
procedure p;
var b:integer;
begln ... end;
begln end
Thls anomaly has been avolded in ACL by dernanding that the scalar
identifiers (inpllcltly) fnherfted lnto a block be distinct from all
other Ídentifiers known i-n the block; consequently, 1f a scalar tyPe 1s
known in a block, each of lts idenÈiflers wfll also be known and will
have the meaning of denoÈl-ng one of rhe values of Èhat type'
136
reâson.) As thls ldentifler ls RO lnherlted into an ACL functlon or
generator functLon lnstancer âr lmpllcltly-deflned local varLable to
hold the value to be returned by this instance (simllar to that in the
descrlptlon of {ata control 1n Pascal) has 1ts name, whlch ls the same
as Èhe deflnltl ,, l-dent.iflerr inserted into the RI^I ltst of the lnstance.
This enËry |s nog llnked to any lnstance aÈ this stage (see later).
r37
treat,ed as Èhose of constants ln both A.CL and Pascal). Notlce also that
the irnplicltly-defined vartable local to a function or generator
functfon lnstance, whfch holds the value to be returned, 1s prlvate to
that. l-nstance.
138
only rrTrr is prlvate. (In the pfctorlal representatfons of known llsts, a
private name l-s pref txed by a sharp ttlltt' lf an enÈry 1s definlng and
prlvate, the pref |x tr//*'r ls used. ) Two varlables, "vl" and "v2" " are
rrTrr) and their
also declared loca1 to'router" (they are both of tyPe
ldentifiers are placed ln definlng entrles ln the RW 11st of the
l-nstance; both of these variables are declared to be herltable. As shown
ln Ftgure 4.34(b), anoËher lnstance (t'inner") ls then entered; in facE'
this is an lnstance of a block whlch is declared lmrnediately ¡,¡ithin that
corresponding to "outertt. Thls nerìI instance lnherits the ldentffiers
"Vlt' and "v2", the ftrst wlth RW access and the second with RO access;
iË ls possible for "outertt to lnherit these identiflers because the
deftnitlon of "innertt is textually nested immediately within that of
t,outertt, and because rrvlrr and ttvztt are heriÈable. Since the inherited
vartables are of type "T", thls causes t.he Lnpliclt Ínherttance of the
ttinnertr has R0
scalar i-dentifiers ttatt, rrbrr and ttc". Notice thaE because
access to the variable "v2", the latEer identlfter is 1n the RO Ilst of
"inner" and its entry 1s llnked v1a an RO link to the (defining) entry
containing "v2" ln Èhe RI^l l1st of "ouËertt, thus establishing a data
control strucËure which cannot be constructed in Pascal' The known list
of "ínner" also contalns a definlng entry for a local' prlvaÈe constant
named rtxrr.
ou ter ou ter
*vl *vl
*v2 *v2
T
l¡xT lrxT
*¿ *¿ I
*b
*g
*b
*g
ir -l
-r- 1-
lt I
lt I
rt I
lnner ll I
vl tt I
L_ rl I
v2 rl
Jl
I
I
a
I
b _ _.1
I
c J
/l*x
(a) (b)
Fleure 4.34 DaEa Control Structures lllustrating the Effect of Local
and Inheriting Declarations ln ACL
139
4.3.4.3 Parameters
140
Section 4.3.1.5 and whlch can norù be restaEed in terns which cover both
lnitiallzatlon and contlnuation parameters: for these transmission
modes, l-nterpretatlon of actual Parameter expressions occurs at the Èime
thaÈ conrol is transferred to Ehe instance concerned, and that
lnterpretatlon reualns current unÈil exí-t from the lnstance (whieh may
be a permanenE or temPorarY exlt).
(c) IVALb: the formal value initlalizatlon parameter names for the
l-nstance ttbtt,
(d) CSEENb: the formal seen conÈinuatlon ParameÈer names for the
Ínstance ttbtt,
141
(e) CMODIFb: the formal rnodlflable contlnuaËlon parameter names for
the lnstance ttbtt, and
(f) CVALb: Ëhe formal value conËlnuatlon ParameEer names for the
fnstance trbtr.
L42
The types of formal parameter ldentifiers are lnterpreted in the
context of the block inmedlately outer to Èhe deflnitlon of the
subprogram concerned; hence' if the tyPe of a formal Parameter involves
scalar fdentlfiers, these ldentiflers w111 be presenÈ in the RO list of
the instance "deff¡errr, from r,¡hich they are (lmpllcitly) inherited into
the RO l1st of t'called". Ttre test on the class of the actual parameter
name ls necessary because an actual seen parameter which ís a variable
may reside ln elther the RW llst or the RO llst of "callert', and it ls
not, possible to sftnply use "llnk(..., a of KNowNcaller' ...)rrslnce thls
leads to an arnbigulty ln the case that "callertt ls an instance of a
ttatt, ín which
functlon or generator functlon r^rhose definition name 1s
case there will be entrles contalning the Ttame "a" in both the RI'I and RO
lists of "callert'. Slnce standard constant Ídentifiers and expliclt
constants are allowed as actual seen Parametersr lt may be necessary to
insert a parenthesized version of Ëhe actual Parameter exPression ln the
RO lLst of the calling l-nstance (as was also the case 1n the descriptlon
of Pascal's Value parameters) because the actual parameter'
parenthesized or not, is not already Present ln that list; notlce thaÈ
the entry lnto whlch such a parenËheslzed actual par:ameÈer is placed 1s
a deflning, private one.
r43
whlch differs from the event IS only ln that fornal parameter
identifiers (and any associated scalar ldentlflers) are only inserted
1nÈo Èhe RO list of "called" if they are not already present' In fact,
all of the identlfiers for conti-nuatLon seen parameters are added to the
RO list of ttcalledtt on the first occasion that such parameters are
rrcalledil
transmitted (that is, the first tlne that the main sectlon,of
is entered), and no such additions are made on any subsequent occasions
that the maln sectlon ls enÈered. Note that the "llnk'r prf-mitive has the
side-effect of eraslng âny exfstlng llnks out of an entry when
establishing a link from that enÈry.
One (noÈ uncommon) sltuation in which seen lnitlalization
parameters prove particularly useful is thaÈ in whlch two lnstances of
the same coroutine definition are required Eo pass control back and
forth between each other. The way in which the necessary mutual
references between Èhe two lnstances must be established in some
languages wlth coroutlnes is lllustrated by Èhe Simula fragment of
Flgure 4.35, which is taken from 176). The formal parameter of the class
trArr is bound to the value "none" rùhen the flrst lnstance of thls class
ref (A) xr yi
class A(other); ref (A) other;
begln ... detachi ... resume(other); ' " end;
r44
t'othertt. Now, an Ínstance of Èhe coroutl-ne (labelled'[lt'in Flgure
4.36) is creaEed by an lnstance of Ehe deflning block (call thls
lnstancettoutertr), passing the varlablettytt as the actual seen parameLer
rrxrr (remember
and sÈoring the newly-created instance ln the varlable
that lnstance variables contain instances, rather than references to
then); Ehe result is shown ln Figure 4.36(a). Control then returns Ëo
,toutertt whlch creates another lns tance of the coroutine (ttA2" ) , this
rrAlrr) as the
tine passing the varlable rrxrr (which contalns the lnstance
rryrr
actual seen parameter, and sËoring this new lnstance 1n the Varlable
(to whlch the lnstance "Altt has access); the sl-tuation after these
actions have taken place is depf-cted fn Flgure 4.36(b), in which the
lnstance trAZ', ls currently execut.i-ng. Thus ' ACL allows the mutual
references to be established Ín two clear sÈePsr 3s opposed to the
clumsy method which must be ernployed fn Slmula'
outer outer
x x --- - - -1
v v
Al A2
Al
(a) (b)
Figure 4.36 Data ConÈrol Structures Illustratlng the Establishuent of
Mutual References between Instances in ACL
r4s
prLvl-1ege.
for formal parameter names (and assoclated scalar ldenÈlflers) need only
be lnserted in the known l1st of the instance
ttcalled" on the occaslon
of the first entry to lts main sectlon. Since this 1s the only
dlfference, the deflnítlon of CM is not presented here'
L46
Value Parameters
as f ollol¡s:
L47
a subordlnate seË of procedure instances. If a forrnal Parameter of one
oL iÈs component instances was last bound to one of Ëhe formal
contínuation parameters of the subprogram, then subsequent transfer of
conÈrol Eo the subprogran wlll lead to Èhe rebl-nding of the continuatlon
parameters, and this ralses the questl-on of whether the parameter of the
componenË inst.ance should also be rebound to the ner¿ acÈual parameter
value. In fact, thls questlon can be extended to cover cases where Ëhe
formal parameter of the component lnstance was also last bound to the
formal parameter of some other component, and so on. Because of the
translent si.gnifLcance of inÈermediary ldentifiers ln the data control
model (see the discussion of Section 4.3.2), and since value parameters
are asslgned their values only at the tlme of parameter transmisslon, 1t
1s clear that such "secondary rebindingtt does not occur with any
transmlsslon mode in ACL. Flgure 4.37 depicts a sttuatlon of the kind
descrlbed above; ln Flgure 4.37 (a) ' rrBrr is a suspended coroutlne
Ínstance r.¡ith a subordinate procedure lnst.ance "Ptt. On the last occasion
ttrt' of the instance
that con¡rol $ras transferred to rrB'r, the varlable
"Att Í¡as supplied as the actual parameter corresPonding to the formal
ttPtt was called,
nodiflable parameter 'tx"; when Èhe procedure instance
rrxrr of ttBtt\n¡as given as the actual parameter corresPondlng Ëo the formal
148
A A
rt¡ It¡
*g *g
x x
P P
(a) (b)
Fieure 4.37 Data ConÈro1 Structures Illustrating the Reblnding of
Contlnuatlon Parameters in ACL
r49
4.3.4.4 Returnl V alues from Subproqrams
FV = { if (class(deflnltion) =functÍon)
or (class(definition) = genfunc) then
link(definitlon of RW"rll.¿, whole of KNOWN"aller, RI{) }
and this evenE ls regarded as occurring at block entry for procedures
and functions, and at main seCtlon entry for coroutines, generators and
generat.or functLons, although lt has a null effect 1n the case of
150
fnstances of procedures, coroutines and generators' FurÈhermore, 1t is
nor.f necessâry to sÈate a partlal ordering wtth respect to the events
occurrlng on entry to a procedure or funcÈlon lnsÈance: Èhe effect of
the event IRO musÈ be computed before thaE of the event FV, or else an
aËtempÈ may be made to es¡ablish a link from a non-existent enÈry
(that
of the pseudovariable for a funcÈion lnstance, which is inserted r'rhen
the functlon identlfier ls inherited). Such a Partial ordering 1s not
necessary in the case of generator functlons ' sifice the pseudovariable
entry ls lnserted as part of initlaltzaËlon sectfon entry and the
establishment. of the link occurs at maln sectLon entry.
Before discussing Èhe actual return of a value to the polnt of
call, lt must first be stated that a generator function instance in ACL
may only execuËe an MR operatfon when Èhe masÈer and caller varlables of
Èhe instance colnclde; slurllarly, the terminatlon of a generafor
functlon instance can only occur \rithout. error in the same
circumstances. this res¡rlction, whlch clearly iurplies that MR and GR
operaÈions in generat.or function lnstances have the SAme sequence
control effect, means that 'rreturning fromtt a generator functlon is
always accompanled by the transmission of a va1ue, maklng the operatlon
of this kind of subprogram easier to understand' This restriction does
not appear to be too severe, ln the llght of the llkely uses of
'generator functions.
151
Table 4.4 A Surnmary of the Data control Events for ACL
For a given block lnstance "btt, the names conÈalned ín all of the
lists assoclaEed with that instance by vlrtue of declarations in the
program texÈ (that is, lists such as LoCA\' INHRI'íb and ISEE\) musL be
dlfferent from each other; furthernorer ânY scalar ldentlfiers
lmplicltly inherlted lnto a block lnstance musE also be different from
those in the above llsÈs. Because of this restrlctlon' and Ehe absence
of lnplicit scope rules of the klnd found in Pascal, the only Partial
orderlng deflned on Èhe events comprlsing block entry in ACL is the one
gl-ven previously: í.n the case of block entry f or procedures and
.functions, the effect. of the evenE FV must be evaluated after thaE of
the event IRO for that block entry. This slmple partlal ordering 1s 1n
contrast to Ëhat necessary fn the descrlptlon of data control 1n Pascal
(recall Figure 4.25).
rrinstance referencett,
As part of the rrfnstancett, aS opPosed to
approach adopted in ACL (see sectlon 4.1), the copying or "clonlng"[89J
of lnsEances is prohibited. Consequently, value parameters must not be
lnstance varlables, nor may they contain lnstance variable's within their
structure; either of these klnds of value parameters r^rould lead to Ehe
copylng of Èhe instance(s) contained in the actual Parameter.
trextent" of
sínilar to the concepË of "reach" ln Algol 68 tl50l, Che
a maln program, coroutlne, generator or generator function is deflned to
consist of all of the Program text enclosed by its deflnlEion down !o,
but not includingr anY nesÈed coroutí-ne' generator or genelator function
definlllons; notlce thaÈ a given exlerrt may lnclude an arbltrary number
152
of levels of procedure and funcElon deflnlÈlons' In an attempt Èo
lncrease the correspondence between the sÈructure of the text of an ACL
program and the structure of l-ts master tree at run-ÈÍ-me, instance
varlables (and sÈructures containlng lnstance varlables) may not be Rf'I
inherited lnt.o a coroutine, generaÈor or generator functlon definitíon'
nor may they be passed as RI,I reference parameters. From the deffnltlon
of the IC operation (see Sectlon 4.2.4), and Èhe facÈ that Rtr{ access to
the appropriate lnsÈance varlable l-s necessary for instance creatlon' ft
l-s clear that the declarat.ion of an instance varlable always occurs
wlthln the extent of the deflnitl0n of the boss of any instance stored
ln the lnstance variable.
Furthermore, slnce RO access to a definitíon ldentlfier is required
both for the declaratlon of lnsÈance variables (recall that these
varlables are strongly typed) and instance creatlon, and slnee these
identlfiers cannoÈ be passed as Parameters ' all instances of a
corout.lne, generaÈor or generator function musE be created textually
wlthln Ëhe block ln ¡vhich the subprogram deflnítlon aPPears; this also
conEributes to a close corresPondence between Èhe statlc and dynamic
structure of an ACL ProgrâD.
However, the occurrence of lnstance varíables ln dynanic variables
between statlc and dynamlc
.can lead to a very poor correspondence
program structures; thts poor correspondence arises because of Èhe
possibllity of multlple references to dynamic varlables, and the fact
thaÈ RO access to a pointer is sufflcient to a1low the value of the
dynamic variable vrhtch it lndicates to be changed, among other reasons'
The possibility of lnstancê varlables ln dynamic varlables !'tas included
fn ACL because of its usefulness in certain sítuaÈions, and ln spite of
the fact that its use can lead to programs which are dtfflcult to
undersËand.
t53
tdenÈifler lnto a coroutine, generaÈor or generator funcElon, and
(a) (b)
Flsure 4.38 An Ex arnple of a GeneraËor not Exhlblting
Procedure-like Behaviour
L54
In ACL, procedure-llke behavlour 1s enforced ln the case of
generator functlons; this is necessary slnce calls on generator functlon
Ínstances occur, ln general, aS part Of expreSSlon eValuatlon and so lt
ls essenElal to ensure that control returns to Ehe caller as a result of
the generator function instance executlng a GR or MR operation' or as a
result of it termfnating, and thereby contributl-ng a value to the
expression evaluatlon in progress in the caller. Thls behaviour is
enforced using a run-Ëlme checking scheme descrlbed in Chapter 6 ' The
possibllity of using cornpile-tlme enforcement of data control
restrlctions to prevent situaÈions such as that in Flgure 4'38 arising
was Ínvesttgated but, partlcularly in view of the actions whlch may be
taken by procedures and functlons, it was found that this approach 1ed
both to a very complex se! of restrictlons and a large amount of
elaborate compile-time checking. In contrast, the run-time scheme
adopted is both sirnple and efficlent, adding l1tt1e to the run-Elme
overhead of an ACL Program.
r55
any coroutine, generat.or or generator function definttion whose
conÈlnuatlon parameter llsÈ has a parElcular
ttform" (see Chapter 5)'
This klnd of weakly Èyped instance Parameter ls useful in the
parameterization of some subprograms whlch Ëransfer conÈrol to
prevlously created lnstances of more than one deflnÍtl-on.
FÍnally, note thaE violations of the prLnciple of opaqueness can
occur in an ACL program through the use of pararneters. Although the
princfple 1s not. enforced in general, the resErlctions stated when
in¿roducing the sequence conËrol operaËions of ACL make lt clear that lt
Ls enforced in the case of Eransfers of control: a direcËed transfer of
control is only legal 1f the princlple of opaquenesg would allow the
Lnstance varlable containlng the target lnstance to be accessible to the
lnstance executlng the transfer of control.
156
CHAPTER 5
5.1 Introductlon
A full descrlptlon of Ehe syntax of ACL 1s gl-ven ln Appendix A'
usLng the same kind of 'rsynEax diagrams" used to descrlbe Èhe syntax of
PascalintT5l.AsinthelaËterdescripÈionrsomeofthenon-terminal
syrnbols used in syntax dlagrams in Appendix A are noE defined by another
syntax dlagram, but raÈher consíst of a generic non-Èermlnal symbol
whtch 1s defined by a syntax diagram, qualified by a context-senslËive
"remarkt'. For example, the symbol "definlElon identifíertt,
which aPpears
in the syntax dlagrams for "type" and "sequence conÈrol operaEionrr'
refers to an itidentlfier'r which has been introduced as the name of a
coroutlne' generator or generator functlon, by appearlng after the
tt or ttgattlttt"tt in a trdeflnÍng
reserved word ttcorollE:llllqtt, ttggat"E
'declaratlontt.
5.2 Declarations
There are three kinds of declaration in ACL: defining declaratlons'
lnherlting declaraÈlons and forward declaratlons, only the first and
last of whlch occur in any form ln Pascal; furthermore' ACL is unlike
Pascal in that lt is not necessary that the declaration of all labels
precede that of all constanEs, nor Èhat the laEter must precede the
declaration of variables, and so orlr within a particular seE of
declaraÈions. The followlng ordering is, however, lmposed on the
declaratlons appearing at the head of a partlcular block: an identifier
may not be used in a declaration untÍ| it has ltself been declared'
Thls
157
via a single scan, and also means that the language lends itself to one-
pass compilation.
158
constructors may be apPlLed to it, maklng Possible structures such as
arrays of lnstance varlables and lnsÈance varlâbles as flelds in record
structures.
Another difference beÈIüeen the syntax of ACL and that of Pascal is
the fact that "nil" Ís a predef lned constant l-n ACL, as 1t l-s ln at
least a number of the lmplementations of Pascal, whereas the syntax
dlagrams for Pascal glven fn [75] show it as a reserved word, and one of
the alternatives for an ttunsl-gned constantrr'
I59
ttforward" or they
and body are replaced by the predeflned identlfl-er
occur irnplicltly (1n the case of some pointer Eype definitions see
160
5.r(a), the ACL verslon, the type "persontt is announced by belng
declared forward; lt is then used 1n the deflnltton of the type "llnk",
ttperson". In the Pascal
and then the latter ls used ln the deflnltlon of
versLon, glven ln Flgure 5.1(b), the type 'rl1fik" is firstly deflned in
terms of the unknol¡n ldentlfier rrpersonrr; Pascal makes an excePËlon of
the rule that tdentlfiers must be declared before they are used, for the
case of a type l-dentlfier used tn a polnter tyPe deflnition, regarding
Ít as havlng been lmpllcitly declared forward, 1f that is necessary' The
second line of Figure 5.1(b) then contalns the definltlon of the ËyPe
ttperson,t in terms of "linktt. Sone dlfflcultles which arise in Pascal ,
partlyasaconsequenceofitslnpll-cltforr.rardtypeldentlfiers'will
be dlscussed shortlY.
forward privaÈe tYPe Person;
(a)
(b)
161
forward herltable procedure Q(value T);
orocedure y:T);
P(
and
L62
The flrst of these Lnterpretations ls used ln sone lmplementatlons
of pascal and is adopted by l4latt in his descrlptl-on of Èhe context-
sensltlve syntax of Pascaltr54l, although (as polnted out by welsh et
al. ) thls interpreEatlon ts precluded by the descriptlon of Pascal ln
Èhe ttReport" in [75], since 1t would mean that an ldentifler can have
more than one "associatl-on'r within the procedure or function ln which it
1s declared (deflned). Ttre second 1nÈerpretatlon 1s not easily
implement.ed in a one-pass eonpller, and does not seem to have found
favour among the lmplementors of Pascal'
procedure P orocedure P;
type A = g!ry. [f ..10] of B;
B = ...i
begin end;
(a) (b)
163
Becauseoftheexplicltscoperuleschemeusedinthelanguage'
none of these questlons of lnterPretation, and the consequent
dlffl-culties, arlse ln ACL: before a type ldentlfi-er may be used in any
type deflnltíon, it rnust ltself be either defined, inherlted or forward
declared at that block level, thus maklng lts assoclation perfectly
clear.
5.3 Parameters
L6¿+
of Èhe subprogram's paraneter list (such as would be glven ln a
forward declaratlon for the subprogram) and' 1n the case of a
functlon, the type of the value returned; thls ktnd of parameter
type 1s used when a procedure or function ldentifl-er 1s being
transmitted and can only occur legally in conJunctlon with the RO
reference transmission ruoder and
5,4 Statements
165
functlon Ldentlfier and an argument |lst ln an expression (at the
ttfactort' level). Procedure and functlon return (the PR operaÈ1on) occur
lnpllcltly on control reachlng the flnal "endt' of Ehe appropriate
subprograrn def lnLtlon.
166
rrhaLtr' ls a parameterless procedure whlch stoPS program executlon
and results in a post-mortem dump being printed'
L67
comPfle-tlme.
168
CHAPTER 6
6. 1 Overvle¡¿
code.
169
instances 1n a program which l-nvolves no coroutlnes, and the
latter program can be expected to execute almost as effj.clently
as lt would with a stack-based lmplementation'
During the lmplemenEaEion of AcL, another advantage of Pascal'H'
emerged: 1Ë ls a useful staglng polnt from which to begin an implemen-
tatlon of a language, based on Pascal, contalning coroutines' This is
because Pascal'I1', lts lntermediate code (called "II-code") and Íts
hypothetical computer (the "heap computer") represent a form of the
activation record roodel wlth local stacks and conÈlnuatlon polnts, and
whlch is sufficient for the description of the run-tlme behavlour of
both Pascal and ACL. Although tt is true that the intermedÍate code 1n
the processor for ACL (which will be referred to as "C-code") contains
extra instructl-ons and its activaEion records have additional fields (to
ttactlVett), the basic model is
lmplement concepts such aS ttmâstert' and
the same as that which underlles Pascal'H"
The processor for ACL was developed fromPascal'II' using the nethod
of sÈepwise ref inemen¡ [159J , whlch I¡Ias also used as the basis of the
development of Pascal'P' by Arnroann [5 ] . The developmenE of the A'CL
lnterpreter was a process of nodlfying the Pascal'H' lnterpreter'
whereas the ACL compiler r¿as built frou scraÈch, and Èhen relevant parts
of the Pascal'H' compiler were borrowed as needed; developing the ACL
comptler by altering Ëhe Pascal'H' compller was noÈ feaslble since some
of the features of ACL made lt deslrable for the ACL compiler to have a
structure qutte different from Ehat of the Pascal'H' compiler'
The development steps used, whfch differ ln slgnlficanË ways from
those used by Ammann, are shol¡n in Flgure 6.1. The flrst sÈep was the
lntroductlon of Ëhe addltional syrnbols required by AcL and the
productÍon of a new symbol scanner. In the second step' the compiler was
altered to process the declarations of ACL and a revised syrnbol table
organizaÈlon rùas introduced Èo coPe w1Èh ACL's expllclt scoPe rules;
thls step also lncluded the analysis of the forrnal parameter llsts of
subprograms. Then, in the thtrd sEeP ' the compiler r'tas altered to
anaLyze the bodíes of blocks and the varlous staEements of ACL; this
st.ep also lnvolved the fntroductlon of objecÈ code generatlon 1n the
compiler, and the differences between C-code and H-code lead to a number
of changes ln the interpreter, as did the need to revise some aspects of
r70
the run-tlme structures. Thls thlrd step also lncluded the nodiflcaElon
of the compller so that the necesstty for a name to have the I{ access
rlght fn certaln sltuatlons 1s enforced, and the lncluslon ln the
lnterpreter of Ehe run-t.ime checklng necessary to ensure procedure-llke
behavlour for genera¡or funcElon lnstances. The result of the thlrd step
was a processor for ACL which correctly comptled and executed ACL
programs, but whlch dld not lnclude any storage management;
consequently, st.orage no longer needed during the executfon of a Program
\tas not avallable for re-use. The fourth and final steP ln Èhe
development of an ACL Processor was thaÈ of the introducÈion of a
reference count storage managenent scheme; durlng thls step' changes
were made to boÈh the compiler and the interPreter'
s¡rmbols
declarations
stat.ements
storage management
L1tt1e more will be said about the first step i-n the development
process; one aspect of it whlch 1s of lnterest, however, is the facÈ
rr' It
that the symbol scanner in the Pascal'P' compi-ler treaÈs ' as a
co1on. Thfs expedfency \,{as presuroably adopted because 1n sltuations such
as frl ..2't, iÈ is only af Èer the second perlod has been consumed thât lt
rrl" rather
l-s clear that the scanner should return the lnteger constanË
Èhan a real constanE (such as tt1.O"); however, the Pascal'P' scanner
L7L
alrrays assuues on entry Èhat tt llas only one character ahead after
returning the previous syrnbol, and hence, before returnlng the integer
constant, the rr. . rr Ís converted to rr'
rr. Thls mearis Ehat the internal
rt..rr ln Pascal's syntax dlagrams |s
represenEatlon |n Pascal'P' of the
the same as thaE for ": "; that 1s, these Èlto symbols are not
dlstinguished. The symbol scanner 1n the AcL compller acts as a
rrI''2": ft
generator in the case of encounterLng a sequence such as
returns Ehe fnÈeger constant, but remembers the sÍtuation 1n which that
synbol was found and hence the fact that lt is two characters ahead of
the last symbol. Thus, on the next occasion that the scanner fs called'
it behaves ln a different manner to usual, reÈurnlng the symbol
corresponding to 't..r' buÈ not advancing Èhe input streaxo'
6 .2 DeclaraÈÍ-ons
t72
I'a"' An l-dentl-fler search in
aboVe that for rrbrr, whlch 1s above thaE for
the Pascal'H' compller Ínvolves examlnlng each of the ldentifier trees
on DISPLAY, startlng at lts top, stopPing the search lf the idenÈlfler
sought has been found or the botËorn of DISPLAY reached; the bottommost
ltem on DISPLAY ls always a tree contaínlng the predeflned ldentiflers
of the language. In this way, the implicit scope rules of Pascal are
correctly lmplemented, and predefined identlflers are treated as Lf'
declared in a block surroundlng the entire program'
L73
tyÞe ctp = lldentifler;
alpha = EEgq arraY tl..8l of char;
accesskind = (readonly,readwrlte) ;
namekÍnd = (inherited,deflned) ;
ldentlf l-er = -packeg record
name: alPha; 111nk, rlink: ctP;
rlghts: accesskind; contParan: boolean;
case nkind: narnekind of
fnherlted: (defn: ctP);
deflned: (forwdecl, privaËe: boolean; )
' end;
L74
present ln the knor¿n llst imnedlately below Lhe current one on DISPLAY,
and 1ts nod.e in that known list must be either inherlted, or defining
and herÍtable; also, the access rlghts at thls lnner block level must be
greater than or equal to those requlred by the inheriting declaratlon
being processed. Finally, the deflnlng node co which a llnk is
established as a result of this Ínheritlng declaration (which may or may
noË be tn the penultimate known l1st of DISPLAY) must represent an
ldentifler of the class speclfied in the lnherlting declaratlon and may
not be forward declared (but not yet defined) '
After an ldentifier search has been successfully completed in the
ACL cornpller, access rights information 1s always ava1lable in the node
returned by the search; however, if the iclentifler is an lnherited one,
it ls necessary to follow Èhe I'defn" pointer 1n this node to obÈain any
other information about it. In this respect, the ACL compller ls quite
different from the Pascal'H' compiler (and the Pascal'P' compller)' ln
which an identtfler search always returns a node sÍm1lar to a defining
node 1n the former.
6.3 Statements
The third step 1n the development of a processor for ACL was the
-first whlch involved the lnterpreÈer for c-code, sfmulatíng
the
operatlon of a hypothetical "coroutine compuÈer"' The structure of
st.orage wlthín this lnt.erpreter ís much Èhe same as that in the
Pascal'H'interpreter, which is descrlbed in detall fn [104]: there fs a
serles of tables holding those user Program constants whích cannoE fit
fnto lnstructlon fields (such as large integers, real numbers and sets) '
an array which contains Èhe assembled c-code lnstructlons, and an array
representing the heap area. There are also a number of reglsters 1n the
ACL lnterpreter, all buL the last of r,rhich are also present 1n
Pascal'H':
ttPC", the program counter, an index lnto the C-code array, gfvíng
the next instrucLion to be executed,
rrMAIN", indícaEing the (base of) the mafn program actívatlon record
wtthin the heap,
t'FP", the free l1st polnter, polnting to the flrst obJect on the
L75
free storage list wlthln the heaP,
ilAp,,, lndicatlng the currenEly executlng acÈlvatlon record (that
isr ln Ëhe notatlon of chapter 4, the actlvatlon record for
ttcurrenLtt),
of
"SP", the stack pointer, whlch gives the top of the local stack
the currently executing activatlon record,
whlch ls used to hold a re-ference t.o an acÈivaËion record
ilNTI¡JApil,
tthead(current)tr.
indlcates the activat.ion record for
lhereglstersMAIN'AP,NEWAPandDYNallreferËoobject's
allocated on the heap, such objects being called "heap objects'r' Three
L76
lnnediately followlng the RC ¡¿ord 1n both kinds of actlvation record
(Flgures 6.2(b) and 6.2(c)) hold Lhe same informatlon:
ttFVt', the functlon value field' holdfng the current value of the
pseudovariable If. this actlvaÈlon record 1s that of a functlon or
generator functlon instance, otherwlse it ls noE used,
ttSLtt, the statíc llnk, which lndicaÈes the activaElon record of the
approprlate instance of the block immediately outer to this one in
the program text'
trCALLERtr, finplementlng the caller l|nk 1n the sequence control
descriptions
'
rrLSPrt, pointing to the Èop of the local sËack wlthin this
activatlon record, ancl
local stack
+
(a) (b) (c)
Fleure 6.2 The Layouts of the Varl-ous Kinds of Heap Object
L77
lrttr' a sluilar sequence of
1n the LsP fleld of the targeË l-nst.ance
actlons fs followed with resPect to the PC regLster and the CP flelds of
the currently executlng lnstance and the instance "trr.
The resÈ of a heap object of the second kind (that ls, a procedure
or functlon actlvatlon record) consists of a sectlon for Parameter
values, followed by a section whlch holds Èhe values of l'ocal variables
and certain oËher quantitles (for example, the upPer bounds of for
loops), and concludes wl-th the local sËack for thls activation record'
Thls sequence of sections also occurs aË the end of heap objects which
are the actlvaÈion records of coroutines, generators ' generator
functlons or maln Programs, but in these cases an additlonal four fields
lntervene:
. TTMASTER", represenÈing the master variable 1n the sequence control
descriPtions '
178
definitlons are virtually transllËeratlons of those developed for the
sequence conËrol primitlves of the same names' and the implemerrt-aLion
of
lndivfdual sequence control operatlons \¡las derived in a more less
mechanLcal way from the appropriaÈe sequence conÈrol descrl-ptlons'
The
ease \^riËh which Èhls could be done noÈ only expedited this step ln the
process of frnplemenÈ1ng ACL, but also meant Èhat the implementation is
more ltkely to be conslstent wíÈh the language defl-nltfon' one polnt
regarding the translatlon of sequence control descripElons for use fn
the ÍmplementaÈfon rvhich requires clarificaÈfon 1s that the prfunÍtive
,,encl,, in these descriptions ls lmplemented by lncludlng ln the
approprlate c-code ínstructlon generated by Èhe compiler, the difference
between the (textual) level of Èhe subprogram in whlch the operatlon
occurs and that of the nearest texEually enclosing coroutlne, generator'
generator function or main program defÍnitton; the interpreter then
ttencl(current) " by
finds the actívation record intended by, sây,
following the speclfled number of static links, beglnnlng at the
currently executlng acÈlvation record'
Innediately prlor to any transfer of control rtlth ìùhl-ch parameter
transmlsslon may be associated, Èhe NEWAP register conLains a reference
Ëo the target lnstance, as Ls also the case in Pascal'H' (where such
transfers of control occur only as a re-sult of procedure and function
calls). Thls allowed the scheme used in Pascal'I1' for the transmission
of actual parameter values to also be used in the ACL processor: the
cornpller sirnply generates C-code insÈructions whlch sLore Èhe calculated
values in locations w1Èhin the activation record indicated by NEWAP' at
the offsets corresponding to the appropriate formal parameters' A mlnor
dlfflculty, slmllar to one encountered when wrltlng Pascal'H" occurs if
the evaluation of an actual Parameter expression lnvolves a functfon or
generator funcEion call: the value currently stored in the NEWAP
register, indicatlng the target. actlvation record ln the transfer of
control r¿fth whtch the parameter evaluation is assoclated, will be
destroyed as a result of the call. The solutlon ls to push Ëhe value of
the NEI,IAP reglster onÈo the local stack of the lnstance exectrting the
orlginal transfer of conËro1, before executlng the function or generator
funcÈ1on call, and to restore the NEWAP reglster from that stack on
reEurn. Thts latter resÈoraÈion is complicated by the fact thaÊ a
funcEion oL- generator function inst.ance returns its value by pushing 1E
L79
onto lts caller's local sËack, whlch ls the same stack as the one on
whlch NEI{Ap 1s saved; thus¡ the C-code Ínstruction restoring NEI{AP rnust
lnÈerchange Ëhe Ël¡o values on toP of the sÈack before using the (ner^r)
top one to set the value of the NEWAP regisÈer, leaving the value
returned by the functlon or generator function on top of the stack'
As stated 1n Chapter explicÍt constants
4, constant ldenÈlfiers and
are pernitËed as actual seen Parameters; however, unlike variables,
these constanEs normally have no run-tl-ne existance and therefore they
occupy no locations in the heap to whlch references may be passed as an
acËual parameter value. Rather than treatÍng actual seen parameters
whlch are constants as 'T.O valuett parameters (with Ëhe attendant
compllcaÈions when a single formal seen parameter may have either a
constanË or a varlable as an actual Parameter) or allocatlng storage for
all constants , both named and expllcit, at run-tfme, f t Ittas decided
instead to allocate locaEions 1n the ttlocal datarr part of Èhe calling
actlvatlon record for any constants used as actual seen Parameters' The
appropriate value is set ln each locaÈlon and then a reference Ëo this
Iocatlon ls passed as the actual parameter, as it would Lf the actual
PArameter srere a variable.
Another part of the third steP in the development of an ACL
.processor was the enforcement,
by the compfler, of Èhe requirement that
the l^I access rlght is necessary lf a name is to aPpear 1n certain
conÈexts; specifically, an RI'¡ accesslble variable 1s requtred in the
following sltuations:
. an actual parameter correspondíng to a formal modifiable (RlI
Since the syntax diagram for "argument listrr includes the syrubol
ttexpressiontt as an alternative for an actual parameterr some comments
will no\¡r be made on how the klnd of access Ëhat a block has to an
180
expresslon ls computed from Èhe access that lt has Èo the components of
the expresslon. If an expression consists sirnply of a slngle ldentlfier,
then the kind of access applylng Èo the expression is the same as that
applylng to Èhe identifier; lf, hor¿ever, âû expresslon conËains any
r+rr operator or a redundant
operators or parentheses, even a prefixing
set of parenËheses, then RO access applies. As fat as variables are
concerned, a block has the same klnd of access to the compon'ents of a
structured varlable as lt has to the variable ldentifier' For example'
ttall]
if "a" is the ldenElfler of an RW accessible variable, then 'b" is
also RI^I accessible, but " (a) " and "a [1] .b+3" are RO accesslble'
Dereferenclng a pointer varfable, whether 1È is RI^I or RO accessible'
always leads to Rl^l access to Ehe dynamic variable and its componenÈs;
for exaurple, lf |tprr denotes an RO accessible pointer variable, then
t'p1.ctt is RI.l accessible.
181
allocaÈed; the above scheme also lncludes t!ùo less obvious
optlmizatlons:
. lt ls unnecessary Eo check the lock fleld of an activation record
belng entered as a result of a procedure or function return'
because of the r.tay 1n whl-ch a proeedure or functlon lnstance fs
subordlnaÈe to lts dynarnlcally enclosing coroutlne' generator,
generaÈor functfon or main Program instance, and
rtgrr cannoË
A call on A genera¡or or generaÈor functlon lnStance
rrgrr
cause a locked instance Ëo recommence execution: the lnstance
must have been called earller, and slnce Èhe generator function
f-nstance that it then called has not. yeE returned, it is clear thaÈ
Èhe caller varlable of rrgrr is st1ll in use (since 'rg'r has not had
the opportunlty Eo reEurn Èo its caller) and so the subsequenE call
on ttgt'will not be permitted by the deflnltion of the GC operatlon'
182
speed of executlon, which 1s probably sufflciently slow to make tt
unsuitable for any "production'r use. sl-m1larly, the storage management
scheme adopted for this lmplemenEation ls a general one, and 1s easlly
adapted to changes 1n the language; however, lt ls perhaps also Èrue
that thls generallty ls at the expense of some gains in efflciency r^rhich
would have been possible if more of the present form of resEricElons in
the language rirere Èaken lnto account. Some couunents are made in Ehe next
chapter regarding avenues which rolght be explored in an effort to
lmprove the storage manageuent; some of these avenues lnvolve imposing
further restrictlons at the language leve1'
r83
and expensive garbage collectlons may become necessary' Another
advantage of a refereo.ce count scheme 1s the way 1n which it spreads the
sËorage manageüent overhead over the entlre executÍon of a Program' as
opposed to the \ray that a garbage collector generally requires large
amounts of processor tlme every now and agaÍn, causlng sf-gnlfleant
dlfferences fn the execuÈ1on Èfmes of seemingly slmllar programs'
184
ftno_instancett. This lnitLaLLzatLon ls an essentlal part of the reference
count storage management scheme.
The inclusion of overlay locatlons 1n the seeondary decrementing
process would be possible Èhrough the Lntroductfon of a tag field
checkl-ng scheme, such as Èhat described by Flscher and LeBlancl'4z1 , to
ensure thaÈ the tag field value 1s always consisËenE r.¡lth the varl-ant
belng used. Changlng the tag fleld value would then lnvolve the
inftlalizatlon of any pointer or insÈance varlable fields 1n the variant
whlch has Just become current; the secondary reference counÈ
decrementing t¿ould also become more tedlous, since |t would then be
necessary Èo tesC tag field values to deËermine the current structure of
a record variable with respect to pointer and lnstance variables (and
the necessary informatlon to compute this structure ¡¿ou1d need to be
passed to the interpreter). For Ehese reasons, and others' lt ¡rlas
declded noÈ to introduce tag fleld checking into this lmplementation of
Ä,CL; the sole consequence of not includlng overlay locatíons ln the
secondary decrementing process is that SoItre heap objects are not
deal-located when Ëhey otherr.¡ise rnlght be. The lack of tag fteld checking
ttnetí" fn ACL
1s also the reason ÈhaÈ, unlike lts Pascal counterpart,
does not take tag field values as parameters; l-n the absence of such
checkingr it ls not possible to guaranÈee thaE tag fteld values other
'than those specified in the call to ttner¡tt will not be used, such use
possibly causing locaElons out.side Èhe dynamlc variable to be accessed'
185
whlch was descrlbed earller, and whlch ls depicted in Flgure 6.3 1n the
manner:
lock count length descrpt,r descrnum
The 'rdescrpÈr" fleld in the object's RC word points to the D-list' and
the rrdescrnum" fteld gives the number of enÈries in the D-list' The only
other ftelds tn the RC word which have not yet been explalned are
ttcounttt which holds the reference count for thls heap object¡ and
ttlength" whlch conÈalris the length of Èhis object. The values of Èhe
lock fields of the heap objeet and its D-l1st are not shown 1n Flgure
6.3; also omltted are Èhe reference count for the heap obJect, and the
values of ttdescrptr" and "descrnumt' for the D-lisË. None of these values
are relevanL Èo this dlscussion. The reference counÈ of a D-l1sÈ object
is always one, since the only reference to it is in Ëhe heap objecE with
rshích 1t 1s associated.
7
I
3 I 4
2 ?
4 I
5 I
186
no further use.
187
pol-nter flelds, much the same as that used ln the cons|ruclion of D-
llsts; Èo remain consfstent v¡ith actions taken elsewhere, referenee
coun¡ decrementlng and incrementlng is a¡tempted in the case of overlay
locatlons.
188
1s also returned to Ln the next chapÈer'
189
made to nodify these algorlthms to better suit the sltuatlon 1n ACL,
although soue co¡¡¡ments are uade l-n the nexÈ chapEer on how thls urlght be
approached.
190
CHAPTER 7
191
trsemantlcs
assumptl-ons) about the semantLcs of those other aspects' The
before synÈax'r dl-sctplLne also helps to avold arbitrary or uncortsclous
design decislons.
L92
of the work descrlbed in thls thesis) always lncompleËe. In order to
produce the descrlptlons of ChapÈer 4r lt $Ias sometlmes necessary Èo
resort to experlmentaÈion wlÈh, or examlnation of, a partlcular
lmplementatlon of the language concerned, where such an lmplementation
was available; for example, experluentation wlth Pascal lrnplernentaEions
was necessary to complete the descrlption of thaE language's data
control features. In fact, discoverlng the semantics of the data control
features of a language hras generally more difficult. than finding out Èhe
semantícs of the other Ewo aspects; data control features are often only
ment,loned in passing in language descript.ions, or thelr descripEfon is
scattered wldely through the documentatfon available on Èhe language'
Even formal descriptions of programming languages, such as the axiomaËic
descrlptfon of Pascalt69l, have very llttle to say abouË data control
matÈers.
The design goals set out ln Chapter 3 are met by the program-ing
language ACL. The coroutíne mechanism of the language follows closely
the notlon of groups presenÈed in ChapÈer 2, particularly htlth regard to
the manner in whlch such groups become suspended. This, along with the
language's powerful data control features, means that it provides good
support for the progranmlng methodology described in Èhat chapter'
r93
same form as they are found ln Pascal; it nighÈ prove worthwhile to
replace these by a hlgh-level data structuring facillty whlch permlts
the construetlon of llsts and t.rees (such as the feaEures suggested by
I{oare[68] or JohnsonITTJ), ln terms of the extent to whlch thls mlght
conÈribute to a reduct.lon ln the gap between static and dynamlc program
structure.
ACLallows a wide range of Program structures Ëo be described' The
coroutine facl1lty lncreases slgniflcanÈly the number of sequence
conüroI structures rqhich can be descrlbed, and the data control features
lnclucled ln the language mean Èhat a large number of data control
s tructures can be expressed. The expresslve
poI\ter of ACL's daÈa
structuring facilltíes 1s roughly the same as that of the correspondlng
feaËures ln Pascal, which is high. In splte of the wlde range of
strucEures expresslble ln the language, the nurober of language features
present 1n ACL, but not ln Pascal, ls small'
Efflcient enforcement of all of the restrlctlons of ACL is possible
and has been lncluded in the lmplemenEatlon descrlbed in chapter 6'
Conclusions regarding Èhe implementatlon and possibilities fox lts
improvemenE, glven the Same language definition, are presented in
the
nexÈ section of this chapter. It rnight, however, be worEh consldering
,further language resËrictlons to allov¡ lmprovements ln
Storage
ThepresentformofAcLreflectsadesiretogaínsomelnltlal
experience with the ideas behind iE, by using a language with few
resÈrictions. It is likely that thls experíence will point to areas in
whlch the language can be further restricted wíthouÈ lnterfering unduly
with the way 1t is used to solve problems. This, for example, 1s the
reason for not enforclng Èhe princtple of oPaqueness in the case of all-
194
l-tems in an ACL Program.
19s
such measuremenLs would also provide lnformatlon r¿hich nlghr lead
to lmprovemenEs 1n the algorithms used to manage the free storage
list
1n the ACL processor, which are currently ldentlcal üo those ln
Pascal'H'. Hanson[60] has suggested a variant of the boundary-tag
algorithm[85], which ls said to be suited to the Ûânagement of coroutine
actlvation records; Ehe slmpliflcations that llanson has made to the
orlglnal boundary-tag algorithm are based on tqro assumptlons' Ihese
assumptlons are t.hat the d1sÈributton of actlvation record sizes l-s
semi-fndependenL of the parÈlcular execuÈlon of a given Program'
and
that the staÈlc and dynamic distrlbuÈlons of actlvatfon record sizes are
much the same. IÈ ís not clear that these assumPtions would be true
for
a naJoríty of ACL programs, and so this particular algorithro \^7as
rejected for use in the ACL processor. The lnvestigatlon of the validity
of these assumpEions, and hence of ühe suitability of Hanson's
algorithm, provides further motivatlon for carrylng ouË storage usage
measurenents for ACL Programs'
TherearetlüolmprovemenËswhichcouldbemadetothe
implementatlon of ACL described in chapter 6; the first of Ehese is the
fnÈroduction of tag fleld checking, which Ís possible by adaptlng Èhe
approach described by Fischer and LeBlanc 142). Tlhe second improvement ls
the extenslon of the reference countíng scheme to Ínclude consideration
'of references due to reference paramet.ers and with statements ' and a
method to achieve this (which 1s based partly on a suggestlon of
LeBlanctgol), will now be outlined. In thls method, a heap object's
reference count. is incremented on each occasLon that an actual reference
parameter (whether seen or uodifiable) which refers to some field within
the obJect 1s transmltted; sfmilarily, this reference count ls
increment.ed if a varfable 1n a with llst 1s found to have an address
located r¿lthin the heap object. At soue later tiue, when Ehe reference
to the partlcular fteld of the heap object is Êo longer currenL, the
reference counL must be decremented agaln. The polnt at which thls
should be done depends on the language feature involved:
. for with statements, it fs at the end of the statement concerned,
L96
performedonthenexÈtransferofcontrolwhlchlnvolvesthe
replacement of the parameter values vrith nehr ones'
L97
suspended. sl-rnllarly, soffa and Llndstrorn[138] have rnodlfled the model
of tr{ang and Dahl to cover some extenslons Èo tbe features descrlbed ln
t152l i they then use the modlfied model to prove that
cerEaln r'law and
orderrr conditlons are observed by the extensLons, and to provlde a proof
of correctness for a sÈrategy for Ehe deletlon of activation records' It
ls this last applicatlon of l^Iang and Dahl's model whlch nlght be
partlcularly useful wlth regard to ACL' not so much to Plove the
correctness of the straEegy eurrently used to decide when heap obJects
are no longer needed, but rather to gulde its optlmizatlon and the
development of language restrlctlons whlch would allow simpler and
more
efftcient straregles.
In summary, thls thesls has provlded a framer^rork for prograrnming
wlth corouËlnes, through the descriptlon of both a programmlng
methodology which produces hterarchically structured corouËine programs
and a programmlng language which supports thls methodology and whích
has
198
APPENDIX A
ldentifier letÈer
letËer
dlgtt
unslgned integer
dfglt
unslgned nr¡nber
unelgned constant
consÈanÈ ldentlfler
unslgned number
characÈer
constant
constanC ldenÈlfler
unslgned nunber
character
sluple type
type ldentlfler
ldentlfler
r99
tyPe
sl.rnple
type ldenÈlfier
FILE
ffeld llsÈ
varlable
varlable ldentff
fleld ldentlf
200
a ta Èement
unsiB¡ìed lnÈeger
non-insEance varlable
sÈaÈement END
expresslon constanÈ
exPùesgion sÈaÈenent
GOTO lnt
201
arßumenÈ 1lst
lnsÈance varl-able
exPre6aLon
facÈor
constanE
non-1nsÈance varlable
functlon ldentifler
lls t
fnstance vatlab
expression
NOT facEor
expresslon expresslon
terû
factor
factor
slmple expre8slon
tern
te¡r
202
expresslon
sfnple expresslon
Blnple expresslon
argument lfst
RXSIJUE
RETURN
ParaEeter foro I
SEEN
( T,ÍODIF ameter
VALUE
psrameler fontr 2
ParaneÈer forn 3
203
påraneter ÈyPe
Èype fdenÈffier
PROCEDURE
parameter form I
COROUTINE
paraneÈer forn 2
GENERATOR
pararDeter lLst
SEEN
PRIVATE
IIÍODIF ldenÈlfier
HERITABLE
VALUE
paraneter tyPe
CONST
TYPE
VAR
PROCEDUR,E
1d enÈ1f ler
FUNCTION
COROUTINE
GENER.ATOR
GENT'IJNC
204
block I
declara tlon
defl-nlng declaration
PRIVATE
HERITABLE
LABEL
unslgned lnteger
ldentlfler Èype
VAR
COROUTINE
ident if1er INIT parameter list
block 2
205
block 2
declaraElon
HERITASLE
TYPE ldenclfier
COROUTINE
identifier paraneter form 3
declaratlon
deflnlng declaraÈlon
forward declaraEion
lnherltlng declaratfon
program
206
APPENDIX B
EC calls the instance LB to fill the buffer for the flrst tlme and then
ttcountt" keeplng
lnlttalizes rtchrr and a local lnteger variable, called
t.rack of Èhe element of the buffer last extracted' The inítialization
number of
actions of the instance pT consist of setting a counter on Ehe
telegrams processed to lts lnltial value of zexo' and creaÈing an
the current
instance of the generat.or funcEion whlch 1s used to compare
word viÈh the word "STOP", thls insEance being stored in the
lnstance
207
proqran Te legraos(1nPut' output) ¡
208
nodlf var ch;
read fron "buffer"
ÞrivåÈe fgE counr 3 lnÈeger; { lndex of lasÈ character
)
lnitbeÊ,ln { ExEractcharacÈer }
call LB;
count:'l; ch:- bufferlcount] { assume buffslze Is aÈ leaat one }
lnltend;
begln
¡rhile true do
becln
count:- counÈ + l;
Lf count>buffsize Èþeq
-Þt"L SeU LB; cãäE:= t end¡
ch:- bufferlcountl ; relurn
end
end f-Ext.racÈCharacter ) ;
orlvaÈe var EC : instánce of ExÈractcharacter;
1 : fnteger;
const blank - "¡
loltbeqln ( Extractl'lord )
-EC:- create ExtracÈCheracÈer
fnf tend;
begln
whlle true do
beg,in
---I- O; wirlle ch=blank do call EC;
rrhlle (1<naxçord) and (chlblank) do .
-Þrgla {:= I + l; rcrd'charstll ¡- ch; call EC end;
word.length:= l; reÈurn
end
9¡!( ExtractWord ) ¡
herlÈåble vsr EW3 lnstance of ExtracÈ!'lord;
Drlvate q.enerator ProcessTelegran;
prlvate const llnelength = 120;
sordcounÈ' n' l: lnteger;
vtr t.l."otntr
anYoversLze: boolean;
seen functlon ZZZZfot¡d; var ElJ, wotd;
herltable Êenfune SToPfound : boolean;
grr!-Sgg!¡¡q STOPf ound; var word;. -
õtf""r" t.t sÈoPword : arrav ft"4l of char;
found: boolean; f: lnteger;
(
lnlrbegln STOPfound )
stÇT"tatf l:= 'S'; stopÍtord[2] t= '-"1'.i
stopword[3] z' 'O'i sÈoPe'ord[4]:= 'P'
lnltend;
besln
uhlle Erue do
begln
r¡lth nord do
lf length-4
then
begln
found:= true; l:= l;
r¡hlle found and (t 3 4) do
begln
f rund¡ = chars If I =stoPword [1] ;
1:- I + I
end;
STOPfound:= found
end
else
STOPfound:- false;
return
end
end(STOPfound)i
prfvate var SF: lnstance of STOPfound;
lnftbeqfn ( ProcessTelegram )
-fãI""ountt- 0; SF:- create SToPfound
lnltend;
209
begln
:{LLþ true do
begln
telecount:o telecount + l; wrlteln('0');
r¡rlteln('0 Èelegram no' ' ,telecount:2); 0; n:= 0;
nrfÈeln; falee; wordcounÈ:-
"nyo.,".ãl"tt=
nhLle not ZZZZfottd do
begln
-Jf--(o+"o.d. I eng Èh+ I ) >l lneleng Eh
then begln çrlEeln; n:= word'len8Èh end
else n:= n * r¡ord'lengÈh + l¡
wrtte( " ) ¡
for J:=l tà word'length do vrlte(v¡ord'charslJl );
wotd.length>I2 Èhen anyoverslze:= true;
-flf not SF then wordcounc:= wordcounE * l;
gelL Elr
end;
wrlteln; wrlteln('0 number of chargeable words:"wordcount:5);
;!! anyoversize then wrlÈeln('+' ,' 't36" (aÈ least one of"
' whlch ls overlengrh)');
reÈurn
end
end TTrocessTelegran ) ;
F1 re 8.1 (continued)
I Telegrams
LoadBuffer LB
2
ET
3 ExtracÈTe legrams
EI.I
4 ExtracÈllords
ProcessTe legram PT
5
EC
6 ExtractCharacter
2L0
varlable trsF'r; the subprogram whlch compares the currefit word wl-th
"ZZZZtt ls a function, Ehe reason for thls difference
being that SF holds
Èhe word'rSTOPrr 1n a local varl-able, whereas the function uses a
procedural represenEaÈion of the word
uZZZZtt
' After all of these
lnftlallzatlons are complete, the structure of the program is as shown
rrTrr is used to
l-n the master tree deplcted ln Flgure 8.2, ln v¡hlch
denote the maln program lnstance; at this polnt, control resídes 1n the
main program fnstance. Apart from the instance sF, whlch plays a minor
role and !¡as omftted from the discusslon of chapter 2 fox this reason'
thls master Èree closely mimlcs Ehe program structure shown ln Figure
2.1, and which l-s also evident from Ehe strucEure of the program text in
Figure 8.1.
I
2 3
4 5
Fiqure 8.2 The structure of the Program in Flgure 8.1 after the
Inltiallzation of lts Instances
Following these fnitiallzations, the insÈance ET is cal1ed by the
maln program which then calls EI^I to extract the flrst word from Ehe
buffer. This latter instance builds up words by sklpplng over blanks and
then storing non-blank characters ln the "\ùord" data structure (up to a
maximum of fifty characters) untll another blank character 1s
encountered; at Èhis point, Ehe length of the word is also recorded
r¡ithin lts representaËion. hlhenever the lnstance EI'l requlres another
character, lt calls on the instance EC whose task fs accomplished in a
relatlvely sinple manner: iÈ extracÈs characlers from the buffer until
the end of the buffer is reached, at whtch polnt iÈ calls LB Ëo have the
buffer refllled. Ì.Ihile this refilllng ls going on, the subtree with root
ET ls suspended, and the caller llnk of LB lndlcates ET; the successful
2LL
refllltng of the buffer results ln LB returnlng control to ET and
executlon contlnues wlthl-n EC. If the lnput flle is already at lts end
when LB Ls called, an error has occurred and LB firstly sets the
rrexiÈrr tO retUfn Contfol to
Vafiable "errortt tO "tfuett and then uSeS An
t'error" to
the maln prograu; the maln program uses the value of
dlfferentlate a normal reËurn of conÈrol via ET from this abnormal
return vla LB. This situation amply d'emonstrates the advantage of
dlstlngulshing between the GR (t'reEurn") and MR ("exltrr) operatlons'
Having regafned control from EI^I, the ínstance ET Èhen alternaÈely
calls pT and Ei^I unttl the word "zzzz" is found; when thls word has been
encountered, an empty telegram has been detected and ET returns control
to its caller, the maln program. on each occasion that it Ís called' PT
processes a slngle telegram, uslng EI,I to extract words from Èhe buffer'
The words are printed on lines whose length does not exceed 120,
hrith a
ttZZZZt'
slngle space between words, and a word count ls kepË, the words
and "STOPt' belng except.ed from thls count; the variable "anyoversizerr is
used to record the detectton of any words of more than thtelve characÈers
ln a glven telegram. when the r¡ord "zzzz" ls encountered, a suitable set
of messages ls prlnted after Ëhe neat llsting of the Lelegram'
(itead Next Characteri the fnput text should be read from and
includi.ng the flrsE letter of the firsE word up to and including Èhe
Ëermlnatfng point. An output texE has to be produced using the
prlmltive i¡¡i(") (i.e. Print Next Character) with a characÈer valued
parameter.Èhetextistobesubject'edtothefollowing
transformatlon:
(1) ín the outPut texE, successíve words have to be separated by a
sl-ngle space
(2)lntheoutputtext,thelastr¿ordhastobefollowedbya
single polnt
212
(3) \then we number the words 0, 1, 2, 3' in the order from
fefi to rlght (i.e. ln whlch they are scanned by repeated evaluatlon
of RNC), the words with an even ordlnal number have to be coPied'
whlle the letters of words with' an odd ordí'nal number have to be
printed in reverse order'
Forinstance(usingtl-lltorePresentaspace)theinputtext
t'
"this----1s--a-silly---prograllF--. has to be transformed into "this-
sl-a-y1lls-program. " .
2L3
Pleglån oddHordl;
heritable const sPÊ' '; Pta-'."
varxichar;k!lnteger;
word : 9¡¡g¿ tt..20l of char;
herlÈable f unctlon RNC:char;
eeen functlon RNC;
DrÍvaÈe var c: char;
Úesfn read(c); n¡¡C:= c end ( of RNC );
DrlvaÈe generaÈor prlnlnextchâr cont (¿flygfg value c:char);
Drlvatevarl:lnteger;
6een conaE ap;
be¡ln
r¡hlle true do
beqln
vrtte(sp); { carralge concrol character }
for 1:=l to 120 do besln wr1Èe(c); ls.lLgrn end;
nriteln
end
gI{ ( of Prlntnextchar );
fonrard prlvate corouÈlne words;
herltable val PNC : lnstance of Prl'nÈnextchar;
WDS ! lnstance of vords;
214
,,true'') and then Lhe execution of SC 1s resumed
the ||error', varlable to
to obtain the next characÈer'
ttword"; thls
The fnstance PR prlnts Ehe conÈents of the alltay
PR' and in the
prlntfng occurs in the forwards directlon on one entry Eo
reverse dlrecÈlon on the next entry. A space is
printed before each
word, except the first'
Af ter lts inl-tl-allzat.ions, the main
program Passes control to the
sc. Eventually, control w111 return to the maln program by
one
fnstance
oftworoutes;thebooleanvariable,'error''Ísexamlnedinthemaln
ProgramtodeËermlnewhethercontrollsreEurned(normally)becauseof
ttexlttt in IüDS'
the terrnlnatlon of SC, or (abnormally) via an
Anothersolutlontotheoddwordreversalproblemlspresentedin
FlgureB.4,alsoinACL.Thesamelmplementat'ionsofRNcandPNCare
ttxt" rrkrr and tbordtt have the same
used as before, and Ehe data items
rtPRrr contains an instance of
definitlons. Ttre instance variable
r,printer,, which has sllghtly rnodified deflnitlon from the corresponding
coroutlnelnFlgureB'3:ltuses"forttloopstoperformtheforwardsand
backwards prlnting, tt never prlnts a space before
a word' and it
transferscontroltoEheinstance'l'SP''whenasinglewordhasbeen
rrprlnterrr a sl-mpler
prlnted. The f lrst two of these combine to glve
'appearance 1n the program of Flgure B'4 than
the corresponding
deflnition in Flgure B'3'
Theremainderoft'heprogramlnFlgureB.4consisÈsof.aword-
(rrRSP'r) and the maln
reader (the instance ,,RWD,,), a space-reader
Program.TheÍnstanceRI^IDlsonlyenteredwhenaletterhasalreadybeen
found,anditsjobisËoreadlettersuntilaSpaceorpoinEis
tbrord"' Thls prograE
encountered, storing the letters ln the artay
adoptsadifferentstrategyonflndingawordlongerthantl.JenEy
letters,whlchisnevertlrelessequallyconslstentwiththeproblem
speclficaEion:theflrstÈwentylettersareregardedasoneword,the
lettersafterthemuptothenextspaceorpointarealsotreat.edin
word' hlhen Èhe
thls waY¡ 1f necessary' or a're regarded as a separaEe
entlre word has been read and stored, Ehe instance PR is
then resumed
for the PurPose of Prlntlng lt'
215
Drogran Oddl{ord2 ¡
2L6
ttreadspacett) l-s to consume the
lhe task of RSp (an lnstance of
spaces between words, and the sPaces
and point after Ehe last word;
havlngfoundanon-sPacecharacter,thischaracterisexamlned.Tfl-tis
apoÍnt'RsPcallsPNCtoprlntltandexitstothemainprogramwhen
thlslsdone;lfthecharacterlsaletter'aneI^Iwordhasbeenfound-
to read Èhe word' It
firstly, a space 1s prinÈed and then RI{D is resumed
af ter the maln
1s RSP which 1s the flrst lnstance to gal-n cont.rol
and read the flrst characÈer'
program has created Ehe various instances
printed before the first
Notlce that thl-s solutlon causes a sPace to be
speclflcation of the
word' and that thls is also consl-stenÈ with the
problem.
DeplctedlnFlgureB.5arethesequencecontrolsÈructuresofthese
Èwoprograms;thatinFigureB.5(a)correspondsÈotheprogramlnFlgure
Figure B'4' The main
8.3, and that in Fígure B'5(b) to the program 1n
Programinstancesarethenodes,|oI^I1t'and'|oI^I2'''respectlvely;the
instancesofRNC,andEhelnstancePNC,areomlÈtedforclarity.Aslnthe
group 1s shown belolr
simllar dlagrams in chapter 2, the boss of a
membersofthatgroup;ineachofthecaseslnFlgureB.5,onlythemain
program lnstance ls caterval'
RI^ID RSP
I^IDS
OI,ü2
(b)
(a)
Two Solutlons to
Fi 8.5 The Sequence ConLroI Structures of the
the Odd l{ord Reversal Problem
ThesedlagramsconfirmEheimpresslongtvenbythetexËsofthetwo
Is cleaner and
programs: Èhat Ehe sËrucÈure of the second solution
slmpler.oneadvantageofthesecondsolutionnotevÍdentfromFlgure
resides within
8.5 is that during Èhe execution of thaÈ program, control
agivenlnstanceforlongerperlods;lnpartlcular,thecharacter.by-
characteroscillationofcontrolbet\'eenscandl^IDSinthefirst
solutionlsavoidedinthesecond.ThisnoEonlyaidsÈheundersÈandíng
of the program' but also lmproves lts efficlency'
2L7
8.3 Hannln tr ts Problem
ls descrlbed bY
The followlng Problem, atErlbuted to R.ïl.llamming
DlJkstra ln [36]:
ThewayËheproblemreachedmewas:r|Togenerateinlncreaslngorder
oiall numbers divisible by no
the sequence 1r213,4,516,8,9']¡
-iiå"'2, 'L2""
prirnes orher i,' ;, 5". Another way of stating whlch values
are ln the sequence is by means of three axloms:
Axiorn l. The value I ls in the sequence'
5*x'
Axlom 2. If x ls l-n the sequence' so are 2*x' 3*x and
The sequence contains no other values than
those ÈhaE
Axlorn 3. 2'
belong to lt on account of Axloms I and
TheACLPrograminFigure8.6lsbasedonthesolutlonpresented'
ttaq" is used to hold the
ln Dfjkstra,s own noÈation, ln t361. The array
membersofthesequencev¡híchhavebeengeneratedsofar,''index''
program ln Figure B'6
indlcating the last-generated member; Èhe
does Dijkstra's solution'
generates 1000 members from Èhe sequence' as
.'aq'' and points to the member of
The variable ',12,, is also an index into
thesequencewhosedoubledvaluewlllnextbeaddedtotheSequence;
tt*/tt The palrs of variables
thls doubled value is held 1n the variable '
ill3rr/rrx3" and rr15rr/rrx5" have similar meanings with regard to fnultiples
ofthreeandfive,respectively.IheinitiallzaÈlonslntheflrstgroup
.ofstatemenËsensurethatalloftheabovemeaningsholdforthecase
t'1" as lts only member'
that the sequence contalns the value
ThesecondgroupofsEatemenEsinFlgure8.6selectsthemlnímumof
,rx2rrr,,x3,, and ,,x5,,, and stores it 1n Ehe nexÈ avallable location in the
ar::ay"aq"'IhethírdgrouPofstatements'whlchisÍnaloopwiththe
ttx5ttto see 1f any or all
second grouP, Èests each of "x2"' "x3" and
contalnavaluelessthanorequaltot.hevalueJusÈaddedtothe
sequence;infactrthe"lessÈhanilpartneverapplies'andthistest
effectivelyfindsoutwhetherthevalueoftheparticularvariableis
equaltothevalueaddedÈothesequence.IfatesÈsucceeds,the
and ttí5t" are updated;
Varlable and the corresponding one of "12",ttÍ3tt
forexample,ifitlsfoundEhatthevalueaddedtotheSequencelsthe ttx3tt is
same as Ëha¡ in
,,x3", Èhen rti3rr is lncremented by one t and
to be three ti-mes the value of the element of l'aq" indlcated
redefined
bythenewvalueoflli3t'.TheflnalgroupofstaEementsintheprogram
merelyprlntsthe1000numberssÈoredinthearray'''q''.
2LB
Droßran Hannlngl;
Þrl.vate var aq : gIIs-.¡¿ t1..10001 ql lnteger¡
12,13, 15,x2,x3,x5,lndex : lnteger;
beeln
-iJnrttaLrzatlons ) l;
aqIl]:= l; lndex:=
12!= l¡ 133= l;15:= l;
x2¡- 2, x3:= 3; x5:= 5;
( generate the nutbers ln Èhe sequence )
whlle lndex*I000 do
whl-le x23aqIlndex] do
!rS1E 12:= f2+I; x2¡= 2*aq[f2] end;
whlle x3 laqIfndex] do
ES1n f 3:= 13+l; x3:- 3*aq[13] end;
vhlle x5Saqllndexl do
!9Cj8 f5:' f5+l; x5:- 5*aq[f5l end
end;
{ prtnÈ resulÈs } -
vrtreln('0ffrst lO00 numbers from the seq-' '
' uence : , , , , , , 9, I 0 ' f 2 ' ' ' ' ) ;
I 2 3 4 5 ó 8,
wrlte('0') ;
for lnclex¡=l Èo I000 do wrlte(aq[lndex]:17);
srfteln
end.
Problem
Figure B'6 Dljkstra's Solution of Hamming's
Theprogramdescrlbedabove$¡astransformedinÈothatShov,nin
FlgureB.T,throughthelnÈroductionoftÍToparameterizedsubprograms
(bothgenerators)tofactoroutoPeratlonsperformedanumberoftimes
.1nt'heprogramofFlgure8.6.Thefírstofthese,ageneratorcalled
group
,rhlext", represenÈs a parameterization of Ehe code in the second
ofstatementsintheorigtnalProgramwhlchaddsanewmembertothe
sequence;therearethreeinstancesof|thiext'',whichatecalled
||extend2,t, ,,extend3,, and ,,extenö',, correspondlng to the cases that
the
nesrmemberlscurrentlystoredin,,x2,,,llx3llor||x5||'resPectively.The
than a procedure lras that
reason for making 'rhiext" a generator rather
to be established as
thls allows a reference to the apProPriate variable
which 1s RO slnce onry the R
each lnstance is crea¡ed; this reference,
rlghtlsrequlred'isretainedbytheinstancethroughoutitslifeÈime
andthlsobvlatestheneedtoPassareferenceÈo'orthevalueof'the
a neÍI value to the axray "aq"'
varlable each time 1t is necessary to add
The name ,,hiexE" was chosen slnce lt
corresponds to an operatlon of thls
nameusedbyDijkstraEoextendthe(index)dornalnofanarrayandto
append a ner't element at the high end
of Ehis donain'
2t9
prograE H8m1n82 ¡
Fl.sureB.TTransformingDiJkstra'sSolutionofHaÛ¡ming'sProblem
Thesecondgenerat'orlntroducedlntheprogramofFlgureB.T
representstheactionsPerformedbyeachofthethreeloopsinthethird
generator (called
group of statements ln Figure B'6; Ëhat 1s' Èhis ttIztl
,rnext,,) updates the values of a particular variable palr' such as
and rrx2rr, 1n the program of Fígure 8'6, when
this updatlng ls necessary'
It has two parameEers: a RI^l reference to one of the variables "x2"'
"x3"
to the variable
and 'rx5'r, and the value of the multiplier corresPondlng
thls case
(that is, elthex ttztt, "3" or rr5rr)' The use of a generator in
rrí3rr and tri5rr to be abandoned' their
enables the varlables "í2",
220
functlonsbelngperformedbythevariablerlllllocaltoeachofthree
stored 1n Èhe variables
lnstances of "next" (these lnstances are
,rnext2,,, ,,nexE3,, and ilnext5rr). Thls ËranSfOrmatlon of three global
variableslntoaslnglevarlablelocaltoeachofthreelnstances
emphaslzesthecommonPurPoseofthethreeoriginalvarlablesand
lmprovesthedatacontrolstructureoftheprogrambyllnitingaccessaS
uuchaspossible.NoÈe,hor.zever,thaÈthlstransformation\.Iasonly
posslblebecauseÈhevariables''f2,.,''i3''and''i5''areonl.yusedinthe rrnextl'
the task of was
inltlalizaÈl0ns and the block of code from which
factored,l-ntheoriginalProgram;asfmilarÈransformatloninvolvlng
rrx3rr and "x5tr is not possible'
the varlables ttx2'rr
TheprogramlnFlgureB.Brepresentsanentirelydlfferentsolution
coroutines (or' more
to Hammlng's problem; lt l-s a soluÈi-on which uses
accuraÈely,generators)asltsbasisandcanberegardedasexhlbiting
,,dlstrlbuted controlrr. The essence of the solutlon is the following: as
(returned as the value of the
a new number fs added to the sequence
ttnextnumberrr)' an instanee of
lnstance t'next" of the generator funCLlon
it ls to generaËe' in
the generator r'üult'r is created whose Job
aequence,thethreemultiplesofthevaluejustadded.Also,tlrerelsa
I'acË1ve llsÈ'r), whose head is lndicated by the
llnked list (call ic the
globatpolnËervarlable,,activehead'',whlchcontainsoneltemforeach
.lnsÈanceof,,mult,,stlllactlve.ApartfromapolntertothenexLltem'
each active list item conÈalns an instance
of ttmult" and the next value
to be generated bY that insËance'
ThegeneraÈlonofanewvaluefromthesequencebythelnstance
,,next,, begins by flnding tlre minlmum of the values in items on Ehe
,'fífidmin''. Next, the procedure ''erase''
active list, using the proeedure
lscalled,anditscansalongt'heactivellstlooklngforal]-ltems
ruhosecurrenEvaluelsthesameasthepreviouslycalculatedminlmurn;
eachofthelnst'ancescorrespondlngtoÈheseitemsiscalled,causlng
themtogeneraEetheirnextvalue.Ifthelastvaluegeneratedbyan
Ínstanceof,,mult,,slasltsflvernultiple,thelnstanceannoun.cesEhe
variable "flnlshed" to
completlon of its task by settlng the global
,,true", as a signal to tterasettthat lÈs item on the actlve list may now
returning to "eraset"
be removed (uslng Èhe procedure "remove")' Before
attrlbute, which is a
the lnstance of ,,mult,, f lrstly sets lts ',th1s''
valueparametertndlcatlngEheltemontheactive]-istforthts
22L
ÞrogråE Haonlng3;
prlvaÈe g! aq ! array tt"l000l of lnceger¡
I : lnteger;
herltable genfunc nextnuEber : lnteger;
fors¡ard PrlvaEe ll!9 acÈ1ve;
her.ttable tvpe acEfvep¡¡ = J¿ctlvei
fofl¿ard ÞrivaEe generaÈor nult lnlc (value activePtr'
1nÈe8'er);
222
prlvate generator nult
lnf¿ 1¿¡!veqe value th13:actlvePÈr; vålue x:lnteBer);
uodlf var flnlshed;
seen orocedure fn6ert;
lnitbegln thlsf.val:= 2*x; lneert(thle) lnlÈend¡
begln
-î-Z** has been congumed ) thisl'val:= 3*x; reÈurn;
I 3** h"" been consuned ) thlsJ'val:- 5*x; le$!n;
5*x h"s been consumed - slgnal thst thts lnstânce has
i of nunbers )
flnlshed Seneratlng lta sequence
flnlshed:' true; Ehls:= nll; return
end ( of nult );
prLvate var newone : actlvePtri Dln : lnÈeger;
geen genfunc nextnunber;
{ body of nextnunber }
i.i.iátr" acÈlvehead¡= nll; flnished:- false inltend;
begln
:îãi(n."on.)
; newonef 'lnst¡- create rnult(newone'l) ¡
nextnunber:- l; newone:= nll; l!.lq!rg;
whl-le true do
begln
-îGd.ttt(.tn) ; erase(nln) ; new(newone) ;
nesonel.lnst!= creaÈe nult(newone'min) ;
nextnunber:= min; newone:= n11; reÈurn
end
end I of uexÈntmber );
Drlvate var nexÈ : lnsEance of nextnunber;
( body of maln Progran )
begln
next :Ê create nextnunber ;
for 1:=I ro 1000 !g aqtll:= next;
( Prtnt results )
itilor"<'0flrsÈ 1000 numbers from rhe seq"
'uence: Lr2,Jr4,5, 6, 8r9, f0' 12" "' );
vrite('0') ;
for t:=l to 1000 do write(aqIi] ?I7);
r¿r lteln
end.
223
returns tso its caller' the
helps in the early recovery of storage) and
maln programr where the ner¿ value is sÈored
ln the array "aq"'
Ffnally,therelsoneaspectoftheProgramofTigureB.Bwhich
makesltqulteunlikeanyoftheotherprogramslnthisAppendíx:the
number of members ln the group with Ëhe
instance "next" as íts boss is
hfghlyvariablerandlÈsvalueataglvenpol-ntlntheexecutlonofthe
program 1s not at all clear from the program
text'
used by Grune[59J to
The following ,,hl-ghry contrived" problem l-s
lllustrate his view of coroutlnes:
-'i""]' the outpuÈ will have rrbtr
I,IehaveaprocessAhlchcopl-escharactersfromlnputtooutputwith
Èhe provlso that hrhere the i"p"a-ï;"
lnstead.Andwehavea"r'iiä'processBwhiclrconvertsllbbtllnto
|rc,'.No\.{$'e\.IantEoconnecttheseProcessesinseriesbyfeedingÈhe
output of A lnto B '
Grunepresentsa',1ow.leve1'|Algol68solutlon,aSinulasolutlon
and'flnally,anotherA1gol68solut'lon,th1sËlmeuslngconcurrenf
processesandsemaphores.Grune,sSinulasolutlonlnvolvesinstancesof
twoclassdeflnitlonswhlchareslmllar,butnotidentlcal,whicheffecE an
,,resume,,; subsequently, Lynnlng[99] proposed
conLrol transfers via
,alternatlve sirnula solutlon involving thro lnstances of a single class
deffnition,ÈheseinsEancesbelngtreat'edasseneratorsthroughtheuse
ttdetachtt'
of ttcalltt and
a character'
sl-ngle "b", calling 'rnextchar" tshen it requires
occurrences of
(3) the lnstance "8", which rePlaces tr¡ro successlve
ilbtt ttctt, calling on the lnstance A vrhen Ít requlres
wlth a slngle
a character, and
224
t'chtt) when conErol returns'
-Ee,SEês LYnnlng;
herlEable var ch : char;
Drivate qenerator fnchcoroutlne;
rrodlf var ch;
begln
-
lhlfC true do begln read(ch); return end
end { of lnchcoroutine };
DrlvâEe qeneraEor converÈer lnit þ¡-¡¡vg¡e seen cl' c2: char¡
seen Producer: generator);
Dtlvâte var chl: char;
nodif var ch¡
begin
whtle true do
begln
call Producer;
ff ch=cl then
begln
call Producer¡
lf ch=c I
then ch:= c2
else
begin
chl:- ch; ch¡= cl;
!et-c-En;
ch:= chl
end
end;
Eeturn
end
end ( of converEer );
prlvaÈe var nexEchar: lnstance of lnchcoroutlne;
. Ar B: lnstance qq converter;
begln
nextchar:= creaÈe lnchcorouÈ1ne;
À:- creaÈe converter('a' ,'b' ,nextchar);
B!= create convercer('b' ,'c' ,A);
wrlte(' ');
whlle Èrue do
besln eall B; wrlte(ch) 9¡¡!;
çr I Eeln
end.
ThisProgramisparticularlylnterestingbecause,unllkeanyof
Gruners solutlons, the conversl-on of double characters
into sl-ngle ones
1s performed by dlfferent lnstances of Ëhe same subprogram deflnltlon'
only with
To achleve thls, the subprogram has to be parameterized not
resPecttothecharacterconversion(forexamPle'thatthefnstanceA
ttatt lnto a ttbtt), but alSO wlth respeq¡ to
COnVertS tqro Oqcurrences of an
whtch lnstance it is that thls lnstance must call when 1t
requires a
ttproducertt in the
character. This latËer paraüeterizaËion (the parameter
the use
deflnltion of rrconverterrr) is easily accompllshed ln ACL through
The Slmula
of the language,s |lgeneral instance Parameter'' feature.
introduced'
verslon ls a llttle more clumsy' sÍnce a durnmy class mustbe
ttConvertertt made SubclasSeS of 1t t to
and both t'inchcOroutinerr and
achleve the same effect'
225
l-rsÈly'
of the instances of 'rconvertert' behaves às foll0ws:
f
Each
theaPproprlateproducerlscalled.IfthecharacÈerreÈurnedin'.ch''is
control 1s returned
not the one soughÈ by thls insÈance (that 1s"rc1") '
then this insÈance
to fts caller (its .consumertt). rf ít 1s a "c1",
callson1Èsproducerforanothercharacter;ifÈhlssecondcharacterls
rrchrr is set to the appropriate
also a ,,c 1" , then the variable
replacemenÈ character ("c2t')' If ' however'
the second characËer is not
thesameasthefirst,whlchwasa,,cl'',thesecondcharacterisstored
trchrr 1s then set to that of
ln che local varlable "chlt'; the value of
"cl"andcontrolreÈurnedEothecallerofthlsinstance'Onthenext simply
occasl-on that, this lnstance is call-ed on
for a character"'chttis
Èo the caller; the
set to the value sÈored ín 'rchl" and control returned
lnstancehasno!ürecoveredfromltsonecharacterlook.aheadandcan
contlnue executlon as before'
Noticethattheproducer/cönsumerrelatlonshlpslnthisprograü
ensurethaÈ,lnÈhesequeflceofcharact'ers'.aab'',i'aa|'¡¡í11flrstlybe
ttbb" \^tlll become "ctt; slmllarlly' Èhe
Converted to "b'r and the resultlng
sequence "baa" wíll also end up as "ct"
slnce when B asks A for a second
ttcltr Value' a rrbrr whl-Ch
character after detectlng an occurrence of lts
1s the result of convertlng the sequence "aa" will
be returned'
226
"poPt' dlscar<Is the element
on top of the stack'
t'top" returns the value of Èhe top element of Èhe stack' and
Slnceltl-snotpossibletoparameEexlzeACLsubprogramsbyLyPe'
for stack elements; the
tt was necessary to choose a particular type
tyoechosenwas,,Ínteger,,.Stacksforot'herÈyPesofelemenEswouldneed
to be r.{rltten as seParaÈe subprogram deflnltlons'
TheACLversionofthestackabsLractlon,andsomeexamplesoffts
use, aPPears fn Figure B'10' Each stack
ls an instance of the generator
1t ls the local data of these instances r¿hlch ls the
'lpushdownstack',;
concreteimplementationoftheabstracElon.ThegeneraÈorhasfour
contlnuatlonparameters,theflrstofwhlchlndicatesÈheoperationto
beperformedonÈhesÈack.Dependl-ngonthlsoperatton,certainofthe
remalnlng three parameters may be used:
. rrpush" exPects the integer to be pushed onto the stack as the value
of the second ParameEer''
Ehree paraneters'
' "PoP" uses none of the last
.tttoP"returnsthevalueofthetopelementofthestackvlaÈhe
fourth Parameter, and
.,,emPtY,,ret,urnsÈhevalue,,true,,or''false''bymeansofthethlrd
Parameter '
ItfscertalnlytruethaÈthesynEaxofthecallsapplylngvarious
oPeratlonstothesÈackslnFlgureB.l0lsmoreawkwardthanwouldbe
thecaselnalanguagewlthaspeciallzeddaÈaabsËractionfaclll-ty,but
theessentlalcharacterístlclspresent:therepresentationofthe
("stack" and "tos") ls hldden and can only be accessed via a
abstraction
specificaËion of a data
supplled set of operatlons' Although Èhe
absEractlonlnACLwasaidedbythelanguage'sdat.acontrolfeatures,
thefeatureofthelanguagewhichmadeltfeasibleatallltlasthe
faclllty; thls Permitted
coroutine (or, nore specifically' generator)
and to have the
the representa.ion Eo be deflned local to a subprogram
samelnst'ancesofthevariablescomprlslngÈhtsrepresentatlontobe
227
used on successive entrles to the subprogram'
ÞroEram SEackTest(outPut) ;
end.
228
REFERENCES
G. At tardi
tfl L.Alello, M.AleIlo' Generallzed ?.Cavallarl and G'Prinl-r "FormaI
' Control Regimesr', Math ematical
Definition of Semantlcs of
of t rSc cel 76 À.Mazurklewicz ( Ed. ) {Lecture
Fo aL
1 7 3-L79 (SPrlnger-Verlag,
Berlln,
Not es in ComPuÈer Science, VoI.45), PP.
L97 6) .
' 9th
August
t7I K. Babcl-ekY personal comsrunlcatlons (5th ApriL 1977
'
1977 ) .
ttSome Notes on SDG Recommendation No. 2", Simula
t8l K .Babcicky,
News let.ter , Vol.6 ,- Ño. 2 (MaY 1978 ) , PP ' 15-17 '
D.I'I.Barron ' An Intr oduct
t9I to the Studv of P eramming
1977 ) .
Languages (Canbrldge UnlversitY Press ' Cambridge '
229
to ?ro osi on Da
t13l D.M.BerrY, rrlnEroducÈ1on Oreganorr,
(Eds.) {A.c.M.
i La J.T.Tou and P'l{egner
Stru tures Pro rnml-
No.2 (FebruarY 197 ),
1) pP.17 1-190'
SIGPLAN No tlces , Vol.6,
or Deletlonrr' Conf.
lf4l D.Ùf.BerrY' "Block Structure: Retentlon f uE Pp.86-
f rd Ann A.C.M. oslum
ord
100 (4.C.M., New York, I97 f) '
A' Sorkln,
t15l D.M.BerrY, L' Chirlca¡ J.B'Johnston' D.F.Martln andHi
m
rrOn the Time Requlred for ReÈentlonrr, Pro S OS
he OS
L977 )'
Í22lBurroughsCorporatio^n"'BurroughsBTO00/86O00ALGOLLanguage
DeÈrolÈ l"fichlgan
Ref erence l,fanualr' (Burroughs
Corporaulon
' ' '
1n
\^I.D.Elliottr'rAbstract DaLa Types
123l E.Chang, N'E'Kaden and vàr-.rr, No.3 (llarch 1978), PP'34'42'
Euclld", A. C.M. SIG PLAN No t ices
D.F.Martin, J.G'Peetz and A'Sorkln'
t24l L.M.Ch1-rica' T.À.Dreísbach, the Dang llng Reference, ImPosEer
rrt^ro EULER Run Time Mo<lels:
PARALLEL 1- n
Pr um Hi
EnvironrnenL, and Labe l Problems",
S OS
230
pp.10-19 (A.C.l'l' , New York, L977)
'
t'Provlng Correc^Eness of Coroutlnes without
t261 E.M.Clarke, Jr', CS:I978-4, DeparÈment of CompuÈer
HÍstory Varlable-sìì,' fechnical RepJrt (March f978)'
Sclence, Duke Univárslty, Durham' NorEh Carollna
CorouEinesrr, Acta Informatica, YoL'Z
Í271 YL.CIlnt, "Program Provlng:
(1973), PP.50-63'
rrConÈrol of Sequence and Parallellsm in
t2Bl L.L.Constantine' J int u rCo erenc r96
Modular Programstt, Proc. r (Thompson Book
ceed ) Vol.32)
pp.409-4 14
A.F.I .P. S. Conf P
'
Co. , l,Iashlngton' D.C. , 1968).
294.
ttNotes on SÈructured Programmíngrr, Structurell
t35l E.trI.Dijkstra' R.IIoãre {4.P. I. C. Studies
Pro srammj-nq O.-J. Dahl, E.I^I.Dijlèstra and 'À'
C
P ress' London, 1972) '
1n DaÈa Process lng, No. 8), pp.1-82 (Academic
l37l J.N.Doyle, "A Generalized Facillty for the AnalYsis and SYn-
Model of an ImPlementaElonr',
thesls of Strlngs, ana a Procedure-based Sclence, The UniversiEY
Technlcal Repori S4D4B, DeparEment of1975)'
CompuÈer
of Arizona, Tucson, Arizona (February
t3Bl F.C.Druseikis, "The Design of Transportable InterpreÈerstt,
SNOBOL4 Project Documlnt S4D49'
Department of Computer Science, Ihe
universltyof/ltízonarTrrcsonrArízona(Februaryl975)'
23L
J.N.DoYle' trA Procedural APProach to Pattern
t39l F..C'Druseikls and
A.C.M. Na iona Co fere eP ce S Vol. 2 9
Matchlng 1n SNOBOL4T',
(1974), PP.3rr-317'
of Pro L (Scfence Research
t40l M.Elson' Co
Associates Inc' ' Chlcago, Illinois '
L97 3) .
232
rrExtens l-ble Pattern Matching in SNOBOL4|" Proc.
t53l R.E.Griswold' f975)'
A.C.M. An I e r9 5 Pp -2 48-252 (L.C.M., New York,
t'St rlng AnalYsis and Synthesis 1n SL5'r, Pr-qg:-
ts 4l
R.E.GrLswold'
A.C.U. Annual Conference r976, pp.4
l0-4 14 (A.C.l"f ., New York, L976)'
D. R.Hanson,
trAn Overvíer¿ of sl,srr, À. c.M.
t56l R.E.Grlswold and (Aprll 1977)¡ PP'40-50'
SIGPLAN Notlces, Vol'I2' No 4
233
rrRecurslve Data Structurestr, Int. J. of Comp. and
t68l C.A.R.Hoare' 105-132'
Inf. Sciences, Vo1'4, No.2 (L975 ), PP'
I'An Axl-omal-1c Definition of Ehe
t69l C.A'R'Hoare and N.llirth,
Acta InformatlcA, Vol'2 (L973)' pp.335-
Programming Language Pascal",
355.
t7O]J.D.IchblahandS.?.l"forse,''GeneralConceptsoftheSimula6T
Progranming Language",
Part I (L972), PP'65-93'
Prl- 1es Pro am De {A.P.I.C. Studles in
t71l M.A.Jackson, Londonr ).
Data Processlng, No'1 2> (Academic Press'
19 7s
A.C.M.
l72t T.Jacobsen, "Another Vtew of Coroutlnes'r'
SIGPLAN
rrVecEor sofCoroutlnesoveÌ.BllkleNets'r'Fundamen-
174l R.Janlckl,
ls of ut on l"f.Karpinskl (Ed. ) {Lecture Notes in Computer
Sclence, Vol.56)' PP' r13-11 9 (Sprineer-Verlag,
Berlln, L977)'
Pas Us la Re or Lecture
U 5I K. Jensen and N 'I^Itrth '
Not,es in ComPuter ScÍence, Vol . lB (Springer-Ver
lag' Berlin, 1974).
234
and D.MacQueen, rrCorout ines and Networks of Parallel
tBz¡ G.Kahn (Ed')r
Processes It , Inf lon Proces 1 77 Ì.Gllchrlst PP'993-998
(North Ho tland Pub. Co., Amster dam,1977>
Programs'', Technlcal
I83l R.B.Kleburtz, ',SÈeps Toward Verif iabIe
ReportNo.12,Dept.ofComputerScience,sEaEeUniversityofNewYorkat
Stàny Brook, Stony Brook, Ñew York (Noveml¡er L972) '
and TYPes", Proc. Confe
tB4l C.Il.A.Koster' "vlsÍbillty ure
D
t94]G.Llndstrom,,,EfflciencyinNondeterminísticConÈrolthrough
Department
Non-forgetfur ¡acttrácking", Technical Report No'UUCS-77'LL4'
ofComputerSclence,Universl-tyofUtah,saltLakeCity'Utah(October
1977 ) .
235
rrControl Structure Aptness: A Case Study using
t95l G.LlndsËrom
ce on So f tv¡are
Top-down Parsing", Proc. Thfrd Internatlonal Conferen
Engineerlng, PP.5-12 (r.E.E.E., L97 8).
tfBacktrackl-ng in a Generalized Control Settlngrr,
t96l G.Lindstrom' sandS sÈems Vol.1, No.1 (JulY
A.C.M. Tr onP amml La
L979)¡ pP.B-26.
f971 B.Llskov' A. Snyder ' R.At klnson and
C.Schaffert, rrAbstracÈion
Mechanlsns ln CLUrf, Co À.C.l"f .. Vo1.20, No.8 (August L977), pp'564-
576.
TechnJ.ques for Data
t98l B.H.Liskov and S.N.Zlllesr "SPecification Rel iable Software L975
AbsÈractlonsrr ¡ Proc. InternaE ional Conference on
A.C .M. SIGPLAN Not Vol. 10 ' No. 6 (June 1975 ) ), pp.7 2-87 (a lso :
I.E.E.E. Trans. Sof r¡tare En neeri Vol. SE- 1, No. I (March L97s),
pp.7-19).
tices,
t99l E.Lynning, letter to the Edltor' A.C.M. SIGPLAN No
tl05lJ.R.McGrawrt'LanguageFeaÈuresforProcesslnteractionand
Department of Computer
Accå"" ConËrol'r, Technlcal Report No'77-319'-
York (August 1977)'
Science, Cornell UniversiÈy, Ithaca, New
236
[109] R.M1lne and C ' StracheY,
trA Theory of Prograrnmfng Language
SemanÈlcs" (Chapman and Hall, London, I97 6> .
ttSchemes: À High Level Data SÈruc-
t f 10 IMltchell- and B 'Iüegbreit '
J. G.
turing Concept'r, Report No' CSL-77-l' Xerox Palo Alto Research
CenÈer'
palo Ãlto, Californla (January 1977)'
rrThe Sp eciflcatlon of Prograu Flow in
t1 lf l J.B.Morrls and M'B'I^Iells, B.l'f .LeavenworEh
Madca P 6",
972)>, pp.2B-35.
(Ed. ) A.C.
t120]D.L.Parnas,'lontheCrl-terlatobeUsedinDecomposlngSystens
l_nto Modules,,, _co*n:_ ¿_.c_.r't:, vol.15, No.12 (Dec. L972) I PP'I053-1058'
11211 T.W.PratE'
es: Desisn and rmp le.mentaEion
Pro arnmlng La
(Prentlce-Hall Inc. ' Englewood Cliffs,
New Jersey I975).
'
es of ECLtt, Proc.
lL22) C.J.Prenner, "The ConÈrol Structure Facillti s.A.schuman (Ed. )
Intern â, tional Svmoosium on ExÈ ens ib 1e LanquaPes.1) pp.104-112.
A.C .M. SIGPLAN Notíce , Vol.6, No.l2 (December 197 ) r
237
tL24]P.A.Prltchard,''onemantlcCharacterlsaÈlonofSome , M'C'Neweyt
AdVanced Control Structurestt, ian National
R.B. Stanton and G.L.i^Iolf endal
unlverslty press, canberra, Australtan capltal rerrlEory' 1978).
I'Semantlcs and Proof Rules for Coroutlne Hierarchles
lL25l P.Raulefs, Mat hematlcal FoundationC --S-!
in Block-Structured Progr arnming Languagestt, Notes 1n ComPuter
ut Scienc r977 J.Gruska (Ed. ) {Lecture
Scl-ence, Vol.5 3), PP. 45 L-459 (Springer-Verlag, Ber 1in,
L977).
lI27]J.C.Reynolds,''GEDANKEN-AsimpleTypelessLanguageBasedon A'c'M.,
the Princlple of completeness and the Reference concêPttt, comm'
Vol.I3, No.5 (May 1970), pp'308-319'
tl28l M.Richards ' "BCPL: A Tool f or CornPller I,Irlting and SYstem
1969 {A.F.I.P.S.
Prograrn-ningt', Proc. Sprins Joi nt Comouter Conference
Conf ence P eedin , Vo1.34), pp.557-5 66 (A.F.I.P.S. Press, Montva Iet
New JerseY, l9 6g).
ttPerformance of
ll29i G.D.Rlpley, R.E.Griswold and D.R'Hanson, i!, I.E.E.E . Trans. on
Storage l'fanagement in an Implenentation of SN0BOL .130-137.
Software Engineering' Vol.SE-A, No-2 (March 1978), PP
t13rlA.H.J.Sale,"867OO/TT00PASCALReferenceManual-Compi-lerVer-of
slon II.8.002", Deiartment of InformatÍon Sclence, The Unlverslty
Tasmanla, Hobart, Tasmanl¿ (July L977)'
is Us es Co nes M. S. thesis,
f32l S.E.Sevclk' An
t
North Carolina at Chapel
DepartruenE of ComPu ter Science, UniversltY of
H111, Chapel llill, North Car ollna (1976).
I'A SCRABBLE Crossword Gaure Playlng
t1331 S.C.Shaplro and II.R.Surlth, Science' StaEe
Program", Technical Report 119, Department of CompuEer (March 1977)'
Universlry of New York ãt Buffaio, Buffalo, New York
and verif ication
11341 M. Shaw, t{.À.tlulf and R.L.London, "AbstracEion
in Alphard: Deflning and Specifylng lteratl-on and GeneraËors", Comm'
238
rrCoroutlnes fn FORTRANTT,
Ir3il Skordalakis and G.Papakonstantlnou'
E.
A.C.M. S No t lces Vol.l3, No.9 (SePtember 1978), pP.76-84.
rrAnalytlc-al Properties of General-
tl3Sl M.L.soffa and G.Lindstrom, No. 76-L0, Department of CompuÈer
fr.å Cotoutlnes", Technical Report Pennsylvania (March
Science, Unlversicy of Pittsúurgh, PitEsburgh'
L977 ) .
ttA Formal AnalYsis of Name Accessing 1n Programming
t1391 C.L.Srnith'
Languages'r , Ph. D. Dissertation, Iowa State UnÍversltY, Ames, Iowa
(1975).
Memo AIM-290 {also:
t1401 N.I^I.Smith, 'TSAIL Tutorialr', A'I' Lab' UnlversitY'
Computer Sclence Department RePort STAN-CS-76-575)' Stanford
Stanford, Californla (October I976)'
t{.SÈallings, "An Appllcatlon of CorouËlnes and Backtracking
11411 on
Ln
Interactive SYstems", lnt. J. of ter and Informati Sclences.
Vol.5, No.4 (December L976), pp.303-313.
in Comouter
Í142J D.F.Stanat and D'F' IfcAllister, Discrete ì,IathemaÈicsr977).
Sciencã (Prentlce-Hall Inc', Englewood Cliffs, New JerseY,
146I I^1. Teltelman ' INTERLISP Reference Manual (Xerox Palo Alto
Re-
t
search CenÈer, Palo Al to, Californla, L975 ).
GeneralizaElon of caltt,
tl4Tl R.D.Tennentr "PASQUAL: A Proposed Pas
0ntario
Technlcal Report No.75-32, Queen's UniverslÈy' Kingston'
(February 1975).
S.Zelgler, ttDeslgn Ratlonale
t1481 L.Travis, I'l.Ilonda, R'LeBlanc and Ar tlf 1al
for TELOS, a Pascal-based A'I' Language t
il Proc. osl
. C.M. Vo1. I 2'
In tell-ieence and P roqrammi nq Languages SIGPLAN S
No.B (August L917) and A.C.M. SIGART Newsletter' No.64 (August L977 ) ),
pp.67'76.
239
t1501 A.van B.J.Mallloux, J.E.L.Peck, C'H'A'Koster,
Wl-Jngaarden'
M.Sintzoff, C.H.LlndseY, L' G.L.T.Meertens and R.G.Fisker (Eds.),
rrRevlsed ReporÈ on Èhe AJ-gorl- throlc Language ALGOL 68", A. C.M. SIGPLAN
Notlces, Vol.12' No .5 (May 197 7 ) ' pp.t-70 (also: Acta Informatica' Vo1.5
(1975), pP.t-236).
rrEuclid and Pascal", A'C'M'
t1511 T.Venema and J.des Rivieres,
SIGPLAN Notices Vo1.13, No.3 (l"farch 1978), PP'57-69'
l|Coroutlne Sequencing in a Block
ÍI52,J À.I^Iang and 0..J. Dahl,
StrucÈured Envlronmenttr, B.I.T., Vol.11 (1971), pp.425-449'
31 S . K. l{arren ' The Co routine Mo 1 of Attrl te Grammar Evalu-
t 15
ation, Ph.D. thesls, Rlce UnlversiEY, llouston' Texas (Apr11 1976).
11541 D.A.I,Iatt, "An Extended Attribute Grammar
for Pascaltt, A.C.M.
SIG PLAN Notlces Vol.14, No.2 (February I97 9), pp.60-74.
240
t1651 f{.I{ulf , D.B.Russel-l and A.N.Ilabermann, I'BLISS: A Language for
Systems Programmingrt, Qemm. A.C.l'{.. Vo1.14 t No. I 2 (December I97 l) ,
pp .780-790.
24L