Appendix A: Syntax Diagrams

Chapter 3 provides a syntax diagram for every language element of Modula-2. These diagrams have been collected in this appendix for easy reference when questions arise concerning the formulation of particular program constructs. The syntax diagrams are listed and numbered in the same order as in Chapter 3. The following alphabetical list is intended to assist in locating individual syntax diagrams.

ArrayType19 OctInteger6 Assignment.41 ParamSection53 B 12 PointerType25 CaseLabelList24 PrioritY67 CaseStatement.43 ProcedureCa1l55 ConstantDeclaration26 ProcedureDeclarationso ConstExpr27 ProcedureHeadings1 DecInteger5 ProcedureType57 Declaration 13 ProgramModule11 Definition63 Qualldent2 DefinitionModule62 Reals Designator31 RecordType20 Element39 Relation33 Enumeration 15 RepeatStatemen~s ExitStatemen~s RetumStatement56 EXport61 Set3s Expression32 SetType17 Factor37 SimpleExpression34 FieldList21 SimpleType1s FormalParameters52 Statemen~o FormalType54 S tatementSequence 14 FormalTypeList5S String9 ForStatemen~6 Subrange 16 HexInteger7 Term35 Ident1 Type29 IfStatemen42 TypeDeclaration28 ImplementationModule65 TypeDefinition64 Import60 TypeTransfer 66 Integer4 VariableDeclaration3o LoopStatemen~7 Variant23 ModuleDeclarations9 VariantFieldList22 MulOperator36 WhileStatemen44 Number3 WithStatemen~9 OctChar10 Appendix A: Syntax Diagrams 235

Qualldent2

Number3

Integer4

Declnteger 5 1 Octlnteger 6 I Hexlnteger 7 ~

Declnteger5

OctInteger6 236 Appendix A: Syntax Diagrams

HexInteger7 ,~4CJ)44?4~1 ~~~~------~-~.~

Rea1s

o 0character~ r~Chafficter~ :~ ~ OctChar 10 .1------'''--... OctCharlO

ProgramModulell

~~~~....L""I Block121-~lldent1 1-0--

Block12

Declaration 13 ---""'------..J---ot"_( BEGIt\D-- StatementSequence 14 Appendix A: Syntax Diagrams 237

Declaration 13

ConstantDeciaration 26

Variable Declaration 30

ProcedureDeclaration 50

_.L-__..... I ModuleDeciaration 59 I-----....::=..~~

StatementSequencel4

----~o~.. ------'=1 State~ent 40 ~

Enumeration 15

Subrangel6

~ Qualldent 2 tJ--CD--l ConstExpr 27 ~I ConstExpr 27 ~

SetTypel7

-@-®--I SimpleType 181-

SimpleTypel8

Qualldent 2 19Enumeration 15 1Subrange 161 • 238 Appendix A: Syntax Diagrams

ArrayType19

- ( Q •. 1 -(ARRAY~I SimpleType 18 ~~I Type 29 r--

RecordType20

,-----lQI4.-~ -(RECORD~I FieldList 21 ~~ Fie1dList21

o-lType29~

'----I VariantFieldList 221---,./

VariantFieldList22

.(CASE~lldent1I;--o-l Qualldent2~ OF

Variant23

CaseLabelList 24

CaseLabelList24 o· ~ ConstExpr 27f---.rO=:l ConstExpr 271, J• Appendix A: Syntax Diagrams 239

PointerType25

-CPOINTER)-®---I Type 29 ~

ConstantDeclaration26

-ildent 1 ~0-1 ConstExpr 27 ~o-

ConstExpr27

-I Expression 32 ~

TypeDeclaration28

_lldent 1 ~G-I Type 29 ~o-

Type29

SetType 17 ~-......

Simple Type 18

ArrayType 19 t---..J

VariableDeclaration3o

~o--I Type 29 1--0-- 240 Appendix A: Syntax Diagrams

Designator31

1....-----1 Ident 1

}+.--..!Io.--1 Expression 32 - Qualldent 21--~------L-""

Expression32

- Simple Expression 34 I Relation 33 ~ SimpleExpression 34

Relation33

SimpleExpression34

Term35

MulOperator 36

---=~--1.~1 Factor 37 I--~'--.

MulOperator36 Appendix A: Syntax Diagrams 241

Factor37

Q.-..-----..) ·1 Designator 31 ( 1 Expression 321 CD ~ ., .. a>r

Number 3

·l String 9

Set 38 CD---I Expression 32 ) NOT - 1 Factor371 ~

~. ) .CD• LI Qualldent 2 tr-CD \ JI8Il1int 391 ! Element39

-I Expression 32 ~o---.I Expression 32 tr- 242 Appendix A: Syntax Diagrams

Statemenl40

Assignment 41

If Statement 42

Assignmen41

-I Designator 31 ~G--I Expression 32 ~

IfStatemen42

r------~~EL~S~IF~~------­

I Expression 32 ~C!B:®--- StatementSequence 14

'----~.. ~ StatementSequence 14 @Q)f------. Appendix A: Syntax Diagrams 243

CaseStatemen43

------•• @@-I Expression 32~ OF )------

'"--=-...... 1 CaseLabelList 24~o--. StatementSequence 141-:r--"~

'----...... ill@--- StatementSequence 14 @@I----_.

WhileStatemen44

-CWHILE}--I Expression 32 ~ StatementSequence 14 ~@Q)-­

RepeatS tatemen45

-(REPEAT}---I StatementSequence 14 ~(UNTIL}---I Expression 32 ~

ForStatemen46

--~lldent 1 1--0-1 Expression 321--CIQ)- Expression 32

ConstExpr 27 ®---I StatementSequence 141--~

LoopS tatemen47

-~I StatementSequence 14 ~~

ExitStatemen4s

WithStatemen49

-@ITB)----I Designator 31 ~@--I StatementSequence 14 ~@Q)-­

ProcedureDeclaration50

-I ProcedureHeading 51 ~I Block 12 ~@Q)---Ildent 1 ~o- 244 Appendix A: Syntax Diagrams

ProcedureHeading51

-CPROCEDURE}--Ildent 1 ~I FormalParameters 52 r-0--

FormalParameters52

r---~O"·--""", ~CD \(1 ParamSection 531 J, "CD----x:0--1 Quallden. 2 r- ParamSection53

L@!D, ~0--1 FormaIType"i--

FormalType54

LCARRAY}-@y--I Qualldent 2 ~

ProcedureCa1l55 0,.·---.

-I Designator 31 ~,-_CD_(_l_l_I_E_xp_re_S_S_io_n_32_I_J_ !__ ·_T~

RetumStatement56

-CRETURN~I Expression 32 r-

ProcedureType57

-CPROCEDURE~I FormalTypeList 58 r- Appendix A: Syntax Diagrams 245

FormaiTypeLists8

~CD l \' ~:nnaITYpe "I lJ ·

ModuieDeciarationS9

-----... (MODULE}.-Ildent 1 ~I Priority 67 fy- ;J---- ......

I Block12~ Ident, ~o--

Import6o

Lill!Q!\I[)--lldenl, Iy---(lMPORT~O--

EXport61 ~(EXPORT>----r-(QUALIFIED)f ~o--

DefinitionModule62

-(DEFINITION)---.(MODULE)--Ildent 1 ~ ; ~"------"'''

Definition 63 '-----~----....L.._@IQ)_Ildent 1 ~Of-----· 246 Appendix A: Syntax Diagrams

Definition63

ConstantDeclaration 26

TypeDefinition 64

VariableDeclaration 30

ProcedureHeading 511 •

TypeDefinition64

-ildent 1 ~0-1 Type 29 tJo---.

ImplementationModule65

-OMPLEMENTATION}--I ProgramModule 11 ~

TypeTransfer66

-I Qualldent 2~CD--1 Expression 32~CD--

PrioritY67

-CD--I ConstExpr 27t-(j)- Appendix B: Predefined Identifiers

Modula-2 contains a number of predefined identifiers for constants, elementary data types and standard procedures. The following summary provides an overview of what they mean. A more detailed explanation can be found in Sections 3.4.1.1 ("Predefined Data Types") and 3.7.8 ("Standard Procedures").

Predefined Constants FALSE boolean "false" NIL POINTER value that points to no object TRUE boolean value "true"

Predefined Data Types BITSET BOOLEAN logical values "true" or "false" CARDINAL natural numbers (~O) CHAR characters INTEGER whole numbers (positive or negative) PROC parameterless procedures REAL real numbers Standard Procedures DEC (x) reduces (decrements) the value of x by 1 DEC(x,n) reduces (decrements) the value of x by n DISPOSE(p) frees the storage to which p points EXCL(s,e) removes (excludes) the element e from the set s HALT terminates program execution INC (x) increases (increments) the value of x by 1 INC(x,n) increases (increments) the value of x by n INCL(s,e) includes the element e in the set s NEW(p) allocates dynamic storage Standard Functions ABS (x) returns the absolute value of x CAP (ch) changes the ch to a capital letter CHR(c) returns the character whose ordinal number is c FLOAT (c) transforms the CARDINAL number c into a REAL number HIGH (a) returns the highest index of the array a MAX(T) returns the greatest value that can be represented by the T MIN(T) returns the smallest value that can be represented by the data type T ODD (x) returns the boolean value of the expression"x is odd" TRUNC(r) transforms the REAL number r to a CARDINAL number VAL(T,c) returns the value of data type T having the ordinal number c Appendix C: Compatibility Rules

The strict type concept in Modula-2 forces the programmer to keep in mind which data types are compatible under which conditions. All the respective rules were covered in Chapter 3, but they are spread throughout the entire chapter. Thus we have summarized all the rules governing compatibility in this appendix.

Type Identity (see Section 3.4.5) The two objects x I and x2 with the data types t I and t 2 are of the same data type if one of the following conditions is met:

t I and t 2 are identified by the same name, e.g.:

VAR VAR n: INTEGER; material: Material; val: INTEGER; substance: Material; xl and x2 are declared within the same variable list, e.g.:

VAR n, val: INTEGER; PROCEDURE P (x, y: CHAR) ; die,dot: [1. .6];

t I and t 2 are identified by names that are designated as synonyms in the type declaration, e.g.: TYPE TYPE Minute = [0 .. 59]; t = (a,b, c) ; Second = Minute; tl = t; VAR t2 = t; sec: Second; VAR min: Minute; xl: tl; x2: t2; xl and x2 are constants o/the same enumeration type, as low and high or red and yellow in these examples: VAR VAR voltage: (low,high); color: (red,blue,yellow); Type equality is required with V AR parameters The data types of formal and actual parameters must be the same. Exceptions: If the formal parameter is an ARRAY parameter, only the element types must be identical in the formal and actual parameters. ADDRESS is compatible with CARDINAL and with all POINTER types. Appendix C: Compatibility Rules 249

WORD is compatible with every data type that occupies exactly one word of memory. ARRAY OF WORD is compatible with any and all data types. with procedure variables

If a procedure P is to be assigned to a procedure variable pv, the parameters of all data types in P and pv must be identical. If P and pv are function procedures, the data types of their function values must also be identical.

Expression Compatibility (see Section 3.5.5) Two operands x 1 and x 2 with data types t 1 and t 2 are expression compatible if any one of the following conditions is met: t 1 and t 2 are the same data type. t 1 is a subrange type with base type t2 (or vice versa). t 1 and t 2 are subrange types with the same base types. t 1 is INTEGER or CARDINAL and t 2 is a subrange type (or x2 is a constant) in the range [0 .. MAX(INTEGER) 1 (or vice versa). The value of MAX (INTEGER) depends on the particular computer used, but in any case it is the largest INTEGER that can be represented (which is simultaneously a CARDINAL number). xl is the predefined constant NIL (see POINTER types in Section 3.4.1) and t2 is any POINTER type (or vice versa). t 1 and t 2 are procedure compatible. t 1 is an ADDRESS and t2 is CARDINAL or any POINTER type (or vice versa). Expression compatibilty is required in expressions Whenever two operands are combined with an operator, they must be expression compatible. Exception: For the expression "e IN s" (where s is of data type SET OF T), e must be expression compatible with T. in FOR statements Intheexpression"FORx:=first TO last DO ... "bothfirstandlast must be expression compatible with x. in CASE statements

In the expression "CASE x OF Cl:'" I C2: ••• END" all the constants Ci must be expression compatible with x. 250 Appendix C: Compatibility Rules Assignment Compatibility (see Section 3.6.1) For the assignment d: =e, we will denote the designator d of the data type td and the expression e of the data type te as assignment compatible if one of the following statements applies: The designator d and the expression e are expression compatible. td is INTEGER (or a subrange thereof) and te is CARDINAL (or a subrange thereof), or vice versa. In the execution of the assignment under these conditions, we must guarantee that the value of the expression e is in the range determined by td, otherwise the value of the assignment is undefined.

td is an ARRAY [0 .. N-l] OF CHAR (i.e., an array ofn characters) and e is a character string constant with length len and len<=n. (If len

If x is of data type ARRAY T OF E, then for every index reference x [i 1, the expression i must be assignment compatible with T. with VAL parameters (those without VAR) The actual parameter (expression) e must be assignment compatible with the corresponding formal parameter. Exceptions: If the formal parameter is an ARRAY parameter, then the element types of the formal and actual parameters must the same. ARRAY OF WORD is compatible with any data type. with function procedures

In a function procedure that returns a value with function data type T, every expression occurring in a RETURN statement must be assignment compatible with T.

Procedure Compatibility (see Section 3.7.9)

Procedure compatibility between a procedure variable pv and a procedure P means that:

pv and P have the same number of formal parameters. Appendix C: Compatibility Rules 251

The formal parameters of pv and P match one to one, that is, the ith parameter in pv and the ith parameter in P must be of the same data type (FormaIType), and both be value parameters or both be variable parameters.

pv and P must either not be function procedures, or their function values must be of the same type. Procedure compatibility is required in every occurrence of procedures or procedure variables (not procedure invocations!) in expressions, assignments or parameter lists (see also "Expression Compatibility") . Appendix D: ASCII Table

The following table lists the ASCII characters along with their corresponding ordinal numbers, which are given in decimal, octal and hexadecimal form respectively. For example

CHR(42) = CHR(52B) = 52C = CHR(2AH) = "*,,

The characters with ordinal numbers 0 to 31 and 127 are control characters that can be interpreted by certain peripheral devices. For example, the character FF (CRR (12) or 14 C) causes a form feed when output to a printer.

o OB OOH NUL 32 40B 20H 64 100B 40H "@" 96 140B 60H 1 1B 01H SOH 33 41B 21H "!" 65 101B 41H "A" 97 141B 61H "a" 2 2B 02H STX 34 42B 22H 66 102B 42H "B" 98 142B 62H "b" 3 3B 03H ETX 35 43B 23H "#n 67 103B 43H "C" 99 143B 63H "e" 4 4B 04H EOT 36 44B 24H "$" 68 104B 44H "D" 100 144B 64H "d" 5 5B 05H ENQ 37 45B 25H 11%" 69 105B 45H "E" 101 145B 65H "e" 6 6B 06H ACK 38 46B 26H n&" 70 106B 46H "F" 102 146B 66H "f" 7 7B 07H BEL 39 47B 27H 71 107B 47H "G" 103 147B 67H "g" 8 lOB 08H BS 40 SOB 28H " (n 72 110B 48H "H" 104 150B 68H "h" 9 11B 09H HT 41 SIB 29H 11) 11 73 111B 49H "I" 105 151B 69H "i" 10 12B OAH LF 42 52B 2AH 11*" 74 112B 4AH "J" 106 152B 6AH "j" 11 13B OBH VT 43 53B 2BH 11+" 75 113B 4BH "K" 107 153B 6BH "k" 12 14B OCH FF 44 54B 2CH II , 11 76 114B 4CH "L" 108 154B 6CH "I" 13 15B ODH CR 45 55B 2DH "_II 77 115B 4DH "M" 109 155B 6DH "rn" 14 16B OEH SO 46 56B 2EH 78 116B 4EH "N" 110 156B 6EH "n" 15 17B OFH SI 47 57B 2FH "/" 79 117B 4FH "0" III 157B 6FH "0" 16 20B 10H DLE 48 60B 30H "0" 80 120B SOH "P" 112 160B 70H "p" 17 21B 11H DC1 49 61B 31H "1" 81 121B 51H "Q" 113 161B 71H "q" 18 22B 12H DC2 50 62B 32H 112" 82 122B 52H "R" 114 162B 72H "r" 19 23B 13H DC3 51 63B 33H 113" 83 123B 53H "S" 115 163B 73H "s" 20 24B 14H DC4 52 64B 34H 114" 84 124B 54H "T" 116 164B 74H "t" 21 25B ISH NAK 53 65B 35H 115" 85 125B 55H "U" 117 165B 75H "u" 22 26B 16H SYN 54 66B 36H "6" 86 126B 56H "V" 118 166B 76H "v" 23 27B 17H ETB 55 67B 37H 117" 87 127B 57H "W" 119 167B 77H "w" 24 30B 18H CAN 56 70B 38H "8" 88 130B 58H "X" 120 170B 78H "x" 25 31B 19H EM 57 7lB 39H "9" 89 131B 59H "Y" 121 171B 79H "y" 26 32B 1AH SUB 58 72B 3AH 90 132B 5AH "Z" 122 172B 7AH "z" 27 33B 1BH ESC 59 73B 3BH 11 ; n 91 133B 5BH "[" 123 173B 7BH "{" 28 34B 1CH FS 60 74B 3CH 11<11 92 134B 5CH "\" 124 174B 7CH "I" 29 35B 1DH GS 61 75B 3DH "=11 93 135B 5DH "j" 125 175B 7DH ")" 30 36B 1EH RS 62 76B 3EH ">" 94 136B 5EH ,,1\" 126 176B 7EH "-" 31 37B 1FH US 63 77B 3FH "?" 95 137B 5FH 127 177B 7FH DEL References

Aho, A. v., J. E. Hopcroft and J. D. Ullman. The Design and Analysis of Computer Algorithms. Addison-Wesley, 1975 Bauer, F. L., and G. Goos. Informatik - eine einfuhrende Ubersicht. Berlin, Heidelberg, New York: Springer, 1982 B6hm, D., and G. Jacopini. "Flow Diagrams, Turing Machines and Languages With Only Two Formation Rules." Communications of the ACM, 9/5,1966, pp. 366-371 Dijkstra, E. W. "Cooperating Sequential Processes." In Programming Languages. Ed. E. Gunuys. Academic Press, 1968, pp. 43-112 Goos, G. "Systemprogrammiersprachen und strukturiertes Programmieren." In Programming Methodology. Berlin, Heidelberg, New York: Springer, Lecture Notes on series, Vol. 23, 1973, pp. 203-224 Jensen, K., and N. Wirth. Pascal User Manual and Report. 3rd ed. Berlin, Heidelberg, New York: Springer, 1985 (1978) Knuth, D. E. The Art of Computer Programming. 3 vols. Addison Wesley, 1973 Kronsj6, L. 1. Algorithms: Their Complexity and Efficiency. Wiley, 1979 Nassi, 1., and B. Shneiderman. "Flowchart Techniques for Structured Programming." Sigplan Notices, 8/8, 1973, pp. 12-26 Odersky, M. "MINOS: A New Approach to the Design of an Input/Output Library for Modula-2." Structured Programming, Springer-Verlag, April 1989 Parnas, D. L. "On the Criteria to be Used in Decomposing Systems into Modules." Communications of the ACM, 14/4, 1972, pp. 1053-58 Pomberger, G. Software Engineering and Modula-2. Englewood Cliffs, NJ: Prentice Hall, 1986 Rechenberg, P. Programmierenfur Informatiker, Band 1 und 2. Oldenbourg, 1974 Wirth, N. "Program Development by Stepwise Refinement." Communications of the ACM, 14/4, 1971, pp. 221-227 Wirth, N. Algorithms and Data Structures. Prentice Hall International, 1986 Wirth, N. Systematisches Programmieren. Stuttgart: Teubner, 1978 Wirth, N. "Lilith - a Modula-2 Machine." In Proceedings: NBSIIEEEIACM Software Tool Fair. San Diego, 1981 Wirth, N. Schemes for MUltiprogramming and Their Implementation in Modula-2. Zurich: ETH, Report No. 59, 1984 Wirth, N. Programming in Modula-2. New York: Springer, 1985 Index

ABS 126; 248 BackgroundDemo 158 absolute addressing 152 base type 70; 76 absolute value 126 Bauer and Goos 6 abstract 227 binary search 192 141; 227 pattern 150; 152 abstraction 33 BITSET 67; 150; 248 access algorithm 41; 226 blanks 164; 176 action 1; 8; 9 Block12 62; 234; 237 active 155 body of loop 99; 100 actual parameter 120 Bohm212 address 113; 147 BOOLEAN 66; 94; 248 addressing, absolute 152 boolean expression 10; 12 ADR 147 brackets 58 Again 179 branch 11; 18; 20; 94; 212 Aho, Hopcroft and Ullman 5 BusyRead 158 algorithm 1; 3; 5; 28; 109 BY 103 characteristics of 6 call 109 definition of 5; 8 CAP 125; 248 diagonalization 27 CARDINAL 65; 174; 175; 248 elimination 26 CASE 75; 95; 217 Euclidean 15 case-sensitive 54; 69 extraneous blanks 23; 164 CaseLabeiList24 75; 234; 238 factorial 22 CaseStatemen43 95; 234; 243 frequency of occurrence 24 CHAR 67; 248 gcd 15; 16; 17; 19; 20; 21 character string 9; 10; 56; 174 Josephus' Problem 26 circular list 205 justification 44; 47; 165 Close 178 maximum/minimum 22 CloseInput 173 prime number 23; 163 CloseOutput 173 selection 26 code duplication 101 text compression 25 commentary 17; 20; 21; 59; 217 vowel count 24 commenting out code 59 ALLOCATE 128; 198 communication 169 ambiguous 7 between processes 156 argument 116 compatibility 249 arithmetic expressions 10; 82; 84; 125 assignment 83; 92; 93; 112; 115; 146; array 9; 72 147; 151; 251 open 165 expression 85; 86; 88; 89; 93; 96; 103; parameter 123 151; 250 ARRAY OF WORD 147 procedure 89; 131; 132; 251 ArrayType19 72; 234; 238 compilation, separate 139; 230 array bounds 127 compilation unit 165 ASCII code 56; 254 compiler 29 assertions 218 complexity 33 assignment 9; 18; 20; 92 conditional statement 3; 91; 93 assignment compatibility 83; 92; 93; 112; conjunction 84 115; 146; 147; 151; 251 CONST77 assignment operator 9; 92 constant declarations 64 Assignmen41 92; 234; 242 ConstantDeclaration2677; 234; 239 Available 198 constants 8; 77 B (octal integers) 55 predefined 66; 248 background 157 ConstExpr27 77; 234; 239 Index 255 control structure 11; 93 designator 83; 92 conversion functions 125 Designator31 83; 234; 240 coroutine 153; 199 device 169 Create 178 diagonaiization 27 D-diagrams 212 Dijkstra 204; 212 data abstraction 36; 41; 45 directory 170 data capsule 41; 42; 46; 165; 226 discriminant 4 advantages 45 discriminator 75 data exchange 120; 122 disjunction 84 data structure DISPOSE 128; 149; 183; 248 dynamic 181 DIV65 static 181 DO 99; 103; 107 data transfer 120 driver 169 data types 8; 64 dynamic data structures 76; 181 abstract 141 dynamic memory allocation 127; 198 ARRAY 72 dynamic objects BITSET67 accessing 183 BOOLEAN 66 creating 182 CARDINAL 65 deleting 183 CHAR 67 efficiency 211 custom 64; 69 element type 72 elementary 69 Element39 87; 234; 242 enumeration 69 elementary action 40 INTEGER 65 elementary types 64 opaque 141; 143; 155; 227 elementary user-defined data types 69 POINTER 76 ELSE 94; 96 predefined 64; 248 ELSIF94 PROCESS 155; 206 empty case 96 REAL 66 empty statement 91 RECORD 73 enumeration constants 69 207 enumeration type 69; 138 SET71 Enumeration15 69; 234; 237 structured 70 environment 136 subrange 69 error 219 user-defined 64; 69 Euclidean algorithm 15; 16; 17; 19; 20; 21; WORD 181 61; 189 data-oriented organization 45 EXCL 127; 248 date as RECORD 73 exclusive OR 67 deadlock 207; 209 executable 7 DEALLOCATE 128; 198 ExitStatemen48 104; 234; 244 debugging 219; 223 explicitly imported 138 DEC 126; 248 exponent 55; 66 DecInteger5 54; 234; 235 EXPORT 135; 136 declaration 61; 63; 64 export 46 declaration of procedures 109 export list 136 Declaration13 62; 234; 237 Exp0rt61 136;234;246 decrement 103; 126 expression classes 82 default 172 expression compatibility 85; 86; 88; 89; 93; definition module 140; 165; 224 96; 103; 151; 250 definition of identifiers 141 Expression32 85; 234; 240 Definition63 141; 234; 246 expressions 9; 10; 82; 85 DefinitionModule62 140; 234; 246 factor 86 definition module 140 Factor37 87; 234; 241 delimiter 58 FALSE 248 dereferencing 83 Fibonacci 31 design phase 224, identifier 107 256 Index FieidList21 74; 234; 238 import file 170; 172 interface 46 access 170 list 135 close 171; 173 ImpoI16o 135; 234; 245 create 170 IN 68; 86 open 170; 173 INC 125; 248 pennanent 170 INCL 127; 248 random access 170 increment 10; 103; 125 sequential 170 index type 72 temporary 170 indexing 83 variable 177 infinite loop 104; 159 FileSystem 170; 177 infonnation hiding 45; 226 FindDouble 114 initial value 103 finiteness initialization 120; 137; 143 dynamic 7 InOut 172; 173 static 7 input 169 flag 222 INTEGER 65; 174; 175; 248 FLOAT 125; 248 integer division 65 floating point numbers 66 Integer4 54; 234; 235 foreground 157 integers 54 fonnal parameter 110; 120; 251 interface 15; 24; 28; 45; 46; 122; 154; 156; FonnalParameters52 110; 234; 244 224;225;230 FonnalType54 111; 234; 244 interface consistency check 230 FonnaiTypeList58 130; 234; 245 interference 161 ForStatement46 102; 234; 243 interrupt 159 FROM 129; 135 handler 160 function 116 pending 162 conversion 125 protection 162 parameterless 116 IOTRANSFER 160 procedure 110; 115; 116 iteration 101; 102; 103; 190 standard 248 Jacopini 212 values 121 Jensen 51 function-oriented organization 45 justification 34; 109; 165 GetPos 178 key words 53 global module 139 Knuth 5; 16; 26 Goos 6; 46 Kronsjo 6 GOT0226 language grammar 50 algorithmic 29 greatest common denominator 189 description 51 H (hex integers) 55 element 51 HALT 127; 137; 144; 248 extension 145 hexadecimal numbers 55 higher 29 HexInteger7 55; 234; 236 machine 29 hierarchic interrupt concept 162 natural 15 HIGH 127; 248 programming 21; 28 Hopcroft 5 Length 178 I/O 169 lexical elements 52 Identl 52; 234; 235 library module 195 identifier FileSystem 170 qualification 135; 136 InOut 173 predefined 124; 248 Printer 170 IfStatement42 94; 234; 243 Storage 129 implementation module 140; 143; 165; 225 Terminal 170 ImplementationModul~5 143; 234; 246 lifetime 118 IMPORT 61; 62; 129; 135 in procedures 120 explicit/explicit 138 in modules 139 Index 257

Lilith 177 PrimeTest 163 linefeed 174 ProcessDemo 156 list 77; 182 program 62 local Queues 228; 229 module 134 ReadName 176 variable 117; 118; 120 RealInOut 172; 175 localizing errors 221 Scheduler 206 logical expressions 58; 82; 84 SimpleScheduler 199; 200 Lookup 178 Stack 137; 144 loop 3; 13 Storage 198 body 99; 100; 103 SYSTEM 145 continuation condition 13 Terminal 171 control condition 99; 100 TestObject 222 control statement 91; 98 WordManagement 166 FOR 102 WordProcessing 165 LOOP 104 ModuieDeclaration59 134; 234; 245 REPEAT 100 MulOperator36 86; 234; 240 WHILE 99 multidimensional ARRAYs 72 control variable 102; 103 multiplication operator 86 forms of 99 multitasking 154 infinite 159 multiway decision 11; 18; 20; 94; 95; 212 termination condition 14 mutual exclusion 203 LoopStatementn 104; 234; 243 names, choice of 217 machine code 29 Nassi-Shneiderman diagram 19 mantissa 66 nested statements 12; 13; 14 MathLibO 196 NEW 127; 149; 183; 187; 248 matrix 9; 72 NEWPROCESS 155 MAX 127; 248 Newton MAX (INTEGER) 89; 250 cube root 15 memory-mapped I/O 152 square root 31 memory allocation 152 NIL 77; 83; 248 MIN 126; 248 non-local variables 122 MOD 65 null character 174 modularization 47; 225 Number3 54; 234; 235 module 45; 61; 134; 135 numbers 54 AuthorCatalog 185 object 1; 8; 52 BackgroundDemo 158 auxiliary 7 body 136 input 7 Clock 160 output 7 compilation 165 structured 9 definition 46; 140; 165 object code 29 design 47 octal numbers 55 execution 136 OctCharlO 57; 234; 236 FileSystem 177 OctInteger6 55; 234; 235 GCD61 ODD 126;248 global 139 Odersky 181 heading 61 opaque data type 141; 143; 155; 227 implementation 143; 165 open array 124 InOut 172; 173 OpenInput 173 Justify 165 OpenOutput 173 library 195 operator 10; 58; 82 LineManagement 167 assignment 9 local 134 pointer dereferencing 183 MathLibO 196 operators 84 Mean Value 180 order of evaluation 84 Numbers 179 ORD 125 2S8 Index organization producer!consumer 156; 200 data-oriented 45 roots of quadratic equation 4 function-oriented 45 selection 26 problem-oriented 45 square root 31 output 169 stack 142; 147 outward form of programs 218 text compression 25 overflow 65 time 160 palindrome 134 problem analysis 224 parallel processes 153; 154; 199 problem-oriented organization 45 parameter 15; 121; 189 PROC248 actual 112; 120 procedure 109; 110 array 123 active 120 formal 120; 165 call of112 list 112 compatibility 89; 131; 132; 251 open array 124 declaration 109 value 111; 113 function 116; 121 VARl13 inner 118 variable 111; 112; 113 invocation 112 parameterless procedure 156 parameterless 156 parameters recursive 189 formal 112 standard 124; 131 ParamSectionS3 110; 234; 244 variable 129; 130 Parnas 41 PROCEDURE types 129 pass by reference 113 ProcedureCallss 112; 234; 245 pass by value 113 ProcedureDeclarationso 110; 234; 243 pending interrupt 162 ProcedureHeadingSl 110; 234; 244 peripheral device 169 procedures POINTER 76; 143 examples pointer dereferencing operator 183 I AppendPublication 186 PointerType2S 76; 234; 239 AppendWord 168 Pomberger 15; 212; 217; 227 arcsin 196 portability 170 Average 122 predefined data types 64 Background 159 predefined identifiers 248 BinSearch 193 prime numbers 23; 194 BuildPowerOf2 111 prime number 163 ByName 132 Printer 170 ByNumber 132 priority 159; 162 BySalary 132 Priority67 162; 234; 247 CheckKeyboard 158 problem ComputeAverage 121 arithmetic mean 120 ComputeSquare 111 binary search 192 Copy 147 blanks 23 CreateProcess 207 cube root 15 Divisible 193 diagonalization 27 DoublePos 117 elimination 26 EliminateBlanks 165 extraneous blanks 164 EverySecond 161 factorial 22 FindDouble 114; 115 Fermat's 7 FindWhiteSpace 168 frequency of occurrence 24 GCD21; 189 gcd 15; 61 InitSemaphore 207 greatest common denominator 61; 189 InsertBlank 169 Josephus' 26 IsInString 124 justification 34; 165 NextPrime 194 maximum/minimum 22 Palindrome 134 prime number 23; 163; 194 Pass 207 Index 259 procedures, examples-continued sqrt 196 Pop 137 termination 127 PoweIDf2 117 TSIZE 128 Prime 194 type transfer 150 PrintLine 168 Write 172; 174 ProcessWord 167 WriteCard 175 Push 137 WriteChar 179 ReadKey 153; 158 WriteHex 175 ReadTextWord 166 WriteInt 175 Search 112 WriteLn 172; 174 Signal 208 WriteOct 175 Sort 129 WriteReal175 Square 116 WriteString 172; 174 SquareRoot 60 WriteWord 179 StretchLine 168 standard 248 Sum 190 ABS 126 Wait 208 CAP 125 library CHR 125 Again 179 DEC 126 ALWCATE 128; 198 DISPOSE 128; 149 arctan 196 EXCL 127 arithmetic 125 FLOAT 125 array bounds 127 HALT 127 Available 198 HIGH 124; 127 BusyRead 158; 171 INC 125 Close 178 INCL 127 CloseInput 173 MAX 127 CloseOutput 173 MIN 126 conversion 125 NEW 127; 149 cos 196 ODD 126 Create 178 ORD 125 DEALWCATE 128; 198 TRUNC 125 entier 196 VAL 125 exp 196 ProcedureType57 130; 234; 245 GetPos 178 process 153; 155; 199; 206 Length 178 active 155 In 196 generation 155 Lookup 178 scheduler 199 memory allocation 127 suspended 155 OpenInput 173 synchronization 154; 155 OpenOutput 173 transfer 154 range 126 variable 155 Read 171; 174 ProcessDemo 156 ReadAgain 171 processor 2 ReadCard 174 producer/consumer problem 156; 200 ReadChar 179 program 28 ReadInt 174 AuthorCatalog 185 ReadReal175 BinSearch 193 ReadString 174 control 93; 99; 100 ReadWord 179 Divisible 193 real 196 extraneous blanks 164 Rename 178 justification 165 Reset 178 MeanValue 180 set 127 module 61; 134 SetPos 178 Numbers 179 sin 196 prime number 163; 194 260 Index program--continued scope 118 ProcessDemo2 200 with modules 138 Scheduler 204; 206 scope control statement 91 SimpleScheduler 200 selection 11 structure 61 self-containment 47 testing 219 semaphore 204; 206; 207 translation 29 semicolon 63; 92 WordProcessing 164 separate compilation 139; 230 programming style 211 separating characters 55 ProgramMcx:lulell 62; 234; 236 sequence 212 project phases 224 sequence control structures 11 pseudoccx:le 17 sequential execution 3 Qualldent2 53; 234; 235 SET71 qualified set operations 82; 84; 127 export 136 Set3S 87; 234; 242 identifier 53 SetPos 178 qualify 106 SetType17 71; 234; 238 quasi-parallel154 Shneiderman, B. 19 queue 205; 227 side effects 123 range 2; 8 Signal 204 range symbol 88 SimpleExpression34 86; 234; 241 Read 174 SimpleTypelS 71; 234; 237 ReadCard 174 SIZE 148 ReadChar 179 software engineering 224 Readlnt 174 specification 4; 224 ReadReal175 stack 137; 147 ReadString 174 standard ReadWord 179 functions 248 REAL 66; 175; 248 procedures 124; 131; 248 real numbers 55; 66 types 64 Reals 55; 234; 236 state 155 RealInOut 173 active 155 Rechenberg 6; 17; 48 dormant 160 RECORD 73; 139; 187 suspended 155 dereferencing 106 wait 155 with variants 128; 148; 150; 187 state variable 203 type 138 statement 61; 90 RecordType20 73; 234; 238 assignment 91 recursion 188 CASE 95 direct 190 conditional 91 indirect 190; 194 dereferencing 91; 106 recursive procedures 189 empty 91 redirecting I/O 172 EXIT 104 Relation33 85; 234; 240 FOR 102 relational expression 10; 67; 84 IF 94 remainder 65 LOOP 104 Rename 178 loop control 91; 98 repeat loop 212 procedure invocation 91 repeat!untilloop 14; 18; 20 REPEAT 100 RepeatStatemen4S 100; 234; 243 RETURN 114 repetition 13 WHILE 99 Reset 178 WITH 106 RETURN 114; 116 statement sequence 94 RetumStatementS6 115; 234; 245 Statemen4091; 234; 242 ring 200 StatementSequence14 63; 234; 237 scheduler 199 static data structures 181 Index 261 step 103 checking 150 stepwise refinement 2; 33; 36; 109; 225; declarations 64; 78 227 identity 80; 249 storage 120; 129 transfer functions 150 string 56; 174 Type29 79; 234; 240 String9 57; 234; 236 TypeDeclaration28 78; 234; 239 structured data types 70 TypeDefinitiol164 141; 234; 246 structured objects 9; 36 TypeTransfer66 151; 234; 247 structured programming 212; 226 Ullman 5 structuring 225 unambiguous 7 in the large 212 unary minus 65 in the small 212 undefined 96; 116; 120 stylized prose 16 user-defined data types 64; 69 subrange types 69 VAL 125; 248 Subrange16 69; 234; 237 value parameter 111; 113 suspended 155 VAR79 swap 92 V AR parameter 113 switch variable 101 variable 8; 79 symbols 59 local 118; 120 synchronization 154; 155; 203; 204 VariableDeclaration30 79; 234; 239 syntax diagram 234 variable parameter 111 SYSTEM 155; 156; 158 Variant23 75; 234; 239 systems programming 145 VariantFieldList2274; 234; 239 tag field 75 vector 9 target type 125 Wait 204 target value 103 wait state 155 term 86 while loop 14; 18; 20; 212 Term35 86; 234; 241 WhileStatementM 99; 234; 243 Terminal 170; 171 Wirth 2; 33; 48; 51; 160; 171; 177; 181; termination criterion 101; 105 195;203 testability 47 WITH 167 THEN 94 WithStatemen149 106; 234; 244 TRANSFER 155; 199; 203 WORD 146 transformation word of storage 179; 180 LOOP 105 Write 174 WHILE/REPEAT 101 Write Card 175 TRUE 248 WriteChar 179 TRUNC 125; 248 WriteHex 175 TSIZE 128; 148 Writelnt 175 TYPE 78 WriteLn 174 declaration 141 WriteOct 175 definition 141 WriteReal175 type WriteString 174 binding 230; 232 WriteWord 179