• No results found

Modular Pascal language definition (with special reference to the PDP11 implementation)

N/A
N/A
Protected

Academic year: 2021

Share "Modular Pascal language definition (with special reference to the PDP11 implementation)"

Copied!
67
0
0

Bezig met laden.... (Bekijk nu de volledige tekst)

Hele tekst

(1)

Modular Pascal language definition (with special reference to

the PDP11 implementation)

Citation for published version (APA):

Bron, C. (1982). Modular Pascal language definition (with special reference to the PDP11 implementation). (Rev. version ed.) (TH Eindhoven. Afd. Werktuigbouwkunde, Vakgroep Produktietechnologie : WPB; Vol. WPB0221). Twente University.

Document status and date: Published: 01/01/1982 Document Version:

Publisher’s PDF, also known as Version of Record (includes final page, issue and volume numbers) Please check the document version of this publication:

• A submitted manuscript is the version of the article upon submission and before peer-review. There can be important differences between the submitted version and the official published version of record. People interested in the research are advised to contact the author for the final version of the publication, or visit the DOI to the publisher's website.

• The final author version and the galley proof are versions of the publication after peer review.

• The final published version features the final layout of the paper including the volume, issue and page numbers.

Link to publication

General rights

Copyright and moral rights for the publications made accessible in the public portal are retained by the authors and/or other copyright owners and it is a condition of accessing publications that users recognise and abide by the legal requirements associated with these rights. • Users may download and print one copy of any publication from the public portal for the purpose of private study or research. • You may not further distribute the material or use it for any profit-making activity or commercial gain

• You may freely distribute the URL identifying the publication in the public portal.

If the publication is distributed under the terms of Article 25fa of the Dutch Copyright Act, indicated by the “Taverne” license above, please follow below link for the End User Agreement:

www.tue.nl/taverne Take down policy

If you believe that this document breaches copyright please contact us at: openaccess@tue.nl

providing details and we will investigate your claim.

(2)

MODULAR P MCAL Language Definition

C. Bron oktober 1982 WPB 0221

(3)

~~

Technieche Hogeechoo\ Twente

t-1nl0RA!';Dl1~:~R.

1 NF-h2-] () I)

t-loclular Pascal Lan!~uagc Definition (witll spccial refercnce to the PDP II implement.:lt i,m).

C. UrCln.

\)ej1artllicnt .. f CU:'iplltinr, SCiel)Cl'

T>"I"J:te l'nivl.'rsit\, ( I f Technology P.O. !:lox :!17

7500 AE Ellscheu"

The ~ctherlands.

Onderaf deling der Inf orma tiea

I )Rt'vl sec version of puhl i ('<3 t i 0n :\,

(4)

TABLE OF CONTENTS

1. Introduction

2. Summary of tIle language

3. Notation, terminology and vocabulary

4. Identifiers, numbers. characters dnd strings

5. Constant defjnitions 6. Data type definitions

Simple types Ordinal types 6.1 6.1.1 6.1.1.1 Enumeration types Subrange tYPl?s Standard types Structured types 6.1.1.2 6.1.2 6.2 6.2.1 6.2.2 6.2.3 Array types Record types Set types Fi Ie typt·s Poi nt~r types Packed tyP"s Stri ng typl'S 6.2.4 6.3 6.4 6.5

6.6 Type identity and typ~ compatibility

7. Declarations and d~nolations of variables

7.1 Entire variables 7.2 Component variables 7.2.1 Indexed variables 7.2.2 Field de~lgnators 7.2.3 File buffers 7.3 Referenced variables 8. Expressi ons 8.1 8.1.1 8.1. 2 8.1. 3 8.1. 4 8.2 8.3 Operators

The operilt or NOT

Hultip1ying operators Addi ng operators Relatio~ll operators Function d"signators Expressions of structured 9. Statement!> 9.1 9. 1.1 9.1. :2 9.1. 3 9.1.4 9.1. 5 9.2 9.2.1

Simple stat ements

Ass! gnmt:'!it statements

Upddte statements Procedurr statem~nts Except101l statements Goto stAtements Structured statements Compound statements types

(5)

9.2.2 9.2.2.1 9.2.2.2 9.2.3 9.2.3.1 9.2.3.2 9.2.3.4 9.2.3.5 9.2.4 Conditional statements If statements Case statements Repetitive statements While statements Loop statements Repeat statements For statements With statements 10. Blocks and scope 10.1 Blocks

10.2 The scope of identifiers and labels 11. Procedure and function declarations 11.1 Procedure declarations

11.2 Function declarations 11.3 Parameter conformance 12. Exceptions and interrupts 12.1 Exceptions

12.2 Interrupt handling 13. Modules

14. Standard identifiers and implicit functions 14.1 Standard types

14.2 Standard constants

14.3 Function-like standard identifiers 14.4 Procedure-like standard identifiers 14.5 Dynamic allocation of variables 14.6 Transfer functions

14.6.1 Explicit transfer functions 14.6.2 Implicit transfer functions 14.7 Standard exceptions

15. File handling

15.1 Connection and disconnection 15.2 File expansion

]).3 Accessing fIle components 15.4 File status information 15.5 File macro operations

15.6 File system exceptions (to be supplied)

15.7 Filenames (to be supplied)

16. Text files (L~gible input/ output)

16.1 Input from textfiles 16.2 Output to text files

16.2.1 The (multi)procedure write

17. A survey of deviations from standard Pascal APPENDIX A: Index to syntactic constructs

APPENDIX B: Defects of the current implementation

(6)

Ahslr.:lct.

This r~p(1rt dcscrib~s the langu3ge Nodular Pascal as implemented

jointly ;'It Twentc University of Technology (Enschede) and the

Univ('rsity of Groningl'll, !-:etherlands.

The l.:lnguage Modular Pascal is 3n eXLension of Pascal and almost

contains the L.lt tt'r as a subset. Modular Pascal supports the developmc'nt of programming systems in terms of manageable units: M'ldules. The langu:lgl: is particul:1rly suit.:.tble for systems programming, nnJ it C.:ln be l'nsily interfaced with a variety of Op~rating Systems.

Tile languJge has heen implemC'nteu by means of rt!targetable (4-pa85) compiler, the 4th pass heing represented by target specific code

gener,nors. C('nl'r;nors ;Ire pr('~;l>ntly aV.:Iilahle for PDPII, M680UO, 1\16809, alld 7.80. Pr'Jf;r<lt,s wri tt(,11 in ~lodu13r P.:lsC.:ll are supportec by a family of Opl'r;,tin~ Sy,.;tems Ul'V,']"Pl'U in this very language, but n:.:ly als0 run IlDut'r U:\L\(l'DP11), RIII(PlJP!!) and CP/~1(Z80 with memory m3nager.k'll t ) •

Altliough :ltl attempt l13s been made Lo describe the language and t;;.:;,

conSL'qut'lld'S l l f its implemelltation in 2etail. tids report shculd n('(

be consiul:rl'u as.l "l'sL'r Kmu<.ll". The report descrihes the COr.L'::~':1

core' of 111\: Jangu.1ge. !h.'vialiol1s for p.:lrticular implementation!:' art

Jistrd in ~ppel1dix C.

I,s dcvl:'l,'pments ""itll Tt'i~<lHI to l.:ll1guage :md s),stC':-:1S nre still ll~ progn'!>:;, this rl'p,'rt (kscriht';-; till' statl.: of thL tlOment only. lIo\,'ev(>r, tile' current contents "f the languagt' definition may bl'

consid('reJ st[l1;],:. One .1SpC,'l ,,( thL' Innguage, .. .'hich is cor.~",:,,;~)n:y

descrih,'" in .:l languagp m:wual, is lwt discussi?d here: Stancdrc Proccdur,'s. It is typical of the approach of Hodular Pascal that standard procl'durl's sjHJUld iw p.1rt of .:1 lihrary, which is dyn.:l~.i;:, :in':

(7)

Modular PasC'.Jl Page 1

REPORT ON THE PROGRAH~lNG LANGUAGE

MODULAR PASCAL

1. Introduction

This report describes the programming language Modular Pascal as

implemented at Twente Un1versity of Technology (Enschede) and the

University of Groo1ngen, Netherlands. The language defined In this

report contains Pascal as defined by N. Wirth as a subset with a few

minor exceptions.

Some of the extensions available in the current implementation deal

wi th a number of we 11 known defic lenc ies In the od ginal language

(most notably: array parameters), whereas most of the remaining

extensions serve to make Pascal fit 81> a systems programnrlng language,

giving the programmer full control over the underlying hardware where

ever this is deemed necessary. Clearly. the latter objective does

imply some changes with regard to a language which was originally

designed for educational purposes only. A survey of deviations of the

language described here from what 1 s generally considered as standard

Pascal can be found in chapter 17.

This report has been wri tten as an adapted version of the original

Pascal report and therefore the presentation heavily borrows from that

original. Whatever use is made of ~irth's original definition is

gratefully acknowledged. A second source from which parts of this

report have been borrowed is the I. S. O. Draft for a Pascal Standard

and comments which have been submitted in the discussion of this

draft. The use of thi s source is E'qually acknowledged.

The accuracy of the full C ontl'nt S ,)f tid s report - wi th respect to the

implementation described - is, how(>vl'r. the author"s responsibility.

The whole project has been accomplished as a set of M. Sc. thesis

projects , notably:

Language Revision and Compiler: Operating Systelll Implementation: PUPIl Code Generator:

M6B09 Code Generator: M68000 Code Generator: Z80 Code Generator: E.J. Dl jkstra M. Prins, S. Joosten, T. Rossingh. C. Bron

J. Sauer, C. Bron, M. Smulders

J. Jongejan, E.J. Dijkstra

H. l'!aaskant, J.A. Ledeboer,

N.G.M. Blokhuis R. Duursma

Various other m~mbers of the Compuling Science Group of Twente

University of Technology have contributed to the project in various

stages of completion, viz. A.H. Noorman, S.D. Swierstra, P. Voda,

A .J • de Vuys t. G. Dooro1 nk .

This report descrIbes the core of the language and its implementation.

Deviations pertaining to particular target machines are described in

(8)

Modular Pascal Page 2

2. Summary of the language

An algorithm or computer program consists of two essential parts, a

description of actions which are to be performed, and a dt'scription of

the data, which are manipulated by these actions. Actions are

described by so-called statements, and data are described by Bo-called declarations and definitions.

Each program, in particular when intended to describe a complex task,

may be split up in a number of modules. Each such module consists of

a set of declarations and a stateme;;-t-part which initializes the data

belonging to the module. Objects introduced in a module may be

exported to other modules. In this way, any set of modules may act ae

an environment to another module. It ie in this way that an Operating

System and a set of standard-procedures may be viewed from any program

(or module) newly to be developped.

The data are represented by values of variables. Every variable

occurring in a statement must be introduced by a variable declaration which associates an identifier and a data type with that variable.

The data

!IE!

essentially defines the set of values which may be

assumed by that variable. In Pascal, 8 data type may either be

described directly in the variable declaration, or it may be described by a type identifier, In which case this identifier must be defined by an explicit.!1:£! definition.

The basic data types are the scalar typ~s. Their definition indicates

an ordered set of values, i.e. introduces identifiers standing for each value in the set. Apart from the definable scalar types. there

exist four standard basic ~:boolean, integer, char, and real.

Except for the type boolean, their values are not denoted by

identifiers, but instead by numbers and quotations respectively. These are syntactically distinct from identifiers. The set of values of type char is the ASCII set as available on the PDP 11.

A type may also be defined as a subrange of a scalar type by indicating the smallest and the largest value in the subrange.

Structured ~ are defined by describing the types of their

components and by a indicating a structuring method. The various

structuring methods differ in the selection mechanism serving to

select the components of a variable of the structured type. In

Pascal, there are four basic structuring methods available: array

structure. record structure, set structure, and file structure.

In an array structure, all components are of the same type. A

component is selec ted by an array selec tor or computable index, the type of which is indicated in an array type definition and which must

be scalar. It is usually a programmer-defined scalar type, or a

subrange of type integer. Given a value of the index type, an array

selector yields a value of the component type. Every array variable

can therefore be regarded as a mapping of the index type onto the

component type. The effort involved in a selection is independent of

(9)

Modular Pascal Page 3

random ac~ structure.

In a record !!ructu~ the components (called fields) are not

necessarily of the same type. In order that the type of a selected

component he evident from the program text, a record selector is not a

computable value, but an identifier uniquely denotIng the component to

be selected. These component identifiers are declared in a record

type defin1on. As is the case with arrays, a record is also a random

access structure.

A record type may be specified as consisting of several variants.

This implies that different variables, although said to be of the same

type, may assume structures which diff~r in a certain manner. The

difference may consist of a different number and different types of components. The variant which Is assumed by the current value of a record variable may be indicated by a component field which is common

to all variants and which Is called the ~ field. Usually, the part

common to all variants will consist of several components, including

the tag field.

A set structure defines the set of values which is the powerset of its

base type, i.e. the set of all subsets of values of the base type.

The base type must be a scalar type, and will usually be a

programmer-defined scalar type or a subrange of the type integer.

A file structure is a ~~~ of components of the same type. A

natural ordering Is def! ned through the sequence. At any instance.

only one component is directly accessible. The other components may

be made accessible either by progr~5sing sequentially through the

file, or by positioning the file explicitly on a specified component. A file can be expanded only by appending additional components at its end.

Varlabl~s declared in t'xplicit declinalions are called static. The

declaration associates an identifier with the variable which is used

to refer to the variable. In contrast, variables may be generated by

a statem~nt. Such a ~~am~ generation yields a so-called ££inter (a substitute for an explicit identifier) which subsequently serves to

reft:'r to the v.:.lriable. This pointer may be assl gned to other

vara! ables, namely of type poi nter. Every pointer variable may assume

values pointing to variables of the same type T only. and it Is said

to be bound to this type T. It may, however, also assume the value

nil, which points to no variable at all. Because pointer variables

may also occur as components of structured variables which are

themselves dynamically generated, the use of pointers permits the

representation of finite graphs in full generality.

The most fundam~ntal statement is the assignment statement. It

specifies that a newly computed value be assigned to a variable (or a

component of a variable). In some cases, where there is a special

relationship between the old value of the variable and the new value, an ~ate tatem~nt may be used. A new value is obtained by

evaluati ng an ! xpression. Expressi ons are formed from variables,

constants, sets, operators, constructors, and functions operating on the denoted quantities and producing new values. Variables, constants

(10)

Modular Pascal Page 4

entities. Pascal defines a fixed set of operators, each of which can

be regarded as describing a mapping from the operand types into the

result type. The set of operators is subdivided into groups of

1. arithmetic operators of addition, subtraction, sign inversion, multiplication, divisIon and computing the remainder.

2. boolean operators of negation, union (or), and conjunction (and). set membership and testing subset property.

3. set operators of union, intersection and set difference.

4. relational operators of equality, inequality, ordering, set

membership and set inclusion. The result of relational operations is of type boolean.

A procedure statement causes invocation of the designated procedure (see below). An exception statement deals with what is usually called an error situation. Assignment, procedure and exception statement are the components or building blocks of structured statements which

specify sequential, selective or repeated execution of their

components. Sequential execution of statements is specified by the

compound statement, conditional or selective execution by the

!!

statement and the

£!!!

statement, and repeated execution by the repeat

statement, the while statement the for ~ment and the loop

statement. The if statement serves to make the execution of a

statement dependent on the value of a boolean expression, and the case statement allows for the selection among many statements according to the value of a selector. The for statement is used when the number of iterations is known beforehand, the other repetitive statements are used otherwise.

A statement can be given a name (identifier), and can be referenced

through that identifier. The statement is then called a procedure,

and its declaration a procedure dec~~~ation. Such a declaration may

additionally contain a set of type definitions, variable declarations

and further procedure declarations. The types, variables and

procedures thus declared can be referenced only within the procedure

itself, and are therefore called local to the procedure. Their

identifiers have significance only within the program text which constitutes the procedure declaration and which is called the scope of

these identifiers. Since procedures may be declared local to other

procedures scopes may be nested. Entities which are declared in a main program (i.e. a module), and therefore not local to a procedure

are said to be global.

A procedure has a fixed number of parameters, each of which is denoted

within the procedure by an identifIer called the formal parameter.

Upon an activation of the procedure statement an actual quantity has

to be indicated for each parameter, which can be referenced from

within the procedure through the formal parameter. This quantity is

called the actual parameter. There are four kinds of parameters:

value parameters, constant parameters, varIable parameters and

procedure or function parametf'rs. In the first case, the actual

parameter is an expression, which 1s evaluated once. The formal

parameter represents a local variable to which the result of this

evaluation is assigned before the execution of the procedure {or

function}. In the second case, the formal parameter represents a

(11)

Modular Pascal Page 5 formal parameter may only appear in expressions. In the case of a variable paramett'r, the actual pC:lramt'ter must be a variable and the formal parameter stands for this vhrJable. Any indices appearing In the Be tual parameter are l>valuated h,' fllre ~ xl'cution of the procedure (or function). In the caSt' of a pr'lc:('durc or function parameter, the actual paraml.'ter must he a proct'dure or fun'~tion identifier. declared to have a paramet~rlist. matching with the parameterlist of the formal proct.'durl' or {unction.

Funl'tions ar~ dccldrl:'d analogou:,]y to procedures. The only difference lies in the fih:t that a fl;l'Ctloll I'lay dt.'liver a result of any type (except a file type) by mt';lnS 01 Iht' o'"currence of a function

designator in an expression.

Ful J control over the Ililrdwar..- , a~ Illay hI.' necessary for systecs applications, is supplied In the fo:-m of programmer-defined Int~rrupt

handline. the pos.:iibility to insert (machine) code anywhere within a Pascal program, the poss! hi J Ity to a ocatevariables at specified memory local i 0l!..~., st andar d pron>dllrt's to fad litate address arithmetic, and a sppclfication of the way in which certain data declarations can be associated with hltftcld~ in words of the target machi ne.

(12)

Modular Pascal Page 6

3. Notation, terminology and vocabulary

The syntax of the language is described in a variant of the

traditional Backus-Naur Fann. Syntactic constructs are denoted by

English words between the angular br.1ckets < and >. These words are

chosen such as to describe the meaning of the construct, and they may

reappear in the semantic description of the construct, following its

syntactic definition. In the definitions the curly brackets { and }

are used in the following way:

{ } indicates an optional occurrence of the r.onstruct enclosed within the brackets.

{ }*

indicates zero or more occurrences of the construct enclosed within the brackets,

{ }+ indicates one or more occurrences of the construct enclosed within the brackets.

If in a syntactic definition a number of constructs are to follow each

other, this is described by a juxtaposition of these constructs. (A

~ construct enclosed within curly brackets will never be followed by a +

or

*

symbol, except where used as described above.) Alternatives in a

syntactic definition are separated by a bar:

I.

The construct

(empty> stands for the empty sequence of symbols.

The vocabulary of Pascal consists of basic symbols, classified into letters, digits, special symbols and word symbols.

<letter> ::=

AIBlciDIEIFIGIHlrIJIKILIM/NlolpIQ/RlsIT/ulvIWIXlyIZI alblcidielfig/hliljlkillminiolplqlrlsitiu/vlwixlylz

Although a set of 52 letters is available, no distinction is made

between a capital letter and its corresponding lower case letter,

except in strings. In a program, a distinct use of both letter types

may be made to obtain particular visual effects.

<octal digit> ::=

011121314/51617

<digit> ::=

011/213141516171819

<speCial symbol> ::= - I + I * I / I - I < I > I ( I ) I [ I J I . I , I

;1:1(11-1'1

I@

<word symbol>

::-MOD 1 t\IL I IN I OR I COR 1 Af'..1.J I CAND 1 NOT I IF I BUT

THEN I ELSE I CASE 1 OF I REPEAT I UNTIL 1 ~llLE 1 DO I

FOR I TO I DOW~TO 1 BEGIN I E~n 1 WITH 1 GOTO 1 CONST I

VAR 1 TYPE 1 ARRAY I RECORD I SET I FILE I FUNCTION

PROCEDURE I LABEL 1 PACKED I PROGR.A}1 1 1 NTER.RUPT 1

OTHERS 1 EXCEPTION I FOR~ARD I EXIT I DIV I LOOP

Word symbols obey the syntax of identifier (see chapter 4), but they

have a fi xed m.eani ng for the language whic h can not be changed by a

redefinition as is the case for ident1fiers. In this report, whenever

(13)

Modular Pascal Page 7 letters, to make them stand out from identifiers, but this is only

done for its visual effect to which no further meaning should be

at tac hed.

Comments can be introduced anywhere in a program except within

identifiers, strinss. word symbols or fixed sequences of special

symbols. These comments should obey the following syntax:

<c omment open> ::- (*

I

%

<comment close> ::- *) I \

<comment bracket> ::- <comment open) I <comment close>

<comment sequence>

::-"any sequence of ASCII characters, not containing a comment bracket" <simple comment>

::-<comment open>::-<comment sequence>::-<comment close> <comment>

::-<simple comment>

I

<comment open>{<comment sequence) I <comment>}*<comment close>

A comment should always be closed by the closing bracket which matches

the opening bracket of the comment. The nesting of comments may be

helpful 1n the development phase of a program, by allowing certain

parts of the program to be temporarily removed by inclusion in comment brackets.

Blanks (spaces) and line separations may appear anywhere in a Pascal

program, except in identifiers, word symbols, relational operators,

update operators. numbers and the subrange separator (If .... , see

6.1.1.2.). Word symbols, identifiers and numbers must be separated by

a blank, comment, or line separation when they are immediately

juxtaposed. Blanks carry no meanJng, except when occurring in a

string, in which case they stand for themselves.

Line separations or any other ASCII ch.lracters that have no visual

representation are not allowed in strings. (See 4. on how

(14)

Modular Pasc al Page 8

4. Identifiers, numbers, characters and strings

---~---Identifiers serve to denote constants, types,

variables, procedures, functions, modules and exceptions. Their

association must be unique within their scope. (With regard to the

concept of scope, see 10.). Underscores may be used in identifiers to

increase their legibility, but apart from that purpose, they have no

significance.

<identifier> ::- <letter){<letter>l<dlgit>l<underscore>}*

<underscore> ::=

<export sym) ::=

1

When In the definition of an identifier

an export sym, then this indicates

accessible outside the module in which global identifiers may be exported.

this identifier is preceded by that the identifier is made

it Is being defined. Only

The usual decimal notation is used for numbers, which are the constants of the data types rea! and integer (see 6.1). The letter E

preceding the scale factor is pronounced as "times 10 to the power".

An octal constant may be used to represent a PDPll bit pattern. A

based integer may be used to represent a value or bit pattern in any

number system having a base <~ 16. The base is given 1n decimal

representation. If the base exceeds 10. the letters A through F

represent digits within the number system having a numerical value

from 10 through 15. .

<digits> ::- I<digit>}+

<integer denotation> ::- <digits>

I

{<octal diglt)}+B

I

<based inte ger>

<based integer) ::- <base)U{<based digit>}+ <base> ::- <digits>

<based digit> ::z <digit> IAIBlclDIEIF

<real denotation) ::- {+I-}<digits).<dJgits>{(scale factor>} , {+I-}<digits><scale factor>

<scale factor> ::= E{+I-}<digits)

Examples:

1 100 0.1 5E-3 87.35E+8 177777B

Examples of based integers:

2#100101 16#AFOO 8U177777

Sequences of n (n > 0) characters enclosed between apostrophes are

called strings. For n > 1 they are the constants of the types PACKED ARRAY [l •• n] OF char

Note: An apostrophe In a string can be represented by writing the

apostrophe twice. <string char>

::-"The full set of ASCII charac ters except ' ..

I

<double apos>

<double apos) ::- "',

(15)

Modular Pascal Examples: ' 8 ' 'Pascal" ' a d l or whistle\OOr 'This is an "A"-string' Page 9

Within a string, sequences of characters starting with a backslash (\)

have a special meaning. A backslash followed by three octal digits

denotes the ASCII character encoded by the octal number following the

backslash (\ddd). A backslash followed by a backslash stands for a

single backslash. A backslash followed by one of the letters listed

below means: \b Backspace \f Page Feed \h Horizontal Tabulate \n Line Feed \r Carriage Return

\z ASCII Null character

Strings of 1 character serve to denote the constants of the standard

type' char. The first line of the exampll!s contains three strings

(16)

Modular Pascal Page 10

5. Constant definitions

A constant definition introduces an identifier as a synonym to a

constant

<constant identifier> ::- <identifier> <constant definition>

::-{<exportsym>}(constant Identifier>-<constant expression) <constant expression> ::- (expression)

<constant> ::- <string>

I

<constant identifier>

<integer denotation>

I

<real denotation>

A set-, record-, or array constructor is a constant expression if all

its constituents are constants. Other expressions allowed in constant definitions are expressions of type integer only, possibly containing

the operators

+ , - ,

* ,

DIV • MOD , or any of the standard functions

pred. succ, ord, tsize (14.3). FunlH.!rmore. in a const:mt expression,

the use of a type transfer is allowed. Examples: n - 100 nl .. succ(n) nd2 • nl DIV 2 + 1 en • char(nd2) minint - 100000B maxint.. 77777&

yes text - 'YES'

compl_i • complex(O.O. 1.0)

(17)

Modular Pascal Page 11 6. Data ty~ defin1t1on$

A data type determines the set of va1u~s which variables of that type may assume, and associates an Identif1~r with the type.

(type> ::- (simple type>

I

(structured type>

I

<pointer type>

I

<packed type>

I

(type identifier> (type identifier> ::- (identifier>

(type definition>

::-{(export sym>J<type identifier>-(type)

0.1. Simple ~

<simpl~ type> ::c <ordinal type)

I

<real type>

<ordinal type> ::= (enumeration type)

I

<subrange type)

All ordinal ty~s define ordered sets of values. for whi ch a first and a la.st element is defined, tht, orderlnr, between which is determined by a successor function, and between which an ordering relation can be applied. If t is an ordinal type, et an expression of that type and vt Is a variable of that type. then th£' following functions apply:

succ(et) the value in t, immediately following et provided et is not the last value in t pred(et) the value in t, immediate Iy preceding et

provided et is not the fi r st value in t first(vt): the first value in thE' type t

last(vt) : the last value in tht2 type t

An enulllt:'ration typt> definE'S an ord~'red St't of values by enumeration of all the identifiers which denute these values.

<enumeration type) ::= «identifler)I,<identifier)}*) E xamp les:

(red, orange, yellow, green, blue) (club, diamond, heart, spade)

(monday, tuesday. wednesday, thursday, frjday, saturday, sunday)

The identi fiers reprt!senting the values of an enumerati on type satisfy the definition of constant.

The values in an enumeratIon type C3n be mapped 01lto the I nte ger numbers 0, I, 2,. •••• , taking thelU in left to right order. If et is an expression of an enumerati on type t • then this mapping Is the result of a func t1 on

ord(et) ; the ordi nal numbr.?r of the value e t in the type t.

(18)

Modul ar Pa sc al Page 12

identifier t as a transfer functton. If Ie Is an t>xpression of type

1 nteger (see b.l. 2), the valul' of whic h lies withl n the range

first(t) •• last(t), then the following equality holds

ord ( t (1

e» •

i e.

A type may be defined as a subrange of another ordinal type by

indication of the smallest and largest value in the subrange. The

first constant specifies the smallest value, which should not be

larger than the second constant.

<subrange type> ::- <constant> •• <constant> Examples:

1 .. 128

-tIS •• (tIS - 1)

monday •• friday

6.1.2. Standard ~

The followIng types are standard in Pascal:

integer: The values are a subset of the whole numbers, given by the

subrange minint •• maxint, where minint and maxint are two

predefined identifiers, standing for tht> constants -2A

lS and 24

15-1 respectively.

real: The values are a subset of the rational numbers as formed by

the standard PDP1l representation of floating point numbers.

The relative precision of the representation Is

approximately 10·-7. The largest number represented In this

way is approximately 2A127 - 10~36. The smallest number

differing from zero is 2A

-129 - 10·-36. The values of type

real form an ordered set of values. The predefined type

real is the only type which satisfies the definition of real type.

boolean: The values are the truth values denoted by the identifiers

true and false. The type boolean is an enumeration type,

which could have been defined as: boolean • (false, true)

char: The values are the (128 elements of the) ASCII set of

characters. They are denoted by the characters themselves,

enclosed within apostrophes. Not all ASCII characters can

be denoted this way as they have no visual representation.

Howevere, every character can be represented by the type

transfer char, which performs a mapping from integer values

in the range O •• 127 to ASCII character values. Thj s

mapping, and the ordering between characters Is determined

by the ASCII standard. The type char satisfies the

definition of ordinal type.

6.2 Structured ~

A structured type Is characterized by the type(s) of its components

and by its structuring method. <structured type>

(19)

::-Modul ar Pascal Page 13 (array type) I <record type) I <set type) I (file type)

An array type is a structure consistIng of a fixed number of components which are all of the same type, called the component ~.

The elements of the array are designated by indices, values belonging to the so-called ~~~~ sy~. The array type definition specifies the component type as well as the index type.

<array type)

::-ARRAY[<index type){(rangc s~p)(index type)}*] OF (component type> <index type> ::= <ordinal type)

<component type> .. (type>

<range sep> ::= ,

I

J OF ARRAY [

If n index types are specified, the n-dimensional, and a component can be However, for n > 0 a single index selects 3

(n-l)dimensional array. Examples (of array types):

ARRAY [0 •• 100] OF real

ARRAY [1. .100, 1. .20] OF O .• maxint ARRAY [color] OF boolean

array type is called designated by n indices. component, which is an

A value of an array type can be formed by an array constructor <array constructor) ::=

(type identifier)«expression){,<expression>}*)

The type identifier must be the idl'nti fier of a (one dimensional) array type. However, eac h Il-di mens i anal array may be concei ved as a one dimensional array with an (n-l)dimcnsional array as component type (for n > 0). All expressions must be of the component type of the array. The number of expressions must equ~l the number of values in the indextype of the array. The v~llles of the expression taken in left to right order correspond to the values of the array components taken in the order of increasing index. If all the expressions are constants, then the array conhtruclor is a structured constant.

Example: if char3 = ARRAY [0 •• 2] OF char, then

char3('Y', 'E', 'S') is a (constant) value of type char3.

Note: The above constant is 110t the Silme as the string 'YES' because char3 is not a PACKr.n ARRAY.

A record typ~ defines a structure of R fixed number of components,

possibly of different types. The record type definition specifics for each component, called a fiel,~, its type and an iclenti fier to denote the field. A field identifier proddes access to a component of a record variable, either by melns of a field designator (see 7.2.2.), or on account of its appearance in a with statement (see 9.2.4.).

(20)

Modular Pascal Page 14 A record may have several variants, in which case a certain field may

be designated as the ~S i~~~~. the value of which indicates which

variant is currently assumed by the record variable. Each variant

structure is identified by a case label which is a constant of the

type of the tagfield. Since the language d~s not enforce the use of

a field designator to be in accordance with the current variant,

variants defy any form of type ch~cking and should therefore be used

with utmost care.

The appearance of a tagfield in a record with a variant part Is

optional. Use of a record structure without a tagfield implies that

the current variant can be estab1isl~d by other means than inspection

of the tagfield. If a subrange appears as a case label, this is

equivalent to the appearance of all the constants belonging to the subrange in the corresponding case label list.

<record type> ::- RECORD <field list> END

<field list> ::- <fixed part> I {<fixed part>;}<variant part>

<fixed part> ::- <record section> {;<record section>}* <record section>

::-<field identifier>{,::-<field identifier>}* : <type>

<variant part> ::=

CASE {<tagfield>:}<type identifier> OF <variant>{;<varlant>}*

<variant> ::- <case label list> : «field list» <case label lIst> ::- <case label>{,<case label>}* <case label> ::= <constant> I <constant> •• <constant> Examples:

RECORD day: 1 •• 31;

month: 1 •• 12;

year: integer END

~CORD name, first name: alfa;

age: 0 •• 99;-married: boolean END RECORD x, y: real; area: real; E~ CASE s: shape OF

triangle: (side: real;

inclination, anglel, angle2: angle); rectangle:(sidel, s1de2: real;

skew, angle3: angle);

circle: (diameter: real)

RECORD real_part, 1m_part: real E~D

A value of a record type can be formed by a record constructor. <record constructor>

::-<type identifier)«field value list)}

(21)

Modular Pascal

{(expressi on), }*<expressi on>

{(expression),}*<varlant constructor>

<variant constructor> ::-<constant>:«field value list»

Page 15

The type identl fil.'r must be the j denliller of a record type. In a variant constructor the constant must be of the type of the tagfield. The expressions in the field value list represent the values of the fields taken in the left to right order of the field identifiers in the record type definition. I f all expressions 1n a record constructor are constants, then the record constructor 1s a structured constant.

Examples of a record constructor: geometric figure{l.S, 2.5, (*x, y*)

- 4.0 (*area*), circle: (2.0 (*diameter*) ) ) rotatlon2(v2(sin(phl), cos(phl», v2( - cos(phi), sin(phi» ) complex{O.O, 1.0)

The firot example satisfies the definition of structured constant. The latter example is a constant, representing

1,

assuming complex to be defined as in the last example of record types.

6.2.3. Set ~

A set type definl's the range of val lies which is the set of all subsets of its so-called ba~~ U'~~. Basl' types must be ordinal types. The base type of a set is restricted to enumeration types with at most 128 elements, the standard type char, and subranges of type integer confined within the range 0 .• 127. Operators applicable to all set types are: + union set di fference

*

Intersection IN membership

<, <=,

>. >=

the subset relationR. = <>

equality, c.q. inequality

The set difference x - y is defined as the set of all elements which are not elements of y. The suhset relation < is defined < y iff {x (= y) At-."D (x

<>

y). The opl'rations are only allowed base types of both operands (or thC' type of the left operand are subranges of the same ordinal type.

<set type) ::- SET OF <base type) <base type> ::z <ordinal type)

A val ue of a set type can be [tlrmed by a set construc tor:

of x by: x t f the of It\)

(22)

Modular Pascal Page 16

<set constructor> : :-I<e1ement){ ,<element)}·]

I

I ]

<element> ::~ (expression>{ •• (expresslon>}

Expressions which are members of a

which is the base type of the set.

form e1 •• e2 denotes the set of all

el and e2.

set must all be of the same type,

[ ] denotes the empty set, and the values in the interval defined by

If all the expressions in a set constructor are constant, then the set constructor is a structured constant.

6.2.4 File ~

A file type definition specifies a structure consisting of a sequence

of components which are all of the same type. The number of

components called the length of the file, is not fixed by the file

type definition. A file with 0 comporu·nts is called~. The

components of a file are indexed I •• length of file, but there is no

direct indexing operation. (For more -details, see 15. on file

handling procedures.)

<file type> ::= FILE OF <type)

The type of the file components can not be a file type or a structured type containing a file type.

The file concept is only available provided the definition of the file

type is imported from some other module by the name of "f_fyle". (See

13. for the meaning of importing.)

6.3. Pointer ~

Variables which are declared in a program (s~e 7.) are accessible by

means of their identifier. They exist during the entire lifetime of

the procedure or module in which the vilTlable is declared. In

contrast to variables, the lifetime of which is bound to a block,

variables may also be generated dynamically, i.e. without any

relation to the syntactic structure of the program. These dynamic

variables are generated by the standard prxedure new (see 14.5.);

since they do not occur in an explicit variable declaration, they

Cdnnot be referred to by e name. Instead, access is achieved via a

so-called pointer value which is provided upon generation of the

dynamic variable. A pointer type thus consists of an unbounded set of

values pointing to elements of the same type. No operations are

defined on pointers except the test for equality. A pointer value may

also be delivered on account of a type transfer (see 14.6.2.).

The pointer value NIL belongs to every pointer type; it points to no

variable at all.

<pointer type) ::= A<type identifier'>

If the component type of a file is or contains a pointer type. the

pointer values occurring in such a file may refer to objects that were

in existence when the file was writt,-'n but may not exist anymore when

(23)

Modular Pascal Page 17 discussed h~re, the pointer values mrty still b~ considered as object identifications.

<packed type) ::- PACKEU <struc tured type)

The use of the prefix PACKED in th~ definition of a structured type indicates that for the components of the structured type a compact represt?ntati on may be chosen( I.e. mor~ that one component may ff t 1 nto one word of the tar get mach! n~). This means (in general) that access to components of such types may be more time consuming than if the type were not packed. In return, the use of the PACKED prefix may cause a more economic use of storage. Apart from the above, there is no distinction 1n the properties of a structured type. whether packed or not. In particular, components of packed structures may be passed as actual paraparaDleters for formal parameters of mode VAR (in which case they w1ll be treated as value/r~sult parameters), and components of a packed structure may act as a variable in an update statement (9.1.2).

Tht! following component tYVes are cand1dates for packing in array structures:

-char

-subrangcs of type intt'gt'r confined within the range O •• 255 -enumeration lypes with no more than 256 elements.

The "sizes" of the above types 3re as follows: -char: 8

-enumerated and subrange types: n, where 2A

(n-l) <= ord(last(t» ( 2A o In record types ,besIdes the

wit hi n the ran

e

eO •• 2 A 1 5 -1 1 s 3 packed structures onto words follows:

above candjdates, any subrange type

can~idate for packing. The mapping of of the tar get mach! ne proceeds as packed !.~<:.~~d. ill~: A compact repr.:>sentatlon of the components is

cho~en in th~ following way: The field identifiers of the record type are considered in left to right order. As long as they denote packable components, the sum of thdr sizes not exceeding 16, these components (sizes sO, 51, 52, .•• ) are packed into one word, mapped onto the bits: 0 .• sO-I,50 •• s0+s1-1,s0+51 •• , where the least significant bit within a tareet machine word corresponds to the least sl gni ficant bi t of th" rl'cord component. Kon-packable components are allocated as many w0rds as they need for their rt:'presentation. The process of potential packing proceeds until all components of a record strllc t ure have been allocated.

packed arr'!.I ~nd f~~~ !..Y..£~~: For a component size 5

>-

6, two components ar~ mapped onto tile two bytes withi n a PDPll word, where the lowest addressed byte contains the lowest indexed component. For a COl1ll'ont'nr si ze s (= 5 the components are mapped as descri bed

for packed records, where the numh~r of compon.:>nts pt?r word equals 16 OIl,' s. Within a word, COmp()lwllts are mapped onto increasingly more significant portion of the word as the index increases.

(24)

Nodular Pascal Page 18 The predefined type text is equivalent to the type definition

text

=

PACKED fILE

OF

char

However, procedures operating on files of type text consider such a text as to be structured into lines. This structure is encoded in the file by means of ASCII characters~-but the encoding characters are not accessi ble as f He components. Tht' encod! ng can be made vis! ble by

tr~ating such a file as PACKEn FILE OF char, and not as text. Files of type text are not indexable.

Examples of type definitions; color sex text shape sui t card hand aHa person

• (red, yellow, green, bllle)

=

(male, female)

=

PACKED FILE OF char

=

(triangle, rectangle, circle) • (club, diamond, heart, spade)

=

RECORD s: suit; val: 2 .• 14 END

- ARRAY [1 •• 13] OF card

- PACKED ARRAY {l •• IO] Of char

RECORD name, firstnamt': alfa;

age: integer;

END

married: boolean;

father, child, slhling: Apt:'rson;

CASE s: s ... x OF

male: (enlisted, bald: boolean); female: (pregnant: boolean;

size: ARRAY!l .. 3J OF integer)

6.5 String ~~~

Types of the for,m PACKED ARRAY [<indC'x type>] OF char, are called string types when index typl' Is (a suhr,wge of) type integer. The strings introduced 1n chapter 4 arc the constants of thes~ types, Where the number of characters In the strIng should match the number of values in the index type.

Types appearing in different places in a program text are identical i f the same typt:' identifier is useJ 1n these places, or if different identifiers are used which have been defined to be equivalent by type

d~finitions of the form

type identifierl

=

type identifier2

Two types are called compatible i f they are identical, or i f one is a subrange of the othE'r, or if both ar\? subranges of the same type, or i f they are stri ng types wi th the sam(' number of components, or if they are set types with compatible base tn)('s.

(25)

Modular Pascal Page 19 7. Declar<ll Ions ;lI1d d~'l1otaLl cns of v,lrl d bIt·"

---Variable declarations consist of a list of identifiers denoting the new variahles followed by their type, and (optionally) of the memory location they are to occupy.

<variable dec1arati on> ::= <export varl ist>: (type> (export varlist> ::- (export var>I,<export var»*

(export var> ::= {(export sym>}<vari~hle ldentifler>{@(constant>) <variable identifier> ::= <identifier>

Every declaration of a ftle variable f with components of type t implies the additional declaration of a so-called buffer variahle of type t. This buffer variable is denoted by fA and provides-access- to the so-called "current" file compon(-nt.

VariahlE's of a file tyPt' or of a tYPI! conl.li ni ng a file type may only be declared at th~ modul~ level. Furthermore, within such n module an initialization procedure must bl' imported with the following heading:

PROCEDURE f_initfyle(VAR f: FILE; txt, pck: boolean; compslze: integer); Examples of variable declarations:

x,y,z: real u , v: com p 1 e x i , j: 1 n t (: be r k: 0 •• 9

p. #isdef: boolean

operator: (plus,minus, times) a: ARRAY [0 •• 63) OF real

b: ARRAY [co1or, boolean] OF complex elr of component: color

f:

FILE

OF chClr

huel,hue2: !iET OF color son: person

clock_registc:r @1725t.Ol.l: intl'g\?r

Denotations of vartabl(os dtht'r dt.'slgnal~' an t'ntire variahle, a component of a variable. or 3 variable referenced by a pointer (see

6.3). Variahles occurring in ('xami'les In subsequent chapters are assumed to be d~clared as indicated above.

(variable> .. = <entire variable>

I

(component variable>

I

<referenced variable>

The consequences of thf' ('xportation of variahl.:>s are discussed in chapter 13.

7.1 re Variables

An entire variable is denoted by its identifier. <entire variable> :;= (v<Jriabll' idt nti f ier>

(26)

~1odular Pascal Page 20

7.2. CO~:ten~ va!:.ia~!El.~

A component of a variable is denoted by the variable, followed by a

selector specifying the component. The form of the selector depends

on the structuring of the variable.

<component variable> ::- <indexed variable>

<field designator>

I

<file buff~r>

7.2.1. Indexed variables

A component of an n-dimensional array is denoted by the variable.

followed by k ( 1 <- k <= n) index expressions.

<i ndexed variable> ::=

<array designator><indices>

<array designator> ::- <array variable>

I

<row>

<array variable> ::- <variable>

<indices> ::- «expression>f<index sep><expression>J*]

<index sep> ::- •

I

J [

The types of the-index expressions must match with the index types

declared in the definition of the arTilY typt' , or specified in the row

parame ter • Examples:

a[l2 ] ali + jj

b[red, true]

(for the meaning of the row concept S€'l' 11.1)

A component of a record variable is denoted by the record variable,

followed by the field identifier of the component.

<field designator> ::= <record variable>.<field identifier>

<r~cord variabl~> ::= <variable>

<field identifier> :;= <identifier>

Examples: u.real part

b[red,-trueJ .im_part 7.2.3. File buffers

At any instant, only the compon~nt d~t~rmined by the current component

index of a file is directly access:lhh'. This component is called the

current file component and h reprt'senten by the file's buff<:.~

variable.

<file buffer> ::= (file variab1e)A

(27)

~lodll].lr Pascal

7.3. Ref~[~nc~d varlabl~s

<rl'fl'r\;'nr~'d varlabl(» ::= <polnt,>r v.!rL1bll')-<pointer variable) ::= <variable)

Pagt! 21

If p is a pointer variabl~ which is hound to :1 type t, then p denotes

that v.ulahlc and its pointer vallh', whereas p- denotes the varIable of type l fL' ft'[cnced hy p.

Examples:

50n-.father

(28)

Nodular Pascal Page 22

8. Expressi ons

Expressions are constructs denoting rules of computation for obtaining

values of variables and generati n~ new values by the npplication of

operators. Expressions consist of operands, i.e. variables and

constants, operators and functions, or may be formed by constructors.

The rules of composition specify op~rator ~reced~~ according to

f our classes of operator Ii>. The operator NOT has the hi ghest

precedence, followed by the so-called mul tiplying operators, then the

so-called adding operators, and finally, with the lowest precedence,

the relational operators. Within a sequence of operators of the same

priority, the order of evaluation is from left to right. It is not

guaranteed that all operands wIll indeed be evaluated, in those cases

where a partial evaluation may already yield the result. Some care

must therefore be exercised when using function designators with side

effects. The rules of precedenc\' are reflected by the following

syntax:

<factor> ::= <variable>

I

<integer d~notation> I<string)

<real denotation> I <factor from const>

I

NIL I

<function designator>

I

<sel constructor>

I

<array constructor)

I

<r~cord constructor>

I

«~xpression»

NOT <factor>

<factor from const> ::= <const or constpar>«selection)}

<const or constpar) ::= (constant identifier>

I

<const parameter>

<const parameter> ::- <identifier>

<selection> ::= <indices){<selection>}

I

.<field identifier>{(selection>}

<term> ::= (factor){(mult op><factor>}*

(simple expression) ::= (<add op>}<term>{<add op><term)}*

(expression) ::=

<simple expression>{<rel op><simple ~xpressfon>J

A factor can be derived from a defined constant or ,from a formal

parameter, specified as a constant. The selection that may be applied

in case of a structured constant is det~rmin0d by the type of the

constant. Examples: Factors: Terms: x 777B (x+y+z) ~Yes" [red, c. green] complex(x, Y + 1) NOT isdef y~s_text[2J x

*

y i / ( 1 - i ) isdcf MID (a

<

0) (x

<=

y) t\l'\D (y

<-

x + 4)

(29)

Modular Pascdl Simple expressions: x + y Expressi oos: - x hll\.·l + hlll'2 (*/lilll<': SC't union!*) i

*

j + x • 1. S isdef ., (a '" b) c IN huel Page 23

If both operands of the arithmetic operators of addition, subtraction and multiplication arLO of type inlegL'r (or a subrange thereof), then the result is of type intl'ger. If one of the opc·rands is of type real, then the result Is also of type real.

T~t' operator NOT denutes negation of its boolean operand.

<mult op> ::=

*

J /

I

Dl\'

I

MOD

I

Al\D

I

CA!\D

The op('r3tor

*

dt:'nott's multiplicatl'JIl for integer <lnd real operancls. and intl'rsection for operands of a !;('t type.

The operator / denotes division for integer and rcal operands. The rt,'sul t is al",,:~~ of type real.

The operator DIV denotes remainder-less division far integer operands and yields a result of tYJ.!t: integer. For a )= 0 and b ) 0, the result of DIV is defined by 0 (= a - (a Dl\, h) 7< b

<

b, and the result of MOD by til(.> tel.ainn: (a DJ\' b)

*

b + .:l N(lD b '" a. For oth€'r values of a

and h th~' n'sult of Dl\, und ~lOLl is llOt dt·fined.

The operator MW yidds thl' result of the logical "and" betlO'een two operands of typl' hoolean. A!\D mil) also be uSc'd as an a1 ternati v('

repr~s~ntation [or

*

wh~n set int€'rsecllon Is intended.

The operator CA:\n has till:' sam(' mdtht'malical mt.'aning as the logical operator AND hut should be used whe'n th(· resul t o[ the right operand is only defined provided the left operand yields trUI? CAND stands for Condition31 A1\D.

<add op> ::= +

I -

lOR

I

COK

The operator + denotes tht:' addition of two op('rands of type integer or real, or the union of two op, .. rands of;J 8,'t type.

The operator - denotes the subtraction of th~ right operand from the left operand. Subtraction is dl'fin('d for operands of type real or integer, or between two operands of set type (sec 6.2.3.),

The operators + amI - may also bl;' used with a right operand only (of type int~'ger or real) and then dt;'note th~' idpntity operation and Sif,D

invt;'rsion respectively.

The operator OK denotes the logical "or" between two op~rands of type boolean. 01< may also be used as .In ill tt:'rn.lti VI;' representati on for +

(30)

l-lodular Pascal Page 24 mathematical meanine as the logical operator OR but should be used when the result of the right operand is only defined provided the left operand yields false. COR stands for Conditional OR.

<reI op> ::- -

I

<>

I

<

I

<=

I )- I

>

I

IN

The operators

<>.

<=, )- stand for unequal. less or equal. and greater or equal resp~ctively.

The operators = and <> are defined hl,twt!en any two operands of the saine type except a file type. Tht, op.:>rator IN is defined between an operand of a set type as a right operand and an operand of Hs base type as a left operand and denotes set membership. The result is of type boolean.

Th~ ordering relations <,

<a,

>=, > are defined for the following cases: when both operands are of 3 simple type. when both operands

are of a set type (with the same base type), when both operands are of an identical pointer type, and when both operands are of compatible string types. In the latter case the ordering of the strings is defined accordin~ to the collating sequence of the ASCII character

set.

\\!1H:'n two pointer values are compared, the resul t is that which is

d~livered by comparing the two addr~sses representing the pointers on the target machine.

A function designator specifies the .3rtivation of a function. It consists of the identifier denoting the function and a list of actual parameters. The parameters ar~ variables, expressions, procedures, functions and slices, which will bl" sllbstituted for the corresponding formal parameters (cf. 9.1.3.).

<function designator>

::-<function identifier>{«actual parameter list»} <actual parameter lIst>

::-<actual parameter){,::-<actual parameter>}* <function identifier) ::= <idenlifier)

Expressions of structured typ~s take tl~ form of a function designator or a constructor. Apart from constructors for a variant record type, constructors have the same syntactic form as function designators. Since such expressions do not satisfy the definition of variable, there is no direct way to select a comronenl from such an expression. They may, however, be used in three ways:

(1) as an operand to a relational op~'rator,

(2) as an argument (actual parameter) in n procedur~ or function call, (3) as the value to be used in nn 3hS1 gnmC'nt stdtt"ment.

(31)

Modular Pascal Page 2S 9. Statcmt:'nts

Statements denote algorithmic actions, and are said to be executable. They may be prefixed with a lab~l, which may serve as the destination of a goto s tatemellt.

<statement> ::- <unlabelled statement>

I

<lahel>:<unlabdled statement>

<unlabelled statel.lent> ::= <simple statement> <struc tured st.ltement>

<label> ::= <inteher denotation> 9.1. Simpl~ statements

A simple statement Is a another ata temenl. The denotes no action.

statement, no part of which constitutes empty statement consists of no symbols and

(simple statement.> ::= (assignment statement> <update s tateml'nt>

I

<procedure statement> <exception statement>

I

<goto statement>

I

(empty statement>

<empty statement> ::- (empty>

The assignment st.ltement Sl'rvt'~ to r!:'pl .lce the current value of a variable by a lIew val Ill'. being the result of the evaluation of an t:.' xpressi on.

<assignml'nt statement> ::= <variable) :- (expression) <function idenlifier>t(s~lection)} := (expression)

The second form of assignment ~tateme"t is used to define the result of a function (within the function body).

When an expressi 011 of type et f sass! p,nt'd to a vari able of typl:' vt, et

must bl.' assignm<'nt-compatible with th~ type \/t. Thjs is the case i f

any of tht:- following five statements is truC'.

(l)vt and ct are identical and fl('ither is a file type, nor a structured type with a component of file type.

(2)vt Is the type real and et is (11 sllhrange of) the type integer. (3)vt .:lOd et ar~ compatibh> ordinal typl:'S and thl:' value of the exprt:ssion lies within the closed interval specified by the type vt. (4)vt and et are compatIble set types and all the members of the set expression lie within the closed interval specified by the base type of vt.

(S)vt and et are compatible string tYpt'S (see 6.6). Examples:

x :- y + z

inrBllge ;= (l (= 1) ArW (i ( 100) i := sqr(k) - i

*

j

Referenties

GERELATEERDE DOCUMENTEN

Albert Philipse (a.p.philipse@uu.nl), Chemistry Department (Utrecht University), in collaboration with the History of Chemistry Group (Royal Netherlands

Either all the organizational costs are allocated to projects, or the present value of a project has to be definitely positive in order to keep the organization going.. Some

12 This understanding of variant readings in Qa is substantiated by other passages in the Qumran documents, which show that the members of the Qumran community regarded the

5, we use the rules regarding the dominant pair to show that for each generic type there are two possible arrangements of the unique and binding folds on the first branch (u and b)

THE MINORITIES IN CEYLON, 1926-1931 WITH SPECIAL REFERENCE TO THE DONOUGHMORE COMMISSION.. by QUINTUS

The second question raised by the Dutch trends in prisoners rates is how movements in crime in the Netherlands and/or in the sentencing tariffs of the Dutch courts can

While in the works of Elzevier and de Haes the context of a literary society implied a first step towards an enlargement of the public sphere, van Belle took

2 The differences in origin, nature and fundamental principles between Islamic law and indigenous customary laws, especially in relation to marriage and the status