GY33 8000 0_ALGOL_F_Rel_21_Compiler_Logic_PLM_Jan72 0 ALGOL F Rel 21 Compiler Logic PLM Jan72

GY33-8000-0_ALGOL_F_Rel_21_Compiler_Logic_PLM_Jan72 GY33-8000-0_ALGOL_F_Rel_21_Compiler_Logic_PLM_Jan72

User Manual: GY33-8000-0_ALGOL_F_Rel_21_Compiler_Logic_PLM_Jan72

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

DownloadGY33-8000-0_ALGOL_F_Rel_21_Compiler_Logic_PLM_Jan72 GY33-8000-0 ALGOL F Rel 21 Compiler Logic PLM Jan72
Open PDF In BrowserView PDF
File Number S360-26
Order No. GC33-8000-0

y

Program Logic

OS ALGOL (F) Compiler Logic
I

Program Numbers: 360S-AL-531 (Compiler)
360S- LM-532 (Library Routines)
OS Release 21
This manual describes the internal logic of the
ALGOL (F) Compiler. It is intended for the use
of IBM field engineers, systems analysts and
programmers.
The ALGOL (F) Compiler is a processing program
of the IBM System/360 Operating System. It
translates a source module written in the ALGOL
language into an object module that can be
processed into an executable load module by the
Linkage Editor.

Page of GY'l3-8000-0
Revised January 15, 1972
By TNL GN33-8129

PREFACE

The IBM System/360 Operating System ALGOL
Compiler consists of ten phases, or load
modules. Chapter 1 of this manual provides
an introductory survey of the main
functions of the several phases. A more
detailed description of the individual
phases is provided in the subsequent chapters, as follows:
Directory (IEXOO)
Initialization (IEX10)
Scan I/II (IEXll)
Identifier Table Manipulation
(IEX20)
Diagnostic Output (IEX21)
Scan III (IEX30)
Diagnostic Output (IEX31)
Subscript Handling (IEX40)
Compilation Phase (IEXSO)
Termination Phase (IEXS1)

Chapter 2
Chapter 3
Chapter 4
Chapter
Chapter
Chapter
Chapter
Chapter
Chapter
Chapter

5
9
6
9
7
8
8

handles the output of diagnostic messages
in the three phases mentioned, is described
in Chapter 9.
Chapter 10 describes the ALGOL Library,
which consists of a set of load modules
representing standard I/O procedures,
mathematical functions, and the Fixed Storage Area.
Chapter 11 describes the composition of
the object module generated by the Compiler,
and the organization of the load module at
execution time.
Other publications that will be useful
to the reader in understanding the Compiler
are:
OS ALGOL Language, Order No.GC28-661S

Two of the phases (Load Modules IEX21
and IEX31) are devoted exclusively to the
editing and output of diagnostic messages.
Diagnostic output is also provided for in
the Termination Phase (Load Module IEXS1).
The Error Message Editing Routine, which

OS ALGOL Programmer's Guide,
Order No. GC33-4000
OS FORTRAN IV Library, Order No.
Order No. GC28-6S96

First Edition (September 1967)
This edition applies to release 21 of the IBM System/360
Operating System, and to all subsequent modifications unless
otherwise indicated in new editions or Technical Newsletters.
Changes are continually made to the specifications herein;
before using this publication in connection with the operation
of IBM systems, consult the latest SRL Newsletter, Order No.
GN20-0360 for the editions that are applicable and current.
This publication was prepared for production using an IBM
computer to update the text and to control the page and line
format. Page impressions for photo-offset printing were obtained from an IBM 1403 printer using a special print chain.
Requests for copies of IBM publications should be made to
your IBM representative or to the IBM branch office serving
your locality.
A form is provided at the back of this publication for
reader's comments. If the form has been removed, comments
may be addressed to IBM Nordic Laboratory, Publications
Development, Box 962, S-181 09 Lidingo 9, Sweden. Comments
become the property of IBM.

©Copyright International Business Machines Corporation

1967

CONTENTS

CHAPTER 1: INTRODU:TION.

• • • 13

Purpose of the Compiler. •

• 13

rhe Compiler and System/360 Operating
System. • • • •

• 13

Machine System • •

• 13

)rganization of the :ompiler •
• • •
Directory (IEXOO) • • • •
•
Initialization Phase (IEX10) ••
•
Scan 1/11 Phase (IEX11) • • • •
•
Identifier rable Manipulation Phase
(IEX20). • • • • • • • • • •
• •
Diagnostic Output (IEX21) • •
•
Scan III Phase (IEX30). • • •
• •
Diagnostic output (IEX31) • •
• •
Subscript Handling Phase (IEX40) • • •
Compihtion Phase (IEX50) • • • • • •
Termination (IEX51) • • • • • • • • •
Diagnostic Output (IEX21, IEX31,
and IEX51) • • •
• • • •
•
ALGOL Library •
The )bject Module.

13
13
13
15
15
15
15
15
15
16
16

• 16

Communication by Source
rext and rable. • • •

CHAPTER 3: INITIALIZATION PHASE
(IEX10) •
• • • •
Purpose of the Phase •

In~erphase

17

Use of Main Storage. • •
Area Occupied by Directory
Auxiliary Routines • • • •
The Common ~ork Area • • • •
Area occupied by Operative Module •
Private Area Acquired by Operative
Module • • •
• • •
Common Area
conventions. • •

• 20

CHAPTER 2: DIRECTORY (IEXOO)

• 21

Purpose of the Directory • •

• 21

...

Selection of Area Size Table
(FNDARSIZ) • • • • • • • • • •
Acquisition of Common Area •

• 18
18

opening of Data Sets

• 19

CHAPrER 4: SCAN

• 19
• 19

Purpose of the Phase

21
21
21
21
21
22

23
23
24
24

• 24
24
• 24
• 24
• 24
• 25
• 25
• 25

• 26
26

Processing Compiler Options., DDnames,
and Heading Information • •
• • 26
:ompiler Options. • •
27
DDnames • • • • • • • •
• 28
28
Heading Information • •

• 18

Organization of the Directory. •
•
• •
Control Section IEXOOOOO • • •
Initial Entry Routine. •
·
• •
Final Exit Routine • • • •
Program Interrupt Routine
(PI ROUT). • • • • • • • • • • • •
1/0 Error Routine (SYNAD) • • • • •
Sysprint 110 Error Routine
(SYNPR) • • • • • • • • • • • • •
End of Data Routines (EODAD1,
EODAD2, EODAD3, AND EODADIN) • • •
Print Subroutine (PRINT) • • • • •
Data Control Blocks. • • • • • • •

•
•
•
•

• • • 26

Execution of the SPIE Macro. •
16
16

• • • 16

Input/)utput Activity.

Control section IEX00001 (Common
Work Area) • • • • • • • • •
•
Register Save Area • • • •
DCB Addresses. • • • • • • • • •
End of Data Exit Addresses
•
compiler Control Field
(HCOMPMOD). • • • • • ••
•
Communication Area • • • •
Area Size Table (INBLKS).
•
Headline Storage Area (PAGEHEAD)
Preliminary Error Pool • • • • •
Data Control Blocks for SYSIN
and SYSUT1. • •
• •••• •
Tables • • •
• • • • •
Other Data •
• • • • • • • •

1/11

• • 28
28
• • 28

PHASE (IEX11) •

30
30

Scan 1/11 Phase Operations • • • • • • • 31
Opening of Scopes • • •
• • 33
processing of Declarations and
Specifications •
• • • • 34
Close of Scopes
• • • • • • • 34
End of Phase. •
34
Phase Input/Output • • • • • •

35

Identifier Table (ITAB) ••
•
Identifier Entries. •
•
Program Block Heading Entries •
For Statement Heading and Closing
Entries. • •
• • • • • • •
processing of the Identifier Table.

• 35
• 36

Scope Identification
Scope Handling Stack.

41
• 42

• 38

• 39
• 40

22
22
23
23

Modification Level 1 Source Text • • • • 43
Group Table (GPTAB). • • • • • • •

45

Scope r3.ble (SprAB).
Pro~r3.m

• 45

Block Number Table (PBTAB1) • • • 46

processin~

of Opening Source Text • • • • 46
46

Close of Scan 1/11 Phase •
Switches

• • 48

Constituent Routines of Scan 1/11
Ph3.se • • • • • • •
•
Phase Initialization.
•
M3.in Loop (TESTLOOP) • • •
•
Blank (BLANK) • • • • • •
•
Test 3.n~ Transfer Operator
(rRANSOP)..
• •••••••••
RIGHTP~R. • • • • • • • •
•
POINr • • • • • • • • • • •
••••
Decimal Point (DE:POINT).
•
Assi~nment (ASSIGN) • •
•
statement (Sr~rE) • • • • •
•
Apostrophe (APOSTROF) • •
•
Scale Factor (S:ALE). • •
•
Bl3.nk after Apostrophe (BLKAPOS) • • •
Zeta after Apostrophe (ZETAAPO) • • •
Invali~ Character after Apostrophe
(NP~FrAPO) • • • • • • • •
•
Colon (COLON) • • • • • • • •
Label (LABEL) • • • • • • • • •
•
Letter Delimiter (LETDEL) • • • • • •
Semicolon (SEMCO and SEMC60) • •
•
Error Recording Routines. • • •
Ch3.nge Input Buffer (:IB) • • •
•
Identifier Test (IDCHECK1) • • •
•
Change Output Buffer (COB and
COBSPEC) • • • • • • •
•
Delimiter (DELIMIT) • • • • • •
•
Delimiter Error Routine (EROUT)
•
Type specification (TYPESPEC) • • • •
Comment (COMSPEC) • • • • • • •
•
Opening Delimiter (STARTDEL) • • • • •
Begin (BEGIN) • • • • • •
• • •
String (STRIN:;) • • • • •
Norm3.l ~ction (NORMAL). •
•
Boolean Constant (BOLCON)
•
Goto-If (GIF) • • • • • • • • • • • •
Then-Else-Do (rED). • • •
•
First Be~in (FIRSTBE3) • • • • • • • •
Program Block (BEGl Subroutine)
•
End (END) • • • • • • • • •
•
Compound End (COMPDEND) • • •
••
For Statement End (FOREND).
•
program Block End (PBLCKEND
Subroutine). • • •
• •
Comment (COM) • • • • • •
• • •
For statement (FOR) • • • • • • • • •
Type Declaration (TYPE) • • • • • • •
Identifier Error (IER).
•
Code Procedure (CO;)E) • •
•
Specification (SPEC) • • • • • • • • •
Parameter Specification (SPECENT
and IDCHECK) • • • • • •
•
rype ~rray (rYPEARRY) • •
•
~rray Declaration (~RRAY)
•
Array/Switch List (LIST).
•
Point in List (PONTLST) •
•
Right Parenthesis in List
(RIGHTP~RL). • • •
• •
•
Left Parenthesis in List (LEFTPARL) •

52
52
54
55
55
55
55
56
56
56
56
56
56
57
57
57
57
57
57
57
59
59
59
60
60
62
62
62
62
62
62
62
63
63
63
63
63
63
63
64
64
64
64
64
65
65
65
65
65
66
66
66
66

Comma in List (COMMALST). • •
• 66
Colon in List (COLONLST). •
• 66
Semicolon in List (SEMCLST) •
66
Slash in List (SLASHLST). •
67
Switch Declaration (SWITCH)
67
Procedure Declaration (PROCEDUR) • • • 67
Procedure Identifier (PROCID)
• • 67
Termination (EODADIN)
• • • • • • 67
Generate Subroutine • • •
• • 68
CHAPTER 5: IDENTIFIER TABLE
MANIPULATION PHASE (IEX20).

69

Purpose of the Phase • • • • •

69

Identifier Table Manipulation Phase
operations. • • •

• • 69

Phase Input/Output • •

• • 70

Identifier Table (ITAB).

70

Program Block Table II (PBTAB2) • • • • • 70
Constituent Routines of Identifier
Table Manipulation Phase. • • •
Phase Initialization • • • • • •
Identifier Scan (READBLIO • • • .•
Storage Allocation (ALLOSTOR) • •
write Identifier Table (WRITITAB)
Print Identifier Table (ITABPRNT)
rermination (CLOSE) • • • • • • •

71

•
•
•
•
•

•
•
•
•
•
•

71
72
72
73
73
73

CHAPTER 6: SCAN III PHASE (IEX30). • • • 74
Purpose of the Phase • • • •
Scan III Phase Operations • • • • • •
Opening and Close of Blocks and
Procedures • • • • • • • • • • •
Identifier Handling • • • • •
Number Handling • • • • • • •
Array Subscript Handling. • •
Handling of Other Operators •
Phase Termination •
Phase Input/output • •

74
• • 75
•
•
•
•
•

•
•
•
•
•

75
75
77
77
77
77

• • 77

Processing of the Identifier Table • • • 78
Classification of For Statements • • • • 79
Processing of For Statements. • •
80
Detection of Operators in For
80
List. . . . . . . . . . .
Recognition of Identifiers in
80
For Statements. • • •• • • •
Optimizable subscript Expressions • • • • 81
For Statement Table (FSTAB).

• • 81

Left Variable Table (LVTAB) • •

• • 82

subscript Table (SUTAB) • • •

82

Critical Identifier Table (CRIDTAB).

82

Array Identifier Stack (ARIDSTAB) • • • • 84
Modification Level 2 Source Text • •• • • 84

swi tches • • • • • • • • • • • • • • • • 85

Phase Input/Output

• .102

constituent Routines of Scan III Phase • 86
Phase Initializati~n (INITIATE)
• 86
General Test (GENTEST). • • • • • • • 88
Identifier Test (LETTER) • • • • • • • 88
IT~B Search (IDENT)
• • • • • • • • • 88
Identifier Classification (FOLI) • • • 88
Noncritical Identifier (NOCRI) • • • • 89
Proce~ure/Parameter (PROFU)
• 89
switch/Label (S~IL~) • • • • • • • • • 89
Critical Identifier (CRITI)
• 89
Make Cridtab Entry (CRlMA). •
• 90
CRIDTAB Overflow (CRIFLOW).
• 90
Erase CRIDTAB (DELCRIV) •
• 91
Up~ate CRIDT~B (CRIFODEL)
• 91
Make LITTAB Entry (LETRAF)
• • • 91
Nonzero Digit (DI3IT19)
• 91
Zero Digit (DIGIrO) • • •
• 92
Decimal Point (DECPOIN) •
• 92
Scale Factor (SCAFACT). •
• 93
Integer Conversion (INTCON)
93
Real Conversion (RE~LCON) •
• 9~
Integer Handling (INTHAN) •
• 9~
Real Handling (RE~LH~N) • •
• 9~
Change Constant Pool (CPOLEX) •
• 9~
output TXT Record (TXTTR~F)
• 95
Generate (GENTXT) • • • • • • •
95
Apostrophe (~UOTE) • • • • • • • • • • 95
Block Be:Jin (BETA). • • • • • • • • • 95
Procedure Declaration (PIPHI) •
• 95
Read ITAB Record (ITABMOVE) • • • • • 95
For statement (FOR) • • • • • • • • • 95
Program Block End (EPSILON)
• 95
For Statement End (ETA) • •
• 95
Do (DO) • • • • • • • • • •
• 96
While (WHILE) • • • • • • •
• 96
Semicolon/Delta (SEMIDELT).
• 96
Opening Bracket (OPBRACK) •
• 96
Comma (COMMA) • • • • • • • • •
• 96
Closing Bracket (CLOBRACK).
• 96
Scan subscript (S[JCRIDEL).
• • • 96
Subscript Test (SUSCRITE) •
96
Operand Test (OPERAND). • •
• • • 97
Multiplier-Operand (SUBMULT) • • • • • 97
Make SUTAB Entry (SUTABENT)
• • • 98
Input Record End (ZETA) • •
• • • 98
Change Input Buffer (ICHA).
• 98
Code Procedure (G~MMA). •
• 98
Program End (OMEGA) • • •
• 98
Other Operators (OrHOP) • • • • • • • 98
Letter Delimiter (RHO). •
• • • 99
Step (STEP) • • • • • • •
• 99
~rray (ARR~Y) • • • • • •
• 99
Switch (SWITCH) • • • • •
• 99
Divide/Power(OIPOW) • • •
• 99
Change output Buffer (OUCHA). •
99
Incorrect Operand (INCOROP)
• 99
Store Error (MOIlERRO) • • • • •
• 99
Move Operand (MOllE) • • • • • •
• 99
Check-Write (CHECK) • • • • • •
.100
write SUTAB/LITTAB Record (WRITE) • • • 100

Optimization Table (OPTAB) •

• .103

CHAPTER 7: SUBSCRIPT HANDLING PHASE
(IEX~O).
• • • •
• • • • • • .101
Purpose of the Phase

• • .101

Subscript, Left Variable and For
Statement Tables. • • • • •
• • • • 103
Constituent Routines of Subscript
Handling Phase • • • • • • • • • • • • • 103
Initializa tion. • •
• • • 103
Read SUTAB. • • •
• .105
Scan SU'TAB. • • • •
• • • • • • .105
Sort SUTAB (SORTSU) • • • •
• • .106
Read and Sort LVTAB (SORTLE and
SORTLE!) • • • • •
• .106
Construct OPTAB (OPTAB)
• • 106
Termination (TERMIN) • • • • • • • • • 107
~rite OPTAB (OTACHA) • • • • • • • • • 107
Read SUTAB/LVTAB (READ) • •
• .107
Sort SUTAB/LVTAB (SORT) •
• • .107
CHAPTER 8: COMPILATION PHASE (IEX50) • • 108
Purpose of the Phase •

• .108

Compilation Phase Operations •

• .108

Phase Input/Output • • • •

• • • 110

operator/Operand Stacks. •

• .110

Control of Object Time Registers

• .113

Decision Matrices • • •

• .116

Compile Time Register Use.

• .116

Constituent Routines of the
Compilation Phase. • •
• • • • 116
Phase Initialization.
• .118
Scan to Next Operator (SNOT). •
.119
Compare (CaMP). • • • • • • • • • • .119
Blocks and Compound Statements • • • • 120
Compiler Program No.O (CPO>' • • • 120
Compiler Program No.16 (CP16) • • • 120
Switches • • '• • • • • • • • • • • • • 120
Compiler Program No.~ (CP~) • • • • 121
Compiler Program No.85 (CP85) • • • 122
Compiler program No.56 (CP56) • • • 122
Compiler Program No.59 (CP59) • • • 122
Compiler Program No.~l (CP~1) • • • 122
Compiler Program No.38 (CP38) • • • 122
Labels. • • • • • • • • •
• • .122
Compiler Program No.1 (CP1) • • • • 122
Goto Statements • • • • • • • • • • • 123
Compiler Program No.6 (CP6) • • • • 123
Compiler Program No.56 (CP56) • • • 123
Compiler Program No.62 (CP62) • • • 123
Arrays • • • • • • • • • • • • • • • • 124
Array Declarations • • • • • • • .125
Subscripted Variables • • • • • • • 126
Compiler Program No.~ (CP~) • • • • 127
Compiler Program No.52 (CP52) • • • 127
Compiler Program No.36 (CP36) • • • 128
compiler Program No.51 (CP51) • • • 128
Compiler Program No.5~ (CP5~) • • • 130
Compiler Program No.~l (CP41) • • • 130
Compiler Program No.38 (CP38) • • • 130

subscript Handling Phase Operations. • .101
Procedures • •

.131

Proce:ture Declaration. • • • •
.131
Procedure Call. • • • • • • • •
.132
Compiler Program No.4 (CP4).
.133
Operand Recognizer (OPDREC).
.134
Compiler Program No.16 (CP16) • • • 134
Compiler Program No. 64 (CP64) • • • 134
compiler Program No.57 (CP57) • • • 134

Integer Power Routine (IUB1)
.160
Real-Real Routine (DHEB2).
• .160
Real-Integer Power Routine
(IIB1) • • • • • • • • • • •
.160
Real Power Routine (HOB1) • • • • .161
Compiler Program No.68 (CP68). • .161

Code Procedures. • • •
• • • • • .135
Compiler Program No.83 (CP83) • • • 136

Semicolon Handling • • • • • • • • • • • 161
Compiler Program No.24 (CP24) • • • 161
Compiler Program No.25 (CP25) • • • 161
Compiler Program No.23 (CP23) • • • 161
compiler Program No.7 (CP7) • • • • 161

Standar:t Procedures. •
• • • • • .136
Compiler Program No.64 (CP64) • • • 136
Compiler Program No.61 (CP61>. • .137
For statements • • • • • • • • • • • • .138
Counting Loops •
.138
Elementary Loops
• • .139
Normal Loops • •
.140
Subscript Optimization •
.143
Compiler Program No.6 (CP6).
.144
Compiler Program No.40 (CP40). • .144
Compiler Program No.43 (CP43) • • • 147
Compiler Program No.45 (CP45) • • • 147
Compiler Program No.47 (CP47) • • • 147
Compiler Program No. 49 (CP49) • • • 148
Subscript Initialization Routine
(DwG3 or USAl) • • • • • • • • • • 148
subscript Incrementation Routine
(OVAl). • • • •
• • • • • .151
Compiler Program No.81 (CP81) • • • 151
statements.
• • • • • .151
Compiler Program No.12 (CP12) • • • 151
Compiler Program No.21 (CP21) • • • 151
Compiler Program No.20 (CP20) • • • 152

~ssignment

Conditional Statements
Compiler Program
Compiler Program
Compiler Program
Compiler Program

No.8 (Cp8) • • •
No.78 (CP78) ••
No.17 (CP17). •
No.18 (CP18) ••

.153
.154
.154
.154
• 154

Conditional Expressions. • •
COmpiler Program No. 64'
Compiler Program No.80
Compiler Program No.34
Compiler Program No.65
Compiler Program No.78
Compiler Program No. 87
Compiler Program No.79

• • • • • .154
(CP64). • .156
(CP80) • • • 156
(CP34) • • • 156
(CP65) • • • 156
(CP78) • • • 156
(CP87) • • • 156
(CP79) • • • 157

Boolean Expressions. •
Compiler Program
Compiler Program
Compiler program
Compiler Program
Compiler Program

• . . . • . 157

No. 64
No.65
No.67
No.76
No.77

(CP64) • • • 158
(CP65)' •• 158
(CP67). • .158
(CP76) ~ •• 158
(CP77) • • • 158

Expressions and Relations • .158
Compiler Program No.64 (CP64) • • • 158
Compiler Program No.66 (CP66) • • • 158
compiler Program No.67 (CP67) • • • 159
Compiler Program No.63 (CP63) • • • 159
Compiler Program No.68 (CP68) • • • 159
compiler Program No.69 (CP69) • • • 159
Integer-Integer Routine (OHZB1) •• 160
Integer Division Routine (ISB1) •• 160
Integer Multiplication Routine
(IPB1). • • • • • • • • • • • • .160

~rithmetic

context switching. • •
Compiler Program
compiler Program
Compiler Program
Compiler Program
Compiler Program

No.19
No.22
No.33
No.70
No.71

• • • • • • 161
(CP19). • .161
(CP22) • • • 162
(CP33) • • • 162
(CP70) • • • 162
(CP71). • .162

Logical Error Recognition. •
Compiler Program No.26
Compiler Program No.27
Compiler Program No.28
Compiler Program No.29
Compiler Program No.30
Compiler Program No. 31
Compiler Program No.72
Compiler Program No. 73
Compiler Program No.74
Compiler Program No.75
Compiler Program No.84
Compiler Program No.86

• • • • • • 162
(CP26) • • • 162
(CP27) • • • 162
(CP28) • • • 163
(CP29). • .163
(CP30) . . . . 163
(CP31> • • • 163
(CP72) • • • 163
(CP73) • • • 163
(CP74). • .163
(CP75) • • • 163
(CP84) • • • 163
(CP86). • .164

Close of Source Module
• • • 164
Compiler Program No.3 (CP3) • • • • 164
Subroutine Pool . . . . . . . . . . . . . . . . 164
Change Input Buffer (JBUFFER) • • • 164
Next OPTAB Entry (NXTOPT) • • • • • 164
Error Recording (SERR) • • • • • • 164
Conversion Integer-Real (TRINRE) .164
Conversion Real-Integer (TRREIN) .164
Generate Object Code (GENERATE) •• 165
Store Object Time Registers
(CLE~RG) • • • • • • • • • • • .165
Operand Recognizer (OPDREC) •• • .165
Update OS~ Pointer (MAXCH)
..165
Semicolon Handling (SCHDLl
• .165
ROUTINEl •
• •••
• .165
ROUTINE2 •
• .166
ROUTINE3 •
• .166
ROUTINE4 •
• .166
ROUTINES •
• .166
ROUTINE6 •
• .166
ROUTINE7 • • • • .. .. • • •
• .166
ROUTINE8 • • • • • • •
• .166
ROUTINE9 •
• .166
ROUTINI0 •
• .166
ROUTIN11 •
• .166
ROUTIN12 •
• .166
ROUTIN13 •
• .166
ROUTIN14 •
• .167
ROUTIN15 •
• .167
Program Block Number Handling
(PBNHDL) • • • • • •
• .167
Parameterless procedure
Statement (PLPRST).
• .167
Termination Phase (IEX51) • • • •

.167

Pro3ram Block Table IV
(PBrAB4) • • • • • •
• .167
L~bel
~ddress
Table (LAT) • • .167
Data Set rable (DSTAB) • • • • • 168
~ddress
Table and END Record .169
Statement of Object Time storage
Requirements • • • • • • • • • • • 169
Dia3nostic Output • • • • • • • • 169
End of CDmpilation. •
• .169
CHAPrER 9: COMPILE TIME ERROR
DETECTI~N AND DIAGNOSTIC OUTPUT

• .170

Error Detection. • • • • • • • •
.170
Warnin3 Errors (Severity Code W) • • • 170
serious Errors (Severity Code S) • • • 170
Scan 1/11 Phase (IEXll) • • • 170
Identifier Table
Manipulation Phase
(IEX20) • • • • • • • • • • 170
Scan III Phase (IEX30).
.170
Subscript Handling Phase
(IEX40) • • • • • • • • • • 170
Compilation Phase (IEX50) • • 170
Termination Phase (IEX51) • • 171
rerminatin3 Errors (severity Code
T) • • • • • •
• • • • • • • • • 171
Diagnostic output • •

• • • 171

Error Pool

• .172

Message POOl •
• • • •
• .172
Error Message •
•
• • .174
L03ic of the Error Message Editing
Routine. . • • • • • • • •
• .174

PUT/GET (IHIGPR)
PUT • • •
GET • • •
~UTPUT • •
INPUT ••
~PENGP ••
CLOSEGP •
OPENEXIT.
CAP1GP ••
rHUNKOUT.
THUNKIN •

•
•
•
•
•
•
•
•
•
•

INARRAY/INTARRAY(IHIIAR)

• .181

INBARRAY (IHIIBA).

• .181

INBOOLEAN (IHIBO) • •

• .182

INREAL/ININTEGER (IHIIDE).

ALG~L

LIBRARY • • •

• .182

OUTREAL (IHISOR)

• .182

OUTREAL (IHILOR)

• .182

OUTARRAY (IHIOAR) • •

• .182

OUTBARRAY (IHIOBA) • •

• .182

OUTBOOLEAN (IHIOBO) • • •

• .182

OUTINTEGER (IHIOIN) • •

• .182

OUTSTRING (IHIOST)

• .182

(IHIOSY) •

• .183

OUTTARRAY (IHIOTA) •

• .183

• .176

FiKed Storage Area (IHIFSA) • •
• • • • 176
Common Data Area. • • • • • • • • • • 176
FiKed Storage Area Routines
• .176
Initialization (ALGIN)
• • • 177
Prologue (PROLOG) • • • •
• • • .177
Epilogue (EPILOG) • • •
• .177
Call Actual Parameter, Part 1
(CAP1) • • . • • • • • • • • •

Call Actual Parameter, Part 2
(CAP2) • • • • • • • • •
Value Call (VALUCALL).
Return Routine (RETPR~G) • •
C:'l.ll Switch Element, Part 1
(CSWE1) . • • • • • • • • . •
C~ll Switch Element, Part 2
(CSWE2) . • • •
••• •
Trace (TRACE)..
• •••
Load Precompiled Procedure
(LOADPP) • • • • • • • • •
standard Procedure Declaration
(SPDECL) • • • . • • • • • •
Get Main Stora3e (GETMSTO) • •
Program Interrupt (PIEROUT).
FSAERR • • • • . • • • • •
rermination (ALGrRt-lN) • • • •
Integer tD Real Conversion
(CNVIRD) • • • • • • • • • •
Real to Integer ConVersion
(CNVRDI/ENTIER) •

• .177

.178
.178
.178
• .178

• 179
.179
• .179

.179
• .179
.179
• .179
.179

.179
.179

SYSACT (IHISYS).
• • •
SYSACT. •
SYSACTl
SYSACT2
SYSACT3
SYSACr4
SYShCT5
SYSACT6
SYShCT7 •
SYSACT8
SYSACT9 •
SYSACT10.
SYSACTll.
• •
SYSACT12.
SySACT13 •
• • • • •
SYSACT14.
SYSACT15.
Subroutine Pool (IHIIOR) •
CLEARNOTTAB •
CLOSE ••
CLOSEPE •
CONVERT •
DCBEXIT •
ENDOFDATA
ENTRYNOTTAB •
EVDSN ••
NEXTREC •
~PEN.

Input/output Procedures • •

.182

INSYMBOL (IHIISY).

OUTSYI~OL

CHAPTER 10:

.180
.180
.181
.181
.181
.181
.181
.181
.181
.181
.181

• • .180

SYNAD ••

• •
• .183
• • • • • • • 183
• • • 183
• .183
• .183
• .183
• .183
• .183
• • • • • .183
• .183
.184
• .184
• .184
• • • • • • .184
• • • • • • .184
• .184
• .184
•
•
•
•
•
•
•
•
•
•
•
•

.184
.184
.184
.185
.185
.185
.185
.185
.185
.185
.185
.185

~~them~tical

Standard Functions. •

.185

APPENDIX Ill: COMPILER CONTROL FIELD
(HCOMPMOD). • • • • • • • • • • • •

.276

Jbject Time Error Routine (IHIERR) • • .186
APPENDIX V-A: PROGRAM CONTEXT MATRIX • • 278
CHAPTER 11: rHE OBJE:r MODULE.

.181

Jbject Module.

.181

APPENDIX V-B: STATEMENT CONTEXT MATRIX .279
Load Module. • • • • •
Jbject Time Tables.
•
Program Block rable (PBT)
L~bel
Address Table (LAT)
Data Set rable
(DSTAB) • •
~ote
Table (NOTTAB) • • • • •
D~t~
storage Area (DSA) •
storage Mapping Function (SMF)
Return Address Stack (RAS) •
Object rime Register Use. •

• .188
• .188
.188
.189
.190
• .191
.191
• • 193
.193
• .194

APPENDIX V-C: EXPRESSION CONTEXT
MATRIX.

··········
APPENDIX VI: COMPILE TIME ERROR
DErECTION •
··········
APPENDIX VII: OBJECT TIME ERROR
DErECTION .
··········

.219
.280
.283

APPENDIX VIII: COMPILE TIME WORK AREA
SIZES, AS A FUNCTION OF THE SIZE
oprION • • • • • • • • • • • • • • • • • 285

FLOwCHARrs • • • • • • • • • • • • • • • 196
APPENDIX I-A: CHARACrER SET -- FIRST
TRA~SLATI0N JF THE SOUR:E MODULE IN
rHE SCAN I/II PHASE • • • • • • • • • .212
APPENDIX I-B: CHARACTER SET -MJDIFICArION LEVEL 1 rEXr • •

.212

APPENDIX I-C: CHARACrER SET -MJDIFICATION LEVEL 2 TEXT • •

.212

APPENDIX 1-0: CHARA:TER SET -- STACK
OPERArORS USED IN rHE COMPILATION
p H~SE •

•

•

•

•

•

•

•

•

•

•

•

•

•

•

•

.273

APPENDIX II: INrERNAL REPRESENTATION
OF JPERANDS • • • • • • • • • • • • • .274
III: INTERNAL REPRESENTATION
OF SrANDARD PROCEDURE DESIGNATORS • • • 275

APPE~DIX

APPENDIX IX-A: STORAGE MAPS OF THE
CO~STITUENT LOAD MODULES OF THE ALGOL
COMPILER. • • • • • • • • • • • • • •
IEXOO - Directory. • • • • •
IEX10 - Initialization Phase • •
IEX11 - Scan 1/11 Phase. •
•
IEX20 - Identifier Table
Manipulation Phase. • • •
•
IEX21 - Diagnostic output.
IEX30 - Scan III Phase • •
IEX31 - Diagnostic Output.
IEX40 - Subscript Handling Phase
IEX50 - Compilation Phase. •
IEX51 - Termination Phase. •
APPENDIX IX-B: STORAGE MAP OF THE
OBJECT MODULE (AT EXECUTION) • •

.286
.286
.287
.288
.289
.290
.290
.291
.292
.293
.294
.295

APPENDIX X: SUMMARY OF COMPILER
PRJ GRAMS. •
• • • • • • •

• .296

APPENDIX XI: INDEX OF ROUTINES •

• .307

FIGURES

Figure 1. Constituent phases of the
AL30L Compiler. • • • • • • •
• ••
Figure 2. I/O Activity by Data set and
Phase • • • • • • • • • • • • • • • • •
Figure 3. Activity Table showing the
processing of source text and tables
by phase. • • • • • • • • • •
•
Figure !I. Use of main storage by
ALG~L Compiler. • • • • • • •
Figure 5.
Jption, DDname and Heading
fields, and pointers • • • • • • • • • •
Figure 6.
PARMLIST Table entry for a
Compiler option key-word. • • • •
Figure 7. Scan 1/11 Phase. Diagram
illustrating functions • • • • • • • • •
Figure 8. Scan 1/11 Phase
Input/Output. • • • • • • • • • • • • •
Figure 9. Identifier Characteristic.
Figure 10.
Identifier Table entry for
all identifiers except declared
~rr~y, procedure and switch
identifiers and labels. • • • •
•
Figure 11.
Identifier Table entry as
constructed in the Scan 1/11 Phase
for ~ declared array identifier •
•
Figure 12. Identifier Table entry for
a declared procedure identifier • • • •
Figure 13.
Identifier Table entry
constructed in the Scan 1/11 Phase
for ~ declared switch identifier • • • •
Figure 14. Identifier Table Entry
constructed in the Scan 1/11 Phase
for a declared label • • • • • • • • • •
Figure 15. Program block heading entry •
Figure 16. Program block heading
entry, as transmitted to the SYSUT3
d~t~ set. . • • • • • • • • • • •
•
Figure 17. For statement heading
entry
•••••••••••••••
Figure 18. For statement closing
entry
••••••••••••
••
Figure 19. Diagram illustrating the
processing of the Identifier Table • • •
Figure 20. Scope Handling Stack
oper~tors • • • • . • • • • . • • • • •
Figure 21. Group Table entries for a
for statement and for a block or
procedure • • • • • • • • • • • • • • •
Figure 22. One-byte Scope Table entry.
Figure 23.
One-byte Program Block
Number rable entry. • • • • • . • ••
Figure 2!1. Chart showing the logical
flow in the search for the opening
delimiter • • • • • • • • • • ~ • •
Figure 25. Exits from Scan 1/11 Phase.
Figure 26.
Private ~rea acquired by
the 3c:in 1/11 Phase, showing pointers
initialized. • • • • • • • •
• ••
Figure 27. Source text buffers and
pointers. • • • • • • • • • • . .
•
Figure 28.
Heading Entry constructed
at irritialization in Identifier Table
for Program Block 0 • • • • • • • • • •

14
17
18
19
27
27
32
35
36

37
37
38
38
38
39
39
39
39
!l0
!l2
45
!l6
46
47
49
52
53
53

Figure 29. Switches used in Scan 1/11
Phase • • • • • • • • • •
• 53
Figure 30. Branch Address Table
BPRTAB. • • • • • • • • • •
54
Figure 31. KEYTAB keys used in
TRANSOP routine • • • • •
• • 55
Figure 32. Delimiter Table (WITAB) • • • 61
Figure 33. Internal Names of boolean
constants 'TRUE' and 'FALSE' • • • • • • 63
Figure 3!1. Identifier Table
Manipulation Phase. Diagram
illustrating the functions of the
principal constituent routines. • •
69
Figure 35. Identifier Table
Manipulation Phase Input/Output • • • • 70
Figure 36. Identifier Table (ITAB)
entry, showing the identifier's Data
Storage Area displacement address, as
inserted by the Identifier Table
Manipulation Phase in bytes 9 and 10,
for all identifiers except those of
declared procedures, switches and
labels. • • • • • • • • • • • • • • • • 70
Figure 37. Two-byte entry in Program
Block Table II (PBTAB2) • • • • • • • • 71
Figure 38. Private Area acquired by
the Identifier Table Manipulation
Phase
• • • • • • • • • • • • • • • 72
Figure 39. Scan III Phase • • • • • • • • 76
Figure !l0. Scan III Phase input/output. 78
Figure 41. Function of pointers NOTER
and NOTEW in inputloutput operations
on the SYSUT3 data set • • • • • • '• • • 78
Figure 42. Diagram illustrating the
handling of Identifier Table (ITAB)
records •
• • • • • • • • • • • • 79
Figure 43. Entry in Left Variable
Table
• • • • • • • . • • • • • • • 82
Figure 44. Fourteen-byte Subscript
Table entry • • • • • •
83
Figure 45. Entry in Critical
Identifier Table (CRIDTAB).
• • 83
Figure 46. Entry for an array
identifier in the Array Identifier
Stack (ARIDSTAB). • • • • • • •
• • 8!1
Figure 47. Private Area acquired by
Scan III Phase. • • • • • • • • • • • • 87
Figure 48. Subscript Handling Phase • • • 102
Figure 49. Subscript Handling Phase
Input/Output • • • • • • • • • • • • • • 103
Figure 50. Optimization Table (OPTAB)
entry • • • • • • • • • • • • • • • • • 10!l
Figure 51. Diagram illustrating use of
the private area • • • • • • • • • • • • 104
Figure 52. Compilation Phase. Diagram
illustrating phase operations.
• .109
Figure 53. Compilation Phase
Input/Output. • • • • • • • •
• .110

54. Diagram illustrating the
fUnction of the ~perator/Operand
stacks • • • • • • • • • • • • • • • • • 112
Figure 55. Five-byte operand
representing an intermediate value or
address contained in an object time
re~ister or temporarily stored in the
register's reserved storage field in
a Data Stora~e ~rea • • • . • • • • • • • 113
Figure 56. Control Fields governing
use of object time general purpose
registers • • • • • • • • • • • • • • • 114
Figure 57. Control Fields governing
use of floating point registers, • • • • 115
Figure 58. Diagram showing the
compiler prograrr~ • • • • • • • • • • • 117
Figure 59. Private Area acquired by
Control section IEX40001 for the
Compilation Phase (IEX50) • • • •
.118
Fi~ure 60.
Entry in Program Block
Table III (PBTAE3). • • • • • • •
.120
Figure 61. Diagram showing code
generatej for switch declaration and
s~itch designator • • • • • • • • • • • 121
Figure 62. Object Time Storage
Mapping FUnction of an array • • • • • • 125
Figure 63. Code generated for declared
type procedure and procedure call • • • 132
Fi~ure 64. I/~ Table (IOT~B) • •
.138
Figure 65. For statement
classification byte in the For
statement rable • • • • • • ••
• .139
Figure 66. Logical structure of the
code generated for a Counting Loop • • • 141
Figure 67. Logical structure of the
code generated for an Elementary Loop
or Normal Loop • • • • • • • • • • • • • 141
Fi~ure 68. Logical structure of the
code generated for a Counting Loop • • • 142
Figure 69. Logical structure of the
code generated for an Elementary Loop .145
Figure 70. Logical structure of the
code generated for an Elementary Loop .146
Figure 71. Entry in subscript Table-C
(SUTABC) • • • • • • • • • • • • • • • • 148
Fi~ure

Figure 72. Logical structure of the
code generated for a Normal Loop. • • .149
Figure 73. Logical structure of code
generated for Elementary Loop or
Normal Loop • • • • • • • • • • • • • • 150
Figure 74. :omposition and execution
sequence of Load MOdules IEX21"
IEX31, and IEX51, containing the
Error Message Editing Routine
(IEX60000) • • • • • • • • • • •
•• 171
Figure 75. Error pattern stored in
Error Pool. • • • • • • • • ••
• .172
Figure 76. Message Pool entry. •
• .172
Figure 77. Three-byte Insertion Code
in the Message Pool entry (see Figure
76) • • • • • • • •
• • • •
.172
Figure 78. Format of the printed error
message • • . • • • • . • • • • • • • • 174

Figure 79. Four-byte parameter list
entry for a standard procedure call •• 180
Figure 80. Label of a PUT/GET record •• 180
Figure 81. Module names of
mathematical standard functions
contained in the ALGOL Library.
.186
Figure 82. Composition of the object
module. • • • • • • • • • • • •
• .187
Figure 83. Sketch showing the
organization of the load module • • • • 188
Figure 84. Object time Program Block
Table • • • • • • • • • • • • • • • • .189
Figure 85. Object time Label Address
rable (LAT) • • • • • • • • • • • • • • 189
Figure 86. Content of the data set
entries and the PUT/GET Control Field .190
Figure 87. Entry in the object time
Note Table (NOTTAB).
• • • • • • • 191
Figure 88. Content of the Data
Storage Area • • • • • • • • • • • • • • 192
Figure 89. Content of the 8-byte
storage field of a formal parameter
called. . . . . . . . . . . . . . . ." .193

Figure 90. Entry in the object time
Return Address Stack (RAS) • • • • • • • 194
Figure 91. Object time register use. • .195

CHARTS

~LGJL Compiler - Jverall ~low.
.197
Directory (IEKOO) • • • • • • •
.198
Initialization Phase (IEX10) •
• • .201
Scan 1/11 Phase (IEK11) • . • •
• • 203
Identifier Table Manipulation Phase
(IEX20) • • • • • • • • • • • • • • • .215

Diagnostic Output (IEX21) • • • •
• .218
Scan III Phase (IEX30) • • • • •
• .220
Dia~nostic Output (IEX31) • • • •
• .234
subscript Handling Phase (IEX40)
• .235
compilation Phase (IEX50) • •
• • • 238
Termination Phase (IEX51) • •
• .262
ALGJL Library • • • • • • • • • • • • • .265

Page of GY33-BOOO-O
Revised January 15, 1972
By TNL GN33-B129

SUMMARY OF AMENDMENTS
FOR GY33-8000-0
OS Release 21
TITLE CHANGES
Maintenance
Names of reference publications have been changed to reflect
their current titles.

11

Page of GY33-8000-0
Revised January 15, 1972
By TNL GN33-8129

CHAPTER 1: INTRODUCTION

PURPOSE OF THE COMPILER
The OS/360 ALGOL Compiler translates a
source program written in the OS/360 ALGOL
Language into an object module which may be
linkage edited and executed by an IBM
Systeru/360 computer. The final load module
consists in part of code generated by the
Compiler and, in part" of routines (in load
module form) drawn from the ALGOL Library.
The Library is a data set containing ALGOL
standard I/O procedures and mathematical
functions, as well as auxiliary routines
required by the object module at €xecution
time. The Library routines are combined
with the generated code at linkage edit
time, to form an executable load module.
The Compiler prints out a listing of the
source module and of the Identifier Table,
if the SOURCE option is specified" and
prints out diagnostic messages reflecting
syntactical errors detected in the source
module, as well as other errors occurring
during compilation.
THE COMPILER AND
SYSTEI'l

SYSTE~1/360

OPERATING

The ALGOL Compiler is a processing program of the System/360 Operating System.
It is executed under the control of the OS
supervisor" and utilizes the I/O and other
services of the OS Control Program.
A compilation is executed as a jOb step
by means of the job control facilities of
the Operating System.
The use of the
Compile!. is expla.ined in the OS AL~()~
l'rogt'~:r:~ s Gilide,.

sole typewriter,
device (magnetic
reader) •

and a
sequential
tape unit or card

ORGANIZATION OF THE COMPILER
Figure 1 indicates the modular structure
of the ALGOL compiler as well as the
essential operations performed in each of
the constituent phases. The Compiler consists of ten load modules, the first of
which, called the Directory"
remains in
main storage throughout compilation. The
other nine modules" representing the Working phases of the compiler" are loaded and
executed in sequence.

DIRECTORY (IEXOO)
The
Directory
consists
of a preassembled Common Work Area, used by .all
phases, as well as a number of auxiliary
routines
providing
interface with the
Operating System. The latter include the
initial entry and final exit routines which
receive control from, and return control
to, the Operating System.

INITIALIZATION PHASE (IEX10)
The Initializatiqn Phase:

MACHINE.SYSTEM

1.

The
m~n~mum
machine
configuration
required for execution of a compilation
using the ALGOL compiler is as follows:

Sets up a control field in the Common
Work Area. reflecting the
opticns
specified in the EXEC Statement invoking the Compiler.

2.

Determines the sizes of the private
work areas required by the individual
phases.

3.

Acquires main storage for a source
text input buffer and for the Error
Pool.

4.

Opens data sets.

5.

Executes a SPIE macro which specifies
the address of the program interrupt
routine in the Directory.

1.

2.

An IBM System/360 Model 30, 40, 50,
65, 75, or 91, or an IBM System/370
Model 135 (or higher} with the
scientific instruction set and at
least 64K bytes of main storage
capacity.
At
least
one
direct
access
input/output device; a printer; a con-

Chapter 1: Introduction

13

ALGOL COMPILER
EXEC
CALL/LINK/XCTl
ATTACH

I EXOO

IEXIO
INITIALIZATION

LINK
DIRECTORY

PHASE

I

I

XCTL

SYSIN

IEXII

Source
oVtodule

SCAN 1/11

5Y5UTl

SY5UT3

.oV.odified
Source Text
(ModiFication
level 1)

Identifier
Table

r--- ----,
---I lv1ain Storoge
I

I lv1ain Storage

I Errof Pool
I P.B. No. Table

SYSUT3

I

L ______

Identifier
Table

I

I
f--

I Error Pool
I Group Table

I

XCTl

r-------,

IEX20

(lTAB)

!
I
I
I

I Scape Table
I P.B. No. Table I

L ______ J

!
I

I

PHASE

IB)

IB)

IAJ

RETURN

SYSPRINT

Scan 1/11

SYSPUNCH

Source
fv\odule
listing

Reads the source module and lists all valid identifiers declared or specified in the source module in
the Identifier Table, together with descriptive internal names; stores character strings in the Constant Pool, replacing them in the output text by internal names containing the string's relative address; and generates TXT records of the strings
stored in the Constant Pool. Replaces all delimiter
words and multi-character operators by one-byte
symbols in the output text (called Modification
level 1). Detects syntactical errors and records
them in the Error Pool. Prints out a listing of the
source module if the SOURCE option is specified.

ESDRecord
& TXT Records
of Constant
Pool

IDENTIFIER

I

TABLE
/'MNIPULATION
PHASE

i

Prog,Blk.Toblelll
I Error Pool
I
L _ _ _ _ _ _ ...J

I

XCTl

r- - - - - - ,

1-- - - ---,
---1 lv1ain Storage
I

I Main Storage
I Error Pool

I

IL

I

Diognostic
Messoges

f-DIAGNOSTIC

_ _ _ _ _ _ ...l

I

SYSUT3

SYSPRINT
--

Identifier
Table

Identifier
Table
listing

IITAB)

SySPR!NT

IEX2l

Ie)

r---

OUTPUT

IA)

IB)

SySUTl
I-Aodified
Source Text
(Iv'oodification
Levell)

Identifier
Table

IITAB)

r-------,
I

I Scope Table
I
I Group Table
!--.
L _ _ _ _ _ _ ..J

I

SYSUT2

I

XCTl

I Main Storage

IEX30

Modified
Source Text
(Modification
Level 2)

PHASE

r------'l
Main Storage
I Error Pool
I For Statement
IL Table
______

I

XCTl

r- - - - ----,
I Main Storage

r-·

I

I

L _ _ _ _ _ _ --I

DIAGNOSTIC
OUTPUT

IE)
XCTL

SYSUTJ

r-------,

I~~TAB)

I N\oin Storage

I

I
IFor Statement
~
I Table
L _ _ _ _ _ _ -...l

'iAB)

I
I
I
...JI

I
SYSLIN/

SYSUT3

SYSPUNCH

Subscript
Table (SUTAB)
Left Variable
Table (LVTAB)

TXT Records
of Constant
Pool

IEX3l

I

I Error Pool

!
I

SCAN III

..........j

Ii;bl

I---

SYSUT2
fv\odiFied
Source Text
(/IIoodification
Level 2)

SYSUT3
Optimization
Table

IOPTAB)

!

I

I

r-- - --'-l
Ifv\o;n Storage

XCTl

I

Iprog.Blk.Table II I
rIFor Statement
ITable
L
_ _ _ _ _ _ -.JI

IEX50

I

COMPILATION
PHASE

XCTl

---- -l

IEX5l

Diagnostic Output

IE)

Subscript Handling
Const-ructs the Optimization Table, listing optimizable subscript expressions in for statements, in
which no term occurs as a 'eft variable in the for
statement. Optimizable subscripts are identified by
comparing each term in the expressions listed in the
Subscript Table with the entries from the same for
statement in the Left Variable Table. Also re-classifies for statements in the For Statement Table.

IF)
SYSUT3
Optimization
Table
(OPTAB)

Compilation

......, Main Storage

I

I For Statement
I Table

I
I

IL _ _ _ _ _ _ J'

SYSLIN/
SYSPUNCH

.

__ J

TFR/

r------i

~i~t:teR:i::s~fs :~i~ Ss\~rr~~: ra~i::t~~;stsc~~~~jet~t
SYSPRINT
Storage

~~~ui~;~es~f~
Messages

14

muw

~

END, ESD, TXT
& RlD
Records for
Loble Address,
Program Block,

~d~~e~~ti abr~s

!

RETURN I

Figure 1.

Generates TXT and RlD records of tables used by
the object module at execution time, as well as
ESD records for standard 1/0 procedures and mathematical functions, and the END record. Edits and
prints out errors recorded in the Error Pool or prints

I

I Prog.Blk.T!;Oblel1ll
I I/O Table
I
I label Addr.Tablel
L~r~ ~~I___ J

ATtn

ij,~~;,i;;~'~;;

Termination

TXT & RLD
Records of
Generated
Obiect Code

I

f-_
I
I

Reads the f.ioodification level 2 source text and generates an object module. Uses the Far Statement
Table to determine the logical structure of the generated code for each for statement. Uses the Optimization Table to generate code which pre-calculates a bose address and an incremental displacement for optimizable subscripts of arrays occurring
in for statements. Generates code to link precompiled standard functions and I/O procedures in the
library t-o the object module.

1-------,

---1 fv\oin Storage

I

Reads the Modification Level I source text output
by Scan 1/11 and generates a new source text (Iv\odification Level 2), in which externally represented
operands in statements are replaced by the corresponding internal names in the Identifier Table,
Stores constants in the Constant Pool, replacing
them by intemal names containing the storage address, and generates TXT records of the Constant
Pool. Classifies for statements in the For Statement
Table and lists linear subscript expressions and left
variables in counting loop and elementary loop for
statements, in the Subscript Table and Left Variable Table, respectively.

Edits the contents of the Error Pool and prints out
diagnostic messages reflecting the errors detected
by the Scan III Phose.

!

IF)

Scan III

Diagnostic
Messages

IEX4Q·

HANDLING PHASE

Diagnostic OlJtput
Edit~ tM contents of the Error Pool and prints out
diagnostic messages reflecting the errors detected
by the preceding phases.

SYSPRINT

SuBSCRIPT

ID)

Identifier Table f.iwJnipulation
Allocates object time storage addresses to all identifiers (other than declared procedure ~nd switch
identifiers and labels) listed in the Identifier Table,
noting the relative addresses in the corresponding
internal names in the table; records the total storage allocation for identifiers declared or specified
in each block or procedure in Program Black Table
II, and records multiple declaration errors in the
Error Pool. Prints oot a listing of the Identifier
Tobie if the SOURCE option is specified.

(D)

SYSUT3

I

Initialization
Determines sizes of work areas acquired by the
individual phases, according to the SIZE option;
opens data sets;. sets switches reflecting compilation options; and acquires storage for on input
buffer and the Error Pool. Also executes the SPIE
mocro-instroction.

SYSLIN/

..JI

(lTAB)

Directory
Contains entry and exit routines which receive
control from and return control to the Operating
System. Also contains Common Work Area for
inter-phase communication, as well as program
interrvpt, SYNAD and EOD routines. Resident
in main storage during compilation.

Constituent phases of the ALGOL Compiler

l

the exit routine in the Directory.

DIAGNOSTIC OUTPUT (IEX21)

SCAN 1/11 PHASE (IEX11)
The Scan 1/11 Phase reads the source
module and constructs the Identifier Table,
listing all identifiers declared or specified un the source module. The Identifier
Table is used in constructing a five-byte
internal name for each and every identifier
declared or specified in the source module.
In the case of declared labels, procedures,
and
switches,
the
internal
name
(constructed in its entirety in this phase)
contains the relative address of an entry
in the object time Label Address Table. In
the case of all other identifiers, the
internal name (constructed partly in this
phase and partly in the succeeding phase)
contains the relative address of an object
time storage field.
The internal name
ultimately replaces all externally represented operands in the source text (see
Scan III Phase below).
The
first
of the
Level
in the

Scan 1/11 Phase also generates the
of two intermediate transformations
source text, called Modification
1.
The principal changes reflected
first transformation include:

1.

An initial translation of all
ters to an internal code.

charac-

2.

The removal of all type declarations
and specifications.

3.

The replacement of ALGOL delimiter
words and multicharacter operators by
one-byte symbols.

IDENTIFIER TABLE MANIPULATION PHASE (IEX20)
The Identifier Table Manipulation Phase
processes the Identifier Table constructed
by the Scan 1/11 Phase. To each identifier
listed in the table, excepting declared
procedure and
switch
identifiers
and
labels, an object time storage field is
aSSigned,
the
relative
address being
inserted in the corresponding entry in the
Identifier Table.
This address specifies
the pOSition of the identifiers storage
field,
relative to the beginning of a Data
Storage Area. The Data Storage Area consists of the total amount of object time
storage space allocated to all identifiers
declared or specified in the particular
block or procedure. The size of the Data
Storage Area allocated to each block and
procedure is recorded in Program Block
Table II and transmitted to the Compilation
Phase via the Common Work Area.

See "Diagnostic output" below.

SCAN III PHASE (IEX30)
The Scan III Phase reads the Modification Level 1 text output by the Scan 1/11
Phase and generates a further transforrration of the source text (called Modification Level 2). In this version, the external names of operands in statements are
replaced by the internal names constructed
for declared or specified identifiers in
the Identifier Table. Similarly, all ccnstants are replaced by internal names containing a Constant Pool address.
After
being stored in the Constant Pool, ccnstants are subsequently transferred to TXT
records.
Logical features of all for staterrents
are detected and recorded in the For Statement Table. Among other things, the For
Statement Table assigns each for statement
to
one
of three loop classificaticns
(Normal Loops, Counting loops and Elementary Loops). The loop classification specifies the logical structure of the cede
generated in the Compilation Phase for each
for statement.
Subscript expressions of arrays found in
for statements, classified counting loops
or Elementary Loops, are analyzed
and
stored in the SUbscript Table, provided
they satisfy certain criteria with respect
to the terms in the expression and their
linearity within the for statement. Integer left variables in Counting and Elerrentary Loops are listed in the Left Variable
Table.

DIAGNOSTIC OUTPUT (IEX31)
See "Diagnostic Output" belo'N.

SUBSCRIPT HANDLING PHASE (IEX40)
The Subscript Handling Phase constructs
the Optimization Table, listing those subscript expressions of arrays contained in
for statements. which can be optimized in
the code generated for for statements.
Optimization refers to the minimization of
computing time involved in addressing the
elements of an array.
Chapter 1: Introduction

15

COMPILATION PHASE (IEX50)
The Compilation Phase reads the Modification Level 2 text output by the Scan
III Phase and generates object code to
perform the operations designated by statements in the source module.
operand addresses in the generated code
are obtained from the internal names of
operands in the Hodification Level 2 text.
The logical structure of the object code
generated for a for statement is governed
by the particular for statement's loop
classification in the For Statement Table.
Where a for statement contains optimizable
subscripts, the Optimization Table is used
in generating code which minimizes the
computing time involved in addressing array
elements.

TERMINATION (IEX51)
The Termination Phase constructs the
Data Set Table and Program Block Table IV;
generates TXT and RLD records for the
latter two tables and for the Label Address
Table; generates an END record as well as
ESD records for all Library routines to be
combined with the oojectmodule; processes
any errors detected in the Compilation
Phase;
and terminates the Compiler by
releasing main storage and returning control to the invoking program via the Final
Exit routine in the Directory. The Termination Phase logically
constitutes
an
extension of the COllipilation Phase and is
described in the same chaPter, namely Chapter 8.

transferred directly to a terminating routine in the Termination Phase., after all
recorded errors have been printed out ty
the Error Message Editing Routine in the
appropriate diagnostic output modUle (see
Figure 1).

ALGOL LIBRARY
The Library is a partitioned data set
(SYS1.ALGLIB) consisting of routines which
perform the standard mathematical functions
and I/O procedures defined in the ALGOL
Language.
The appropriate routines, corresponding to the standard functions or I/O
procedures called in the source module, are
linked to the object module at linkage edit
time. ESD records to call standard fUnctions or I/O procedures are generated in
the Termination Phase.
The Library also contains the Fixed
Storage Area, which consists of a set pf
auxiliary
routines
and control fields
required
for
execution of the object
module. The auxiliary routines include the
Initialization and Termination routines, as
well as other routines which acquire or
release main storage and administer the
calling of procedures.
The Library is
further described in ChaFter 10.
An ob ject tirr,e Error Routine is provided,
which
forms
a
module
of
the
SYS1.LINKLIB data set. The Error Routine,
which is loaded only if an Object time
error is detected, prints out an appropriate error message and terminates the object
program. The error routine is described in
Chapter 10.

DIAGNOSTIC OUTPUT (IEX21, IEX31, AND IEX51)

THE OBJECT MODULE

The compile time Error !1essage Editing
Routine, which forms a control section of
each of load modules IEX21,
IEX31, and
IEX51, prints out
diagnostic
messages
reflecting errors detected by the preceding
phase or phases in the source module. Any
errors detected are recorded by the particular phase in the Error Pool, in the form
of error patterns. At the conclusion of a
phase, the Error Message Editing Routine
processes the contents of the Error Pool
and prints out appropriate diagnostic messages. Errors are classified as warning
errors, serious errors, or
terminating
errors.
The recognition by any phase of a
terminating error causes control to be

The structure of the object module is
descr ibed in Chapter 11.

16

INPUT/OUTPUT ACTIVITY
The data sets used by the Compiler are
indicated in Figure 1. I/O operations in
each of the several working phases are
discussed in further detail in the relevant
chapters. The table in Figure 2 summariZES
I/O activity during compilation, in terms
of the macro instructions issued.

Data Set Tobi e

SYSIN
QSAM

SYSUTI
BSAM

SYSUT2
BSAM

Data Set
SYSUT3
BSAM

IEXOO

CLOSE~

CLOSE

CLOSE*

IEX10

OPEN
CLOSE*

OPEN
CLOSE*

OPEN

IEXll

GET
CLOSE

WRITE
CHECK

Phase
Access method used:

..

IEX20

SYSLIN
QSAM

SYSPRINT
QSAM

SYSPUNCH
QSAM

CLOSE'

CLOSE*

CLOSE *
PUT

CLOSE*

OPEN

OPEN (if used)

OPEN
PUT

OPEN (if used)

WRITE
CHECK

PUT

"

PUT

..

READ, CHECK
WRITE, CHECK
NOTE,
POINT

..

IEX21
IEX30

READ
CHECK
CLOSE

WRITE
CHECK

CLOSE (1)
READ, CHECK
WRITE, CHECK
NOTE, POINT

PUT

PUT

..

IEX31
IEX40

EAD
!,-HECK

READ, CHECK
POINT
WRITE, CHECK

IEX50

~EAD, CHECK

READ, CHECK

PUT

!,-LOSE

CLOSE

PUT
CLOSE

IEX51
IEX51 002

CLOSE'

..

PUT
PUT
LOSE

CLOSE

* Data set closed in ever:'t of program interrupt or unrecoverable I/O error •

.. In each of the modules indicated, a call is made to the PRINT subroutine
in the Directory (IEXOO), which executes the PUT macro instruction.

Figure 2.

1/0 Activity by Data Set and Phase

INTERPHASE COMMUNICATION BY SOURCE TEXT
TABLE

A~ID

The source module is subjected to two
transformations before object code is generated in the Compilation Phase.
These
transformed versions of the source text are
named Modification Levelland Modification
Level 2. They are described in Chapters 3
and 5, respectively. Modification Level 1
is generated by the Scan 1/11 Phase, Modification Level 2 bY the Scan III Phase.
MOdification Level 2 forms the main input
to the Compilation Phase, which generates
the ultimate object code.
The Ta~les constructed in the several
phases and transmitted to one or more
subsequent phases are indicated in Figure
3. A detailed description of the function
and contents of each table is given in the
chapters indicated:

Descri~ed

Narre of Table
Address Table
Data Set Table (DSTAB)
For Statement Table (FSTAB)
Group Table (GPTAB)
Identifier Table (ITAB)
I/O Table (IOTAB)
Label Address Table (LAT)
Left Variable Table (LVTAB)
Optimization Table (OPTAB)
Program Block Number Ta~le
(PBTAEl )
Program Block Table II
(PBTAB2)
Program Block Table III
(PBTAB3)
Program Block Ta~le IV (PBTAB4)
Scope Table (SPTAB)
Semicolon Table (SCTAE)
subscript Table (SUTAB)

in

ChaQter
8
8, 11
6

4
4, 5, 6
8
8, 11
6
7

4
5
8
8, 11
4
4
6

Chapter 1: Introduction

17

Activity Table
Text /Table

Initialization
Phase
(IEXIO)

Scan 1/11
Phase
(IEXI1)

(All table. except those marked by
asterisks are transmitted between
phases via the Comman Work Area)

Identifier
Table
Manipulation
Phase
(lEX20)

Diagnostic
Ou~t
(IE 21)

Scan III
Phase
(IEX30)

Diagnostic
Ou~t
(IE 31)

Subscript
Handling
Phase
(lEX40)
-excluding
Compilation
Phase

Compilation
Phase
(lEX50)

Termination
Phase
(lEX51)

Initialization

Source Text.

B

A

A

Address Table

C,W

Data Set Table (l>STAB)

C,W

Far Statement Table (FSTAB)

C

Group Table (GPTAB)

C

Identifier Table (lTAB) *.

C

M

T

T
T

M

I/O Table (lOTAB)

C

T

lab.1 Address Table (LAT)

C

W

Left Variable Table (LVTAB)· *

C

Optimization Table (OPTAB)· *

T
C

Program Black Number Table (PBTABI

C

Program Black Tabl. II (PBTAB2)

M,T

C

C

Program Black Table III (PBTAB3)

Scope Table (SPTAB)

C

Semicolon Table (SCTAB)

C,T

T

C

Subscript Table (SUTAB)* •

The source text is transmitted between phases via
external storage, unless the text is less than a full
buffer in length. In the latter case it is transmitted

~

by way of Source Text Buffer I in the Comman Area.

* lie

Table trmsmitted between phases by way of
ternal storage device (see Figure 1).

Figure 3.

CI1

ex-

A
B
C
M

- Source Text transformed
- Table canstucted
- Table completed or madified

T - Table utilized and terminated
W - Table transmitted ta object module

Activity Table showing the processing of source text and tatles by phase

The storage maps in
the layout of routines
storage in each of
compiler. In terms of
storage utilized by
divided into five main

AREA OCCUPIED BY DIRECTORY AUXILIARY
ROUTINES
Appendix IX indicate
and tables in main
the phases of the
function, the main
the Compiler may be
areas:

Area occupied by auxiliary routines of
the
Directory
(Control
Section
IEXOOOOO)

2.

Corr~on

3.

Areas occupied by the operative phase
(the operative module)

4.

Private area acquired by the operative
phase

5.

Common Area occupied by the Error Pool
and Source Buffer 1

WOrk Area (Control
IEXOOOOl Of the Directory)

Section

These areas are pictured in Figure 4.
18

T

- Source Text terminated (object code generated)

USE OF' MAIN STORAGE

1.

T
C,W

Program Block Table IV (PBTAB4)

*

T

T

The composition of this control section,
which contains auxiliary routines interfacing with the O~erating System, as well as
Data Control B16cks for all data sets
except SYSUTl and SYSIN, remains unchanged
during compilation.

THE COMMON WORK AREA
The Common Work Area is an area of
approximately 3500 bytes, resident in main
storage throughout compilation. Except for
the lower 540 bytes, whose assignment is
fixed, the composition of the Corr.rr.on Work
Area varies between ~hases and is defined
by a Dummy Control Section in each phase.
The Comrr.on Work Area functions as an interphase corr.munication and control area. It
contains a control field, initialized by
the Initialization Phase and modified in
the subsequent phases; a save area; a
general transmission area used for communicating addresses, parameters and counters

used by all phases in common~ and a general
work area. The general work area, which
represents the major part of the Common
Work Area, provides space for the construction and/or transmission between successive
phases of small-size tables.
In the Scan
1/11 Phase, an 80-byte field of the Common
Work Area is used for processing card-image
records of the (translated) source module.

vate area for the construction of relatively large size tables which are transferred
to external storage devices. The private
area is in every case released at phase
termination.
The private work areas are
described in the relevant chapters under
the heading "Initialization". In the Scan
1/11 and Compilation Phases., the private
area provides space for one source text
buffer, while the Scan III Phase acquires
three buffers.
(See Corrmon Area.)

Directo!l: Routines and DCS"s

Common Work Area

(Directory - IEXOO - comprising
auxiliary routines and Common
Work Area, is resident in main
storage throughout compi lation)

(Composition defined by dummy
control section in each phase)

Operative Module

(lEX10, lEXll , lEX20, lEX21, 1000, lEX31,
lEX40, lEXSO and lEX51, in sequence)

(Nodules loaded in sequence)

Private Area
(Variable - acquired by each
phase and released at phase
termination)

Common Area

(Error Pool and Source Text Buffer 1)

Figure 4.

Use of main
Compiler

(Acquired by Initialization
Phase - released at termination of compilation)

storage

by ALGOL

AREA OCCUPIED BY OPERATIVE MODULE
The operative module, which varies in
size, is loaded adjacent to the Common work
Area.

COMMON AREA
The Common Area is acquired by the
Initialization Phase and is not released
until Compiler termination.
It provides
space for the Error Pool and for Source
Buffer No.1. The Common Area buffer is
provided in order to enable the source text
to be transmitted between phases via rrain
storage, in the event the text occupies
less than a full buffer. If either or both
of the intermediate versions of the source
text exceeds the buffer length, the text is
transferred to external storage. In each
of the phases which process the source
text, one or more additional buffers are
provided for in the private area acquired
(and subsequently released) by the phase.
In the Scan 1/11 and Compilation Phases,
the private area contains one source buffer, while in the Scan III Phase, the
private az'ea contains three buffers.
In the Scan 1/11 Phase, the Modification
Level 1 text is assembled and transmitted
to the Scan III Phase in the Common Area
buffer, unless the text exceeds the buffer
length. In the latter case, the text is
transferred to SYSUT1, using the Corrmon
Area buffer and the private area buffer as
output buffers.
In the Scan III Phase, the Modification
Level 1 source text is processed in the
Common Area buffer (if the text was transmi tted in mai n storage) " or al ternati vely,
in the OOmmon Area buffer and a private
area buffer (if the text is input from the
SYSUT1 data set). The Modification Level 2
text is assembled in one (or two) buffers
in the private area and, if it exceeds the
buffer length, it is transferred to SYSUT2.
If the text is less than the buffer length,
it is moved to the Common Area buffer,
before the private area is released, for
transmission to the Compilation Phase in
main storage.

PRIVATE AREA ACQUIRED BY OPERATIVE MODULE
All of the phases of the Compiler"
except
load
modules
IEX21 and IEX31
(diagnostic output modules), acquire a pri-

In the compilation Phase, the Modification Level 2 source text is processed in
the Common Area buffer (if the entire text
was transmitted in main storage) or, alternatively, in the Common Area buffer and a
Chapter 1: Introduction

19

private area buffer (if the text was transmitted on the SYSUT2 data set).

vention applies to operators used by
the Compiler internally, e.g. Beta,
Proc, Epsilon. ExceFt for the power, !
aSSignment and scale factor operators \
(represented respectively as Power,
Assign, and Scale Factor), arith~etic
and relational operators are represented by their commonly understood
symbols, e. g.
+, <, =.
Parentheses
and brackets are also represented
symboli cally, as in (, ), [, ]. The
complete range of internal character
representation during the
various
phases of the Compiler is indicated
in the code tables in Appendices i-a
through i-d.

CONVENTIONS

The following conventions are
this manual:

observed

in

1.

ALGOL delimiter words in the text of
a source module are represented in
the manner defined
by
the
IBM
System/360 Operating System
ALGOL
Language, e.g.
'BEGIN' or 'REAL'.

2.

With certain exceptions,
one-b}'te
characters in the internal code of
the
Compiler,
representing ALGOL
delimiter words, as well as other
conventional delimiters, are
represented as in the following exampIes: Beg:in, Goto, Power, Or, Comn;a,
.QeciIl@.LRoint, Array. The same con-

3.

20

Syntactical, logical, or operational
errors detected during co~pilation
are identified by the serial nurrter
in the corresponding diagnostic message key.
Thus, for example, the
error
whose detection produces a
diagnostiC message with the message
key IEX034I, is identified in this
manual as "error No. 34. n

CHAPTER 2: DIRECTCRY (IEXOO)

PURPOSE OF THE DIRECTORY
The Directory (IEXOO) is the first of
ten load modules of the ALGOL Compiler. It
is the first module to be loaded in main
storage, and unlike the other nine modules,
which are loaded, executed and then displaced by the succeeding module, the Directory remains in main storage throughout
compilation.
The function of the Directory is:
1.

2.

3.

To provide the requisite interface
between the compiler, on the one hand,
and the invoking program and the Operating System, on the other.
This
interface is provided by (a) the Initial Entry routine, which receives
control from the invoking program and
loads the next module (IEX10)i and the
Final Exit routine, which returns control to the invoking program at the
close
of
the
Termination
Phase
(IEX51);(b)
the Program Interrupt,
SYNAD
and
EODAD
routines, which
receive control from the Operating
System in the event of an unexpected
interrupt
and pass control to an
appropriate routine in the operative
phase; and (c) data control blocks for
data sets used by the compiler.
To provide a PRINT Subroutine., used in
con~on by several phases, which prints
out compilation output on the SYSPRINT
data set, on call from the operative
phase. The printed output includes
diagnostic messages indicating syntactical errors detected in the source
module, and, depending on the Computer
options specified, listings of the
source module and
the
Identifier
Table.
To provide the Common Work Area, an
area of main storage used for the
transmission of tables, addresses and
other
data between phases.
Among
other things, the Common Work Area
contains a common register save area,
a
Control Field (HCOMPMOD
see
Appendix IV) which governs operations
in each phase, and an Area Size Table
which specifies the sizes of the private areas acquired by the several
phases. The Control Field and Area
Size Table, which are initialized or
constructed
by
the Initialization
Phase (IEX11), reflect the compiler
options specified by the user.

The
program
ATTACH
control

Directory is loaded by the invoking
by means of a LOAD, XCTL, LINK, or
macro instructicn, or by an EXEC
card.

ORGANIZATION OF THE DIRECTCRY
The Directory consists of two control
sections, named IEXOOOOO and IEX00001, respectively.
Control Section IEXOOOOO contains the Initial Entry, Final Exit, Program Interrupt, SYNAD. EODAD, and Print
routines, as well as data control tlocks
for all except two of the data sets used by
the compiler (the other two are contained
in the Common Work Area). Control Section
IEX00001 comprises the Common Work Area.

CONTROL SECTION IEXOOOOO
The principal components of Control Section IEXOOOOO are as follows:

Initial Entry Routine
The Initial Entry routine receives control from the invoking program.
The rcutine saves registers in the Invoker's save
area, loads register 13 with the address of
a save area in IEXOOOOO, and executes a
LINK macro instruction to load and activate
the Initialization Phase (IEX10).

Final Exit Routine
The Final Exit routine is entered from
the Termination Phase (IEX51).
Registers
are restored and control returned to the
Invoker by a RETURN macro instruction.

Program Interrupt Routine (PIROUT)
PIROUT is activated by the control program in the event of a program interrupt.
The address of PIROUT is specified by a
SPIE macro instruction in the Initialization Phase (IEX10).
Chapter 2: Directory (IEXOO)

21

PIROUT records error No.209 in the Error
Pool (indicating a program interrupt) and
transfers control to a closing routine in
the operative phase, the address of which
is stored at a location named ERET in the
Common Work Area. ERET is updated by the
initialization routine (as well as by other
routines) in each of the several phases, so
as to indicate the correct entry point of
the
closing routine in the particular
phase. A switch (TERR -- see Appendix IV)
turned on by PIROUT to indicate a terminating error, causes the terminating routine
in the operative phase to transfer control
to the Error Message Editing routine in the
next diagnostic output module (IEX21, 31,
or 51) for print-out of the errors recorded
in the Error Pool. The same TERR switch
causes the Error Message Editing Routine in
the particular diagnostic output module to
transfer control to the terminating routine
in the Termination Phase (IEX51), rather
than to the next successive phase.
Where a program interrupt occurs in the
closing routine of the operative phase (in
which case the same program interrupt will
recur after PIRou'r has returned control to
the defective cloSing routine),
PIROUT
exits directly to the terminating routine
in the Termination Phase.
PIROUT is temporarily replaced as the
program interrupt exit by the execution of
a second, SPIE macro instruction in the
initialization routine of the Scan III
Phase. The substitute routine provides for
special handling of exponent overflow and
underflow interrupts, but passes control to
PIROUT in all other cases.
PI ROUT is
restored as the program interrupt exit by a
final SPIE macro instruction in the closing
routine of the Scan III Phase.

Sysprint I/O Error Routine (SYNPR)
The Sysprint I/O Error Routine is activated by the control program in the event
of an unrecoverable I/O error involving the
SYSPRINT data set.
The address of the
routine is stored in the relevant DeB.
The routine turns on a switch named PRT
(Appendix IV) to indicate that the printer
is down, and then enters the SYNAD routine
to take the same actions as that taken for
all other data sets. The PRT switch (if
turned on) causes the Error Message Editing
routine to print out a single message (for
Error No. 210) on the console typewriter,
indicating that the printer is inoperative.
End of Data Routines (EODAD1"
EODAD3, AND EODADIN).

The End of Data routines are entered
from the control program when a data input
operation from the SYSUT1, SYSUT2, SYSU~3,
or SYSIN data set is terminated at the end
of the data set.
The address of the
particular End of Data routine is stored in
the data set's DCB.
The End of Data routine loads the entry
point of the appropriate ECD exit routine
in the operative phase, and then passes
control to that routine. The entry point
of the EOD exit routine is stored ty the
initialization routine in each phase which
processes a data set, at the appropriate
one
of
the locations EODUT1, EODUT2,
EODUT3, and EODIN in the Common Work Area.
The phases which specify an EOD exit routine for an end of data condition, the data
sets involved, and the locations where the
entry points are stored, are as follows:
Data Set

I/O Error Routine (SYNAD)
SYNAD is activated by the control program in the event of an unrecoverable I/O
error involving the SYSIN, SYSLIN, SYSPu"NCH, SYSOT1, SYSUT2, and SYSUT3 data
sets. The address of the routine is stored
in the relevant DCBs.
The routine closes the affected DCB,
records error No.
210 in the Error Pool
(using the ddname contained in the DCB),
sets the TERR switch on to indicate a
terminating error, and passes control to
the closing routine in the operative phase,
whose entry point is specified in the
location ERET.
(See also Program Interrupt
Routine PIROUT).
22

EODAD2,

Storage Field for
EOD Exit

IEXll

SYSIN

EODIN

IEX20

SYSUT3

EODUT3

IEX30

SYSUT1

ECDUT1

SYSUT3

ECDUT3

IEX40

SYSUT3

ECDUT3

IEX50

SYSUT2

EODUT2

SYSUT3

EODUT3

Note that End of Data exit routines for
SYSUT2 and SYSUT3 are specified toth in the
the Compilation Phase initialization routine in IEX40. and at the start of IEX50
(see "Phase Initialization" in Chapter 8).

Print Subroutine (PRINT)

Data Control Blocks

The PRINT subroutine prints out text on
the SYSPRINT data set on call from the
operative phase. Depending on the compiler
options specified, the subroutine may be
called by the following routines in the
modules indicated:

Control Section IEXOOOOO contains Data
Control Blocks (DCBs) for the following
data sets:

CIB (IEX11) - Source module listing
PRINTITB
(IEX20) - Identifier
listing

SYSPRINT
SYSLIN
SYSPUNCH
SYSUT2
SYSUT3

Table

COT27 (IEX21, 31, 51) - Diagnostic messages
PRINTT (IEX51) - Object module storage
requirements
The text printed out includes front page
titles, headlines, as well as variatle
(compiler-generated) text. A single line
of text is printed by each call to PRINT.
After a page shift, one or more headlines
are printed at the top of the new page
before the next line of text is printed.
Text other than headlines is assembled ty
the calling routine in a print buffer
previously specified by. PRINT (in register
1). Headlines are transmitted by the calling routine in a Common Work Area field
named PAGEHEAD (which accommodates up to
three lines of text) and are subsequently
moved by PRINT to a print buffer for
output. The headlines are assembled at
PAGEHEAD during initialization of each particular phase.
PRINT maintains both a line and page
count, and inserts the control character in
the appropriate line of text to effect the
required page shift.
Before a page is
shifted, the next line of text is temporarily moved from the print buffer to a save
area, to enable the headline(s), together
with the page number, to be printed at the
top of a new page.
Control characters
governing line spacing between headlines
are supplied by the calling routine in the
headlines.
These characters are used by PRINT to
add the correct increment to the line
count. The control character to effect a
standard single-space
line
change
is
inserted by PRINT at the beginning of each
new print buffer.
special page shifts,
e.g.
following the title page, are specified by the calling routine by arbitrarily
raising the line count, maintained in the
Common Work Area. The calling routine may
also suppress one or more headlines by
inserting a special character at the beginning of the particular headline.

The DCB addresses are listed in the
Common Work Area, £cllowing the register
save area. The foregoing data sets are
required throughout compilation. DCBs for
the SYSIN data set, which is not used after
the Scan 1/11 Phase (IEX11), and the SYSUT1
data set, which is not used after the Scan
III Phase (IEX30), are stored in the Corr.rron
Work Area.
Data Sets are opened ty the
Initialization Phase (IEX10), which also
modifies the information in the DCBs to
reflect special user requirements concerning block sizes and record lengths.

CONTROL SECTION IEX00001 (COMMON WORK AREA)
The Common Work Area is an area of
approxlinately 3500 bytes used by all phases
of the Compiler., principally for the construction and/or transmission tetween phases of small-size tables, essential control
information, and address data. Except for
a limited number of fields which remain
essentially unchanged throughout compilation, the composition of the CORmon Wcrk
Area varies between phases.
Its composition is defined by a dummy control section
in each phase.
The general layout of
tables and other data in the Common Work
Area in each phase is indicated in the
storage maps in Appendix IX-a.
The principal fields which remain fixed
in position in the Common Work Area are the
following.

Register Save Area
A standard format save area of 72 tytes.,
addressed throughout compilation by Register 13, is provided for saving registers
when control is passed to the control
program at any point during execution of
the phases IEX10-IEX51.
Chapter 2: Directory (IEXOO)

23

DCB Addresses
The addresses of the Data Control Blocks
of all seven data sets used by the Compiler
are recorded in the Common Work Area,
immediately below the general save area.

in succession (e.g.
the pointer PBPT,
which is incremented in the Scan 1/11 and
Scan I I I Phases to indicate the displacement of each point in the object module,
beginning with the Constant Pool).

Area Size Table (INBLKS)
End of Data Exit Addresses
This field contains the entry point(s)
of the closing routine(s) to be entered in
the operative phase in the event of an End
of Data condition on anyone of the data
sets SYSIN. SYSUT1. SYSUT2. and SYSUT3.
The appropriate entry point is fetched from
this field by the EODAD routine in the
Directory when an EOD condition occurs.
The field is updated by each phase at
initialization so as to specify the correct
closing routine in the phase.

Compiler Control Field (HCONPMOD)

The Area Size Table specifies the sizes
of work areas or buffers acquired by the
individual phases for the construction of
tables transferred to auxiliary storage.
It also specifies minimum block sizes for
certain data sets. The relevant entries in
the table are referenced by the initialization routines of the several phases, before
the GETMAIN instruction for the particular
phase's private area is issued.
The Area Size Table is set up by the
Initialization Phase (IEX10), Which determines the appropriate size for each wcrk
area, according to the SIZE option specified by the user. The table in Appendix
VIII shows the increase in work area sizes
as the value of the SIZE option increases.

A three-byte field in the Common Work
Area named HCOMPMOD is used as a Compiler
Control Field.
All excel:lt one of the 24
binary positions in this field are used as
switches to govern operations in each phase
of the compiler. The significance of each
switch is indicated in Appendix IV.

Work areas for small-size tables transmitted between phases via the Common Work
Area are defined by a DS statement in the
durr.my control section defining the Common
Hork Area in each phase.

The Control Field. which is initialized
by the Initialization Phase (IEX10). indicates. among other things, the Compiler
options specified by the user. It also
indicates
significant
error conditions
detected by anyone phase, which may cause
the Compiler to enter Syntax Check Mode, or
alternatively, to terminate
operations.
The compiler options are listed in Chapter

Headline Storage Area (PAGEHEAD)

3.

Communication Area
The Communication Area contains addresses. pointers, counters, and other information used by two or more phases in common.
The address information may be variable (as
in the case of the program interrupt or I/O
error closing routine address at ERET,
which changes with each phase) or invariable (as in the case of the address of the
Common Area Source Text Buffer 1, stored at
SRCE1F~D).
Counters designate literal number values (e.g. the line count referenced
by the PRINT subroutine at LINCNT). Pointers designate address displacement values
which may be incremented by several phases
24

This area is provided for the headlines
used in the printed output of the individual phases.
The area accommodates up to
three
90-character
headlines.
The
appropriate headlines, which are stored in
the area at initialization of each phase
generating printed output, are fetched by
the PRINT subroutine on call from the
operative phase.
The principal contents of the variable
part of the Common Work Area during the
several phases are as fOllows.

Preliminary Error Pool
A Preliminary Error Pool is provided in
the originally assembled Common Work Area,
for the recording of any errors which may
occur
before
the main Error Pool is
acquired by the Initialization Phase.
Any
recorded errors are immediately moved to
the main Error Pool, after main storage for
the latter has been acquired. The Prelirri-

nary Error Pool is deleted after the
of the Initialization Phase.

Data

close

The above list does not include these
tables which are transferred to external
storage.
The processing of all tables,
except those used locally, is indicated in
detail in Figure 3.

ontrol Blocks for SYSIN and SYSUTl

The DCBs for the SYSIN and SYSUTl data
sets are stored in the variable part of the
Conuuon Work Area, since the data sets are
not used beyond a certain point, and the
area occupied by the DCB's can be released
for other uses.
The DCB for SYSIN is
deleted after the close of the SCAN 1/11
Phase, while the DCB for SYSUTl is deleted
after the close of the Scan III Phase.

Tables

Other Data
The remainder of the variatle part of
the Common Work Area is used in the various
phases for switches, addresses, counters,
and pointers of local significance only
(i.e. used exclusively by the operative
phase).
In the storage maps in Appendix
IX-a,
these
areas
are identified as
"private work areas".

The following tables are constructed by
the several phases in the variable part of
the Common Work Area. A majority of these
is transmitted to at least one or more
subsequent phases via the Common Work Area.
A few are used locally only.
IEXll

P.B. No. Table (PBTAB1)
scope Table (SPTAB)
Group Table (GPTAB)
Semicolon Table (SCTAB) -- local
use

IEX20

Program Block Table II (PBTAB2)

IEX30

For Statement Table (FSTAB)

IEX40

Address Table (ATAB) -- local use

IEX50

Program Block Table III (PBTAB3)

IEX51

Program Block Table IV (PBTAB4)

Chapter 2: Directory (IEXOO)

25

CHAPTER 3: INITIALIZATION PHASE (IEX10)

The logic of the Initialization Phase is
outlined
in Flowcharts 007-010 in the
Flowchart section. The following sections
describe the principal functions perforned.

PURPOSE OF THE PHASE
The Initialization Phase:
1.

Saves registers used by the Initial
Entry Routine in the Directory, and
addresses a save area (by loading
register 13) for storing registers
when lower-level routines, e.g.
in
the control program, are invoked by
any of the subsequent phases.
The
save area addressed comprises
the
first 72 bytes of the Common Work
Area.

2.

Executes the SPIE macro, specifying
the PIROUT routine in the Directory as
the program interrupt exit.

3.

Reads the options specified for
Compiler by the invoking program
turns on a set of switches in
HCOMPMOD Control Field to reflect
options specified.

4.

Inserts ddnames (if any are specified
by the invoking program) in the corresponding Data Control Blocks.

5.

Selects an Area Size Table, according
to the machine system capacity indicated by the SIZE option. The Area
Size Table specifies the main storage
space to be provided in each phase for
work areas and buffers, as well as
maximum data set block sizes.

6.

7.

26

the
and
the
the

Acquires main storage for the Common
Area, containing the main Error Pool
and
Source Buffer 1.
Any errors
detected before the main Error Pool is
acquired are recorded in the Preliminary Error Pool in the Common Work
Area.
Opens all data sets, after specifying
the addresses of Open-Exit routines in
the Data Control Blocks of the SYSIN,
SYSLIN, SYSPUNCH, and SYSPRINT data
sets, and after inserting block sizes
in the Data Control Blocks of the
SYSUT1 and SYSUT2 data sets (the block
size is equal to the length of the
Source Text Buffer). Block sizes for
SYSIN, SYSLIN, SYSPUNCH, and SYSPRINT
are inserted by the particular open~
Exit routine, using the block sizes
(if
any)
specified
in
the
DD
statements, or the maximum block size
specified in the Area Size Table. The
block size for SYSUT3 is included in
the assembled Data Control Block.

EXECUTION OF TEE SPIE MACRO
At entry to the Initialization Phase,
after registers used by the Initial Entry
routine have been saved, and after Register
13 has been loaded with the address of the
general save area in the Ccmmon Work Area,
a SPIE macro instruction is executed which
specifies the address of the Program Interrupt Exit routine (PIROUT) in the Directory. By virtue of the SPIE macro instruction, the Operating System passes control
to PIROUT in the event of a program interrupt.
When entered (in the event of a
program interrupt), PI ROUT passes control
to the routine whose address is stored at
the location named ERET in the Common Work
Area.
ERET is updated in each phase so as
to indicate the address of the appropriate
closing routine in that phase. Immediately
after execution of the SPIE rracro, the
address of the Initialization Phase closing
routine GOTOTERM is stored at ERET. GO~O­
TERM transfers control directly to the
Termination Phase (IEX51), after releasing
main storage and closing data sets.
GOTOTERM is subsequently replaced as the
program interrupt exit by OPEXERR
and
GOTOEDIT (the latter exits to IEX21 for
output
of any recorded errors,
before
transferring control to IEX51).

PROCESSING COMPILER OPTIONS,
HEADING INFORMATION

DDNA~ES,

AND

The compiler may be invokedCa) by means
of the job control EXEC statement, i.e.
using the facilities of the control program, or (b) by a user-made program. The
options o~en to the user, as Well as the
concomittant obligations, insofar as the
execution of the Compiler is concerned,
differ under each of these alternatives.
Where the Compiler is invoked by the
EXEC statement, the options specifiable are
limited to the compiler control options
listed under "compiler Options"
below.
Under this alternative, the key-words representing the compiler options specified

are assembled by the con~rol program in an
option field addressed by a pointer.
At
entry to the Compiler, the address of the
pointer is contained in Register 1.
Where the Compiler is invoked by a
user-made program, the user may specify (a)
any of the compiler options, (b) ddnames
for data sets, and (c) heading information"
consisting of an opening page number for
the printed output of the Compiler. Under
this alternative, it is the obligation of
the user to assemble the key-words representing the compiler options exercised,
ddnames (if any) specified, and the heading
information, in three separate fields of
main storage (hereafter called, respectively, the option field, the ddname field, and
the heading field).
Each field must be
addressed by a pointer in a three-word
address
list, and the address of the
address list must be contained in Register
1 when control is transf erred to the Compiler.
Figure 5 pictures the arrangement of the
option" ddname and heading fields, and the
related pointers. The arrangement is completely analogous under both invocation
alternatives, except that in the case of
invocation by EXEC statement, the ddname
and heading fields are always vacant (the
latter fieldS may also be vacant under the
alternative
invocation
procedure).
A
vacant field is indicated by the value zero
in the corresponding pointers; value zero
in Register 1 indicates that all three
fields are vacant. A vacant option field
indicates that the options exercised are
the default options.
Register 1

Address List

process the ddname and heading fields will
be bypassed.
The address of the address
list
is
obtained
from the Operating
system's save area, in which the contents
of Register 1 will have been stored after
entry to the Coropiler.

COMP ILER OPTI ONS
The processing of Compiler options consists in reading the key-words listed in
the option field and in setting appropriate
switches in the HCOMPMOD Control Field
(Appendix IV) to reflect the particular
options specified.
The key-words representing valid options
which may be specified for a compilation
are as fellows (the first key-word corresponds to the default option):
SIZE = [a number ~45056]
PROGRAM (PG) or PROCEDURE (PC)
SHORT (SP) or LONG (LP)
SOURCE (S) or NOSOURCE (NS)
LOAD (L) or NOLOAD (NL)
NODECK (ND) DECK (D)
EBCDIC (EB) or ISO (I)
TEST (T) or NOTEST (NT)
The letters within parentheses represent
tlle alternative (abbreviated) form in which
the option may be specified. The key-words
are recorded in the option field in EBCDIC
code and are separated by commas. Except
in the case of the SIZE option" each option
is identified by comparing the key-word
with a list of 28 possible key-words in a
table named PARMLIST.

o

1

10

14

r---------~----------------T------------,

I l
instruction> JI

Figure 6.

Figure 5.

option,
DDname
and
fields, and pointers

Heading

The first bit of each full-word pointer
in the address list functions as a flag, to
indicate whether or not the field currently
being processed is the last to contain
significant data. The bit is tested after
each field has been processed, to determine
whether the next field is to be processed.
Thus, for example, if the flag bit is on in
the option field pointer, indicating that
the ddname and heading fields are vacant,
the DDNAMES and BEAD INFO routines, which

PARMLIST Table entry for a
piler option key-word

Com-

In addition to the option key-word and
the key-word length (-1), each entry in the
PARMLIST Table contains a logical instruction (NI or OIl which, when executed, turns
on a specified switch in the HCC~F~CD
Control Field (Appendix IV). As soon as a
key-word in the PARMLIST Table is found
which matches the key-word in the option
field, the instruction in the table is
EXECUTEd, turning on the appropriate switch
in the Control Field and thus recording the
option specified.
The SIZE option is identified by a CLI
instruction.
After recognition, the size
specified is converted to binary and stored
Chapter 3: Initialization Phase (IEX10)

27

at SIZE, provided it is not less than the
minimum capacity required.
The size is
subsequently referenced in selecting the
Area Size Table (see below). If an option
is incorrectly specified, error No. 200 is
recorded in the Preliminary Error Pool in
the Common Work Area and the default option
is assumed.
If the main storage size
specified is less than the minimum, error
No.
208 is recorded, and the minimum size
of 45,056 is assumed. The contents of the
Preliminary Error Pool are subsequently
moved to the main Error Pool after the
Common Area has been acquired.

tion Phase (IEX10) acquires a Coromon Area
used by all phases (see below).
To enable the Compiler to adapt itself
flexibly to the available storage capacity,
the space allotment for certain work areas
is scaled to the capacity of the particular
machine system as specified in the SIZE
option. Twelve capacity levels are established,
beginning at 45,056 bytes and
graduated upwards at increasing intervals,
up to a maximum of 999,999 bytes. At each
capacity level, specific area sizes are
defined for all work areas and buffers.
Capacity levels and area sizes are defined
by twelve Area Size Tables, the first of
which is named ARTAB.

DDNAMES
The processing of ddnames consists in
transferring the ddnames (if any) from the
ddname field to the relevant Data Control
Blocks. Unless a ddname field is provided
in a user-written program which invokes the
Compiler, the ddname field is vacant (Data
control Blocks contain the ddnames required
by the Compiler).
The ddnames, each consisting of a maximum of eight EBCDIC characters, will have
been entered in the ddname field in prescribed positions, according to the physical
device involved.
Data
Control
Block
addresses are listed, in
corresponding
order and position, in the Common Work
Area, beginning at LINADD.
This enables
the ddnames to be transferred to
the
appropriate DCB in sequence.

The
FNDARSIZ
routine
selects
the
appropriate Area Size Table, according to
the machine capacity specified in the SIZE
option, and moves the table to the Common
Work Area at the field beginning at INBLKS.
The table thus selected, which specifies
the main storage space to be acquired for
all work areas, is referenced by the rrain
working phases at initialization, before
the GETMAn~ instruction for the phase's
private area is executed.
In addition to work area sizes, the Area
Size Table also specifies the maximum blcck
sizes for the SYSIN, SYSPRINT, SYSLIN, and
SYSPUNCH data sets.
The maximum bleck
sizes are referenced by the Open-Exit reutines (see below).
Appendix VIII shows the increase in the
size of work areas, buffers and maxirrurr
block sizes as the SIZE option increases.

HEADING INFORMATION
ACQUISITION OF COMMON AREA
The heading information which may be
specified, consists solely of a starting
page number for the printed output of the
Compiler. Where no page number is specified, page numbering begins with the number
1.

The page number
field is moved to a
which is updated
PRINT subroutine in

(if any) in the heading
counter named PAGECNT,
and referenced by the
the Directory.

SELECTION OF AREA SIZE TABLE (FNDARSIZ)
With
the exception of load modules
IEX10, IEX21, IEX31, and IEX51, each phase
of the Compiler acquires a private area
containing one or more work areas or buffers for the construction, processing, or
output of working tables. The Initializa28

The Initialization Phase acquires a Common Area containing Source Buffer No.1 and
the Error Pool, in which compile time
errors detected in the several phases are
recorded.
The sizes of the buffer and
Error Pool are obtained from the Area Size
Table.
The use of Source Buffer No. 1 is
discussed under "Use of Main Storage" in
Chapter 1.
After acquisition of the Error Pool, the
contents (if any) of the Preliminary Error
Pool in the Common Work Area are moved to
the newly acquired Error Pool.

OPENING OF DATA SETS
The Initialization Phase opens all data
sets used by the compiler, namely SYSLIN,

\

SYSPRINT, SYSIN, SYSPUNCH, SYSUT1, SYSUT2,
and SYSUT3. The DCBs of SYSIN and SYSUT1
are contained in the Common Work Area (this
facilitates the release of main storage for
other uses when the data set is no longer
needed after the Scan 1/11 and Scan III
Phases, respectively); all other DCBs are
contained in Control section IEXOOOOO of
the Directory. DCB addresses are listed in
the Con®on Work Area, beginning at LINADD.
In®ediately
before
the
OPEN macro
instruction is executed, the addresses of
the Open-Exit routines INEXRT, LINEXRT,
PCHEXRT, and PRTEXRT are stored in the
SYSIN, SYSLIN, SYSPUNCH, and SYSPRINT DCBs.
The Open-Exit routines, which are entered
from the Operating System when the OPEN
macro instruction is issued, serve to verify that the block size (if any) specified,
is a multiple of the record length and does
not exceed the maximum s~ecified in the
Area Size Table. If the block size is not
specified at invocation or if the block
size is incorrectly specified, the OpenExit routine inserts the record length as
the block size.
If the block size is
incorrectly
specified,
an
error
is
recorded, and in the case of SYSIN, the
NOGO switch (Appendix IV) is turned on,
causing compilation to be subsequently terminated.
In the case of the SYSUT1 and
SYSUT2 data sets, the block size (equal to

the source buffer length specified in the
Area Size Table) is inserted directly,
before the OPEN macro
instruction
is
issued.
In the case of SYSUT3, the block
size is sFecified in the DCB at assembly
time.
When control is recovered from the Operating system OPEN routine, a test is rrade
to determine if the SYSPRINT data set bas
been opened (in the negative case, Error
No. 201 is recorded and the PRTNO and NCGO
switches are turned on, causing compilation
to be terminated after the error message
has been printed out by Load Module IEX21
on the console typewriter).
If the data
set has been successfully oFened, the date
is derived and edited from the systerr
clock, and the title "LEVEL 1 JUL 67 OS
ALGOL F DATE [date]" is printed on a new
page.
Tests are then made to determine if the
remaining data sets have been opened.
If
all data sets have been correctly opened,
control is passed to the Scan 1/11 Phase
(IEX11).
If any data set has not been
opened, an error is recorded, and in the
case of SYSIN, SYSUT1, SYSUT2, or SYSU~3,
the NOGO and TERR switches are turned on,
causing compilation to be terminated after
recorded error messages have teen printed
out by Load Module IEX21.

Chapter 3: Initialization Phase (IEX10)

29

CHAPTER 4: SCAN I/II PHASE (IEX11)

PURPOSE. OF THE PHASE

object time storage fields are allocated to all identifiers listed in the
table,
other than declared label.
switch, and procedure identifiers .•

The purpose of the Scan I/II Phase is to
read the source module and perform the
following principal tasks.
1.

To tabulate and classify all valid
identifiers declared or specified in
the source module" in the Identifier
Table.
Declared identifiers include
those designated by such declarators
as 'REAL',
'INTEGER',
'ARRAY',
or
'PROCEDURE', among others l as well as
labels.
specified identifiers are
formal parameters of procedures, specified in a procedure heading.

The Identifier Table is terminated in
the Scan III Phase" when all externally represented operands in the source
text are replaced by their internal
names in the table.
2.

The Identifier Table" which is further
processed in the two subsequent phases, facilitates the construction of
the internal names of identifiers and
the replacement of identifiers in the
source text by their internal names.
An identifier's internal name consists
of a five-uxte unit containing a descriptive
characteristic, a Program
Block
Number,
and a displacement
address.
The Program Block Number specifies
(indirectly) a Data storage Area, compriSing the object time storage area
required for all identifiers declared
or specified in the particular block
or
procedure.
The
displacement
address specifies (in the case of a
declared label, switch, or procedure
identif"ier) the displacement of an
entry in the object time Label Address
Table, or (in the case of all other
identifiers) the displacement of a
storage field in the particular Data
storage Area.
The entries in the Identifier Table
consist of the identifier's external
name (represented by a maximum of six
characters
translated
to internal
code),
followed
by the five-byte
internal name described above.
For
declared label, switch, and procedure
identifiers, the complete entry, comprising external and internal name, is
constructed by the present phase. For
all other identifiers, the present
phase enters the external name and
constructs all except the address part
of the internal name. The Data Storage
Area
displacement address is
inserted in the entry by the Identifier Table Manipulation Phase, in which
30

To assign a serial Program Block Number to every block and procedure in
the source text.
The same Prograw
Block Number appears in the internal
names of all identifiers declared or
specified in the particular block or
procedure.
At object time"
the Program Block
Number references an entry in the
Program Block Table, containing, among
other things, the size of a Data
Storage Area.
In the Object code
generated by the Compilation Phase, an
operand is represented by the address
of the Data Storage Area (loaded in a
base register) and the displacement
contained in the operand's internal
name.

3.

To generate a transformed source text,
called Modification Levell. A second
transformation of the source text"
called Modification Level 2, is generated by the Scan III Phase.
~he
changes reflected in the first transformation include an initial one-forone translation of all characters in
the source text to the internal code.,
the replacement of all ALGOL delimiter
words by one-byte operators, and the
removal
of
declarations,
except
procedure"
array" and switch declarations, from the source text.
These
and other changes are described in a
later
section
under
the heading
"Modification Level 1 Source Text".

4.

To store strings enclosed by string
quotes, '(' ')'" in the Constant Pool"
and to replace the string in the
transformed source text by an internal
name referencing the location where
the string was stored. All constants
other than strings are stored in the
Constant Pool by the Scan III Phase.

5.

To recognize syntactical errors in the
source module and to store appropriate
error patterns in the Error Pool. The
contents of the Error Pool are printed

out in the form of diagnostic messages
by the Error Message Editing routine
in the next module but one (IEX21),
after execution of the
Identifier
Table Manipulation Phase.
6.

To print a listing of the source
module, if the SOURCE option is specified.

7.

To assign a serial Identifier Group
Nun,ber to every block, procedure, and
for statement in the source module.
The Identifier Group Number is used in
the Scan III Phase to verify the
validity of goto statements, and to
facilitate the classification of for
statements (see Item S).

S.

To construct a Group Table listing all
Identifier Group Numbers and identifying each for statement represented in
the list. The Group Table is used in
the Scan III Phase, in classifying the
optimizability of for statements containing goto statements which imply a
branch out of the for statement.

9.

To construct a Scope Table indicating
the Program Block Number of the block
or
procedure
enclOSing every for
statement. The Scope Table is used in
the Scan III Phase to ascertain if all
terms
of subscript expressions of
array identifiers occurring in for
statements are valid (i.e. declared)
outside the for statement.
This is
one of several conditions for subscript optimization.

10. To construct the Program Block Number
Table, indicating the Program Block
Number
of the block or procedure
imrr~diately enclosing every block
and
procedure in the source program. The
table is constructed for purposes of
user-information and is used in the
Identifier Manipulation Phase in the
print-out of the Identifier Table.

ALGOL delimiter words (e.g •.,
'BEGIN' or
'STEP'), as well as other multicharacter
operators (e.g., := or .,). If a delimiter
constitutes a declarator (e.g." 'INTEGER').,
or a specificator, entries are made for the
immediately following identifiers in the
Identifier Table, after each identifier has
been checked for validity.
Otherwise, a
one-byte symbol representing the delimiter
is transferred to the output buffer. Other
multicharacter
operators
are similarly
replaced by one-byte symbols.
Statements,
containing externally represented operands
(identifiers) and operators are transferred
unchanged, except that any delimiter words
and multicharacter operators within the
statement are replaced by cne-byte symbols.
(See "Modification Levell Source Text" in
this chapter.)
The following provides a general description of the main eperations performed
in the Scan 1/11 Phase, illustrated graphically by the diagram in Figure 7. The
description is intended to be read in
conjunction with the diagram.
At the extreme left of the diagram. it
will be seen that the' source module (in
card or card-image records~ EBCDIC or ISO
code) is read from the SYSIN data set into
an SO-byte field of the Common Work Area by
the CIB subroutine.
Immediately
after
read-in, a copy of the record is moved te a
print area (or a dummy print area, if the
SOURCE option was not specified)~ and the
record in the Work Area is then translated
to the internal code (Appendix I-a. Appendix I-b shows the same character set,
expanded by ·the characters which replace
delimiter words). The untranslated source
text in the print area is used in printing
a listing of the source module. It is also
used to enable character strings to be
stored in the Constant Pool in their original EBCDIC or ISO code.
The CIB subroutine"
first activated at phase initialization, is subsequently called by any routine
which detects the record-end operator zeta
(the operator is inserted by CIB at the end
of each trans lated source record).

SCAN 1/11 PHASE OPERATIONS
The two primary
1/11 Phase are:

functions of the Scan.

1.

To tabulate all identifiers declared
or specified in the source module, in
the Identifier Table.

2.

To generate a transformed source
(Modification Levell).

text

In principle, these functions are performed by searching the source text for

In the Work Area" the translated source
text is scanned by the TESTLOOP routine,
which searches for any of 14 different
characters. As soon as anyone of these
characters is identified., TESTLOOP meves
the preceding scanned characters to the
Mo'dification Level 1 text in an output
buffer, and then activates the appropriate
routine.
The diagram indicates the reutines activated in the case of 12 of the 14
characters (the remaining two are the Blank
and the Invalid Character"
which are"
in
effect, ignored).
Chapter 4: Scan 1/11 Phase

3.1

w

""

• , <, >, (

<,
>, ( , /,)

·,1,

SCAN

1/11 PHASE QEX11)

;

I

/

I

...... ,

.

Not, Power




Change Input Buffer (CIS)
Gets records from SYSIN into a work
area, moves them to a print'orea, then
trtmslote!tne records to internal code
in the work area. CIS is coiled wl'\en
the record-end operatOl"Zefo is
encountered.
-



Label Colon

1="' H"','." '0<.
SEMCu transfer.

llAI..I:a.operotor:

I

TESTLOO P scons the rranslatea source text for OIly of 14
characters, moves the intervening
characters to the output buffer, then
aelivates the routine concerned.

Chonge Output Buffer (COB)

l~

I

(Operands, numbel'$ & arithmetic

=:fur~ra:,~:f:~ ~~t:=Y:de)

I

/
I

I



~ Then, ~, Goto, .!f,~~

DELIMIT identifies the
delimiter enclosed by
apostrophes and branches
to the routine concerned,
using the Delimiter Table.

=

F ~~! ~:!~ o~

Zeta

the source texl
into the work oreo
ond returns control
to TESTLOOP,

~,( ,

NORMAL, TED and GIF

;:~r,:p:~'7i~~ the

_._

>, :; ; , ~,

I, =,

t

/1

I

delimiter, from the
Delimiter Table.

'BEGIN'
'FOR'
(FOR -for
statement

:"~~:r
BEGI called

(listing is printed
by Directory PRINT

~BEGI

(Firstdedar-

subroutine, on call

~~EGI~t!)

framelS)

......

!
I

/I

I
I
(

~~;:~:~:I=I~ ~~lre;!,~~

tines or. recorded in the farm
of error pottems in the Error
Pool. The pattems are edited
and messages printed out by the
Error MeSSClge Editing routine
in lEX 21.

I'n><


I

I
.TYPE, PROCEDUR,
PROCID, ARRAY,
SWITCH, SPEC, IDCHECK,
SPECENT, IDCHECK1, end VALUE
!'OUtines conlNC! entries for identifi8/'$ in the Identifier Table.

(DeciaredOlld
~
specified identifier entries)
(labels)

I=END ~

-END-

I

I
L

,-C=pBLCKEND

zr r
E

]

\ ' "=FOREND

W

I

ITAB

~;:;,~t:;;;:.)

\ '==COMPDEND

I

-(-

(Charocterslrings
in external axle)
-TRUE-FAlSE-

Figure 7.

Scan I/II Phase.

BOLCON trtlnsfers a
five-byte intemal name
referencing a location in
the Constant Pool where
binary 1 and 0 are stored.

I

I
.. _... _, '/

I XCTL to IEX20

I

(or IEX21, if a

t termlnatingenor
h..s been detected)

Diagram illustrating functions of principal constituent routines

(If DECK and/or
LOAD options
$pecified)

For a majority of the characters, the
character is simply transferred to the
output buffer or replaced by another character, depending on the character which
follows. In the case of a colon, the COLON
routine may:
1.

Transfer a Label Colon and construct
an entry in the Identifier Table for
the preceding label;

2.

Replace a letter string by a Comma; or

3.

Transfer the Assign operator.

In the case of a semicolon, the SEMCO
routine inspects the Scope Handling Stack
to determine if the semicolon closes a
procedure or a for statement, and if so,
activates
the
appropriate
subroutine
(PBLCKEND
or
FOREND).
See "Close of
Scopes" • If a semicolon terminates a declaration, SEMCO transfers the Delta operator to the Modification Level 1 text;
otherwise, the Semicolon operator is transferred.
The record-end operator zeta causes TESTLOOP to call the CIB subroutine, which
reads in a new record and translates it to
the internal code.
The apostrophe leads into the Apostrophe
routine (APOSTROF).
APOSTROF scans the
text immediately following the apostrophe,
for a digit or +/- sign, a second apostrophe, or one of a set of logical operators.
A digit or +/- sign identifies the
apostrophe as the Scale Factor.
A second
apostrophe indicates an ALGOL delimiter
word (that is, a string of letters or an
operator enclosed by apostrophes). In this
case, the Delimiter routine (DELIMIT) is
entered. If the scan is terminated by a
logical operator (indicating that the closing apostrophe of a delimiter is missing),
the Delimiter Error routine (EROUT -- not
shown in the diagram) is activated. EROUT
differs from DELIMIT, described below, only
in point of procedural detail.
DELIMIT compares the characters enclosed
by apostrophes with a list of 38 delimiter
words in the Delimiter Table (WITAB) and
branches to the routine specified in the
table for the particular delimiter.
A
majority of delimiters (21) lead into the
NORHAL, TED, or GIF routines, which simply
transfer the one-byte symbol in the Delimiter Table to the Modification Level 1 text.
Declarators and specificators lead into
routines which construct entries in the
Identifier Table for the immediately following identifiers.

OPENING OF SCOPES
Whenever the delimiter opening a block,
a procedure" a for statement, or a compound
statement is encountered" a one-l::yte operator identifying the particular scope is
entered in the Scope Handling Stack. The
operators Beta (for a l::lock), Proc (for a
procedure), For (for a for statement)" and
Begin
(for a cOITrpound statement), are
stacked by the BEG1"
PROCEDUR, FOR"
and
BEGIN routines, respectively. Depending On
the structure of the l::ody of a procedure"
the
operator Proc may subsequently be
replaced by the operators Proc* or Proc**
in the BEGIN, STATE" or FOR routines. See
"scope Handling Stack".
At the beginning of every block and
procedure, a program block heading entry"
containing a new Program Block Number,. is
constructed in the Identifier Table. The
Program Block Number in the heading entry
is copied into the following identifier
entries representing identifiers declared
or specified in the particular clock or
procedure. Similarly" at the opening of
every for statement., a for statement heading entry is constructed in the Identifier
Table.
The for statement heading entry is
subsequently deleted unless it is followed
by one Or more identifier entries representing a label or lal::els declared inside
the particular for statement. In the latter case, a for statement closing entry is
made at the end of the for statement.
Program block heading entries are constructed by BEGl (for a block) and PROCID
(for a procedure); for statement heading
and closing entries by FOR and FOREND,
respectively.
The BEGl subroutine, which stacks the
operator Beta and constructs the program
block heading entry at the opening of a new
block, is entered from any routine processing the first declaration following the
delimiter 'BEGIN'. Entry to BEGl is governed by a switch named BEGBIT, which is
turned on by the BEGIN routine., entered
from DELIMIT on recognition of the delirriter 'BEGIN'.
BEGBIT is tested in all
declaration-processing
routines
(immediately after entry from DEI.IMIT)" and
if the switch is on, a call is made to BEGl
before the particular declaration is processed.
BEGl and PROCEDUR also construct entries
in the Group Table, Program Block Numter
Table, and Semicolon Table.
FOR makes
entries in the Scope Tatle and Group Tatle.

Chapter 4: Scan 1/11 Phase

33

PROCESSING OF DECLARATIONS AND
SPECIFICATIONS
In the construction of entries in the
Identifier Table for declared or specified
identifiers, the external name is copied
from the translated source text in the Work
Area, while the characteristic is inserted
by an MVI instruction or, in the case of
specified identifiers, copied from
the
Delimiter Table.
Type declarations ('REAL',
'INTEGER' ,
and 'BOOLEAN') are processed by the TYPE
routine.
All type declarations are completely
removed
from the Modification Level 1
source text, whereas procedure., switch and
array declarations are represented in the
modified source text by a one-byte declarator, followed by the identifier (s) " as well
as parameters., components" or dimensionS.
Array and switch declarations are processed by the ARRAY, SWITCH, and LIST routines.
The main function of the LIST
routine, which branches to several subroutines is to count the number of dimensions
or components of arrays and switches, and
to store this information in the appropriate identifier entries.
Entries for declared procedure identifiers are made by the PROCEDUR, PROCID, and
IDCliECKl routines. The external names of
formai parameters in the parameter list
following a procedure identifier are copied
into the Identifier Table by the IDCHECKl
subroutine on call from PROCID. The characteristics
of
formal
parameters are
entered
subsequently when the specifications in the procedure heading are processed. The routines which process specifications include, firstly, the TYPE, VALUE,
SPEC, ARRAY, SWITCH, and PROCEDUR routines
(depending on the particular specificator),
and secondly, the SPECENT and IDCHECK routines (SPECENT is a special entry point of
IDCHEcK) •
To distinguish between declarations and
specifications, a switch named PROBIT is
used.
PROBIT is turned on by PROCEDUR, as
soon as a procedure declaration is recognized, to signify that a procedure heading
has been entered.
If a delimiter (say
'REAL') is subsequently encountered, the
condition PROBIT=l signifies that the'delimiter is a specificator rather than a
declarator and causes the particular routine activated (TYPE in this case) to
branch directly to SPECENT.
After copying the appropriate characteristic from the Delimiter Table to a
(or
standard storage location, SPECENT
34

IDCHECK) compares each identifier following
the specificator (' REAL' in this example)
with
the
formal parameters previously
copied into the Identifier Table from the
parameter list, and when the matching identifier is found, moves the characteristic
into the identifier entry.
No part of the procedure heading except
the procedure identifier and the parameter
list is transferred to the Modification
Level 1 text.
Type-qualified procedure and
array declarations are processed by the
TYPE, TYPPROC, or TYPARRAY, and PRCCEDUR or
ARRAY routines l in that order.

CLOSE OF SCOPES
When the delimiter' END' is encountered,
the END routine inspects the operator at
the top of the scope Handling stack and
calls an appropriate subroutine (PBLCKEND,
FOREND, or COMPDEND) " according to the
stack operator detected.
PBLCKEND is called if 'END' closes a
block or a procedure (indicated by the
stack
operators
Beta, Proc, Proc* or
Proc**). PBLCKEND transfers the last block
of entries in the Identifier Table representing identifiers declared or specified
in the clos ed block cr procedure" to the
SYSUT3 data set~ releases the stack operator; and transfers the closing operator
Epsilon to the Modification Level 1 text.
FOREND and COMPDEND (which are called if
the
stack
operator is For or Begin"
respectively), transfer the operators Eta
or End to the modified text, and release
the stack operator. FOREND may also ccnstruct a for statement closing entry in the
Identifier Table, or delete the preceding
for statement heading entry.
The
Scope
Handling
Stack is also
inspected by the SEMCO routine in case a
semicolon closes a procedure or a for
statement. In the affirmative case" the
PBLCKEND or FOREND subroutine is called.

END OF PHASE
The Termination routine (EODADIN)" which
closes the Scan 1/11 Phase, is normally
entered as an EOD (End of Data) routine
from the Operating System"
after
the
PBLCKEND subroutine has detected the final
exit. from the outermost scope of the source
module and has initiated a special scan of
the closing text, designed to detect possible logical errors.
EODADINmay also be
entered when a terminating error has been

detected in the source module, in which
case control is passed directly to Diagnostic Output Module IEX21, rather than to
the Identifier Table Manipulation Phase
(IEX20). The conditions under which EODADIN is entered are described more fully
under "Close of Scan 1/11 Phase".
Flowcharts 011 and 012 in the Flowchart
Section indicate the logical arrangement of
the principal routines in the Scan 1/11
Phase. All of the major routines illustrated in the diagram in Figure 7, namely
TESTLOOP, APOSTROF, and DELIMIT, can be
readily distinguished in the charts. The
various levels of routines entered from
each of these routines may be seen in both
the chart and the illustrative diagranl.

the Program Block Number of the clock or
procedure"
and the record length are contained in the first (heading) entry.
An ESD record for the object module and
TXT records of the strings stored in the
Constant pool are generated on the SYSLIN
and/or SYSPUNCH data sets, provided the
options LOAD and/or DECK are specified in
the EXEC job control statement. If the
source module is a precompiled procedure to
be stored on a partitioned data set, the
ESD record will contain the procedure name.
If the SOURCE option is specified, a listing of the source module is printed out on
SYSPRINT.

The name of this phase, Scan 1/11,
derives from the fact that the source
module is twice scanned in the phase, first
by
the Change Input Buffer subroutine
(CIB), when the source text is translated
to the internal code, and second by TE8TLOOP, APOSTROF, or some other lower level
routine.

PHASE INPUT/OUTPUT

SYSUTl

-

Modification

level 1 Souree

rex'

~

-

SYSIN

Identifier Table

Souree Wcdule

SCAN 1/11

Figure 8 pictUres the data input to and
output from the Scan 1/11 Phase.
The
figure also indicates the tables and other
data transmitted to the subsequent phases
via main storage.

PHASE
SYSLIN/SYSPUNCH

!"-

r--- ----,

I

Input consists of the source module on
the SYSIN data set (card reader, disk unit,
or magnetic tape unit). Input records, 80
characters in length, are read into the
Work Area (WA) by means of a GET macro
instruction.
The
transformed
source
text
(Modification Levell) output by the phase
is transferred to the SYSUT1 data set by a
WRITE macro instruction from two alternating output buffers in unblocked, fixed
length records. At phase termination, the
data set is closed by a Type T CLOSE (no
repositioning to the beginning of the data
set).
RecordS are numbered serially from
O. In the event the transformed source
text occupies less than one full buffer, it
is transmitted to the Scan III Phase via
main storage.
The Identifier Table is transferred to
the SYSUT3 data set by means of a WRITE
macro
instruction,
in
variable-length
records of up to 2000 bytes (181 Identifier
Table entries of eleven bytes each).
Each
record comprises the set of identifiers
declared or specified in a block or procedure.
The record number, represented by

ESD record md
TXT record. of
Con.tan. Pool

I
I

MalnSto_
Error Pool

Group Table

I S " " , . Tabl.

I

II

p....... 610d<

Number Table
[Modification
Lev.1 1 Source

L __T:,t1 ___

:
I

I

I

I
I

SYSPRINT

I

Source NadJI.
Listing

J

'---

• Source text tronsmltted in main storage if It

occupies lea than a full buffer.

Figure 8.

Scan 1/11 Phase Input/Output

IDENTIFIER TABLE (ITAB)
The Identifier Table (ITAB) is a working
record in which an internal form of operand
representation, facilitating later compilation operations, is constructed for every
valid identifier declared or specified in
the source module. This internal representation, referred to as an identifier's
internal name, replaces all externally represented operands in the source module.
The replacement is made in the Scan III
Phase after the construction of the Identifier Table has been completed by the
Identifier Table Manipulation Phase.
Chapter 4: Scan I/II Phase

35

The entry constructed for an identifier,
called an identifier entry, is eleven bytes
in length. It contains up to six characters of the identifier's external name,
translated to internal code, and a fivebyte internal name. For declared procedure
and switch identifiers and labels, the
complete entry, compr~s~ng external and
internal name, is constructed in the Scan
LlII Phase. For all other identifiers, the
external name and all except the address
part of the internal name is constructed in
the present phase, the address part being
inserted
in
the
Identifier
Table
Manipulation Phase.
Each set of identifier entries representing identifiers declared or specified'
in a block or procedure, is headed by a
program block heading entry. The heading
entry contains the Program Block Number
assigned to that block or procedure. At
the close of a block or procedure, the
block of entries relating to that block or
procedure is transferred as a record to the
SYSUT3 data set.
Within a given block of entries, an
entry (or entries) representing a label (or
labels) declared inside one or more for
statements, is enclosed by one or more for
statement heading entries and a for statement closing entry. The Identifier Group
Numbers in the for statement heading and
closing entries are used, in the Scan III
Phase, in detecting illegal branches into
for statements.
(SWlLA routine in IEX30.)
The processing of the Identifier Table is
described in further detail in a later
section.

or procedure identifier is type-qualified,
the characteristic is modified by a logical
instruction to show the type.
The hexadecimal value of the characteristic for each type of identifier is
shown in the table in Appendix II.
~he
characteristic. which serves to describe
the identifier. is inspected in the subsequent phases. Each of the binary positicns
in the characteristic identifies (when set
= 1) a particular characteristic of the
identifier.
The significance identified
with each position is shown in Figure 9.
Bits 5 and 6 of the first byte are designated Special Use Bits because they may be
manipulated in the Scan III Phase if the
identifier is a critical identifier. that
is, if the identifier occurs in a for list.
First Byte (Byte 6 in identifier entry)
Bit No:

~}
2

3
4

5
6
7
Second

Bit No:

o
I
2

6

7

Figure 10 shows the content of the
eleven-byte entry constructed in the Scan
I/II Phase for all identifiers except those
of declared arrays, procedures, switches,
and
labels.
The identifier's external
name, represented by a maximum of six
characters in internal code (Appendixes I-a
and I-b), is copied from the translated
source text in the Work Area, after the
full identifier has been checked for validity.
If the identifier does not satisfy
the specifications of the OS/360 ALGOL
Language with respect to validity, no entry
is made, and an error is recorded in the
Error Pool.
The tWO-byte characteristic, in the case
of declared identifiers, is provided by the
program (i. e. by an MVI instruction).
In
the case of specified identifiers, the
characteristic is copied from the Delimiter
Table (see DELIMIT routine). If an array
36

Operand

(See use of bits 0-2
in "Operator/Operand
Stacks" - Chapter 8)

Not used
Not used
No Assignment
Special Use I
Special Use 2
String
Byte (Byte 7 in identifier entry)

3
4
5

IDENTIFIER ENTRIES

Description

Figure 9.

Description
Standard Procedure } Procedure
Code Procedure
Call by Value } Simple
Call by Name
Variable
Label
Array
Real
} Boolean
Integer
Identifier Characteristic

The Program Block Number (P.B.No.) is
copied from the program block heading entry
of the block or procedure in which the
identifier is declared or specified.
With the exceptions already noted ana
described more fully below, the last two
bytes of the identifier entry as constructed in the Scan I/II Phase, are filled with
zeros. They are reserved for a relative
address which is inserted by the Identifier
Table Manipulation Phase. The address specifies the identifier" s object time storage
field within the Data Storage Area provided
for the block or procedure in which the
identifier was declared or specified .•
Figure 11 shews the content of the entry
constructed for a declared array identifier. The external name. characteristic, and

Program Block Number are entered in the
manner described above.
The number of
subscripts (or dimensions) of the array is
entered in the first half of byte 9.
The
last one-and-a-half bytes, filled
with
zeros in the Scan I/II Phase, are reserved
for the relative address of the array's
Storage Napping Function in the particular
Data Storage Area. The address is inserted
in the Identifier Table Manipulation Phase.
The entry constructed for a declared
procedure identifier is shown in Figure 12.
The external name and characteristic are
entered in the manner described earlier. A
new Program Block Number is assigned to the
procedure. This same Program Block Number
appears in the immediately following program block heading entry, which heads the
set of entries representing formal parameters specified in the procedure. The number
of parameters of the procedure is entered
in the first half of byte 9.
The last
one-and-a-half ~ytes of the entry contain
the relative address, referred to as the
La~el
Number (LN), of a four-byte entry
reserved in the object time Label Address
Table (LAT).
At Object time, the Label
Address Table entry contains the absolute

o

address of the
the procedure.

In
the
case
of a declared typeprocedure, the heading entry ~hich follows
the procedure identifier entry is followed
by
a
second entry for the procedure
identifier. The two identifier entries for
a type-procedure are identical. except that
in the entry which precedes the heading
entry, the first ~yte of the characteristic
is equal to hexadecimal CA, ~hile in the
entry which fcllo~s the heading entry. the
first byte of the characteristic is equal
to hexadecimal C2.
Figure 13 shows the entry constructed
for a declared s~itch identifier.
~he
entry
is identifical ~ith that for a
declared procedure identifier, except that
the first half of byte 9 contains the
number of components of the switch. minus
one.
The entry constructed for a declared
label is shown in Figure 14.
The entry
differs from that for a procedure identifier only in that the first half of byte 9 is
unused and set to zero.
8

6

object code generated for

11

9

r----------------------------------T-----------T-----~----------,

I



I 1~ ____
No·>1L_ __________ JI

<------(Internal Name)------>


= 

(Reserved) : The last one-and-one-half ~ytes are reserved for the relative address
of the identifiers's object time storage field -- inserted by the
Identifier Table Manipulation Phase
Figure

10.

Identifier Table entry for all identifiers except declared array, procedure
and switch identifiers and labels

o

6

8

9

10

11

r----------------------------------T-----------T-----~----------,

I

I (Re- 1
istic>1
No. _L
>1 ___________
served) lI
IL__________________________________ I __________
_L ____
~

<------(Internal Name)------>




: 

(Reserved)

= The

Figure 11.

last one-and-one-half bytes are reserved for the relative address
of the array's Storage Mapping Function. inserted by the Identifier
Table Manipulation Phase.

Identifier Table entry as constructed in the Scan 1/11 Phase for
array identifier

a

declared

Chapter 4: Scan I/II Phase

37

o

8

6

10

9

11

r----------------------------------T----------~----~-----------,

I



I   I
I
I

L
_L ____
_L __________ -J
istic>1
No·>1
I __________________________________ ~ __________

<------(Internal Name)------>


= 
 = 
 = 
Figure 12.

Identifier Table entry for a declared procedure identifier

o

8

6

10

9

11

r----------------------------------T-----------~----~----------,

I


I I
_L __________ -JI
istic>1 ____
No·>1
IL __________________________________ I ___________
~

~

<------(Internal Name)------>


= 
 = 
 = 
Figure 13.

Identifier Table
switch identifier

o

entry

constructed
8

6

in

the scan I/II Phase for a declared
9

10

11

r----------------------------------T-----------T-----~----------1

I
I



I  I No·>1

L ______ ----------------------------~-----------L-----~

 I

__________ I
J

<------(Internal Name)------>

 = 
 = Relative address of an
entry in Label Address
Table>
Figure 14.

Identifier Table Entry constructed in the Scan
label

PROGRAM BLOCK HEADING ENTRIES
A program block heading entry heads
every set of identifier entries representing identifiers declared or specified in a
block or procedure.
Figure 15 indicates the content of the
eleven-byte program block heading entry.
The first eight bytes provide two four-byte
save areas, in which the contents of the
pointers LIGP and LPBP are stored, before
these pointers are set to the address of
the heading entry itself. The first bit of
byte 8 functions as a switch to indicate if
the scope is a type-procedure. In this
38

I/II

Phase

for

a

declared

case, the bit is set = 1; in all other
cases, it is set = O. The Identifier Group
Number (I.G.NO.) and Program Block Numter
(P.B.No.) are copied from two counters
(IGN and PBN) '.
IGN is incremented for
every block, procedure, and for statement,
while PBN is incremented for tlocks and
procedures only.
At the close of a block or procedure,
when the set of entries representing identifiers declared or specified in the block
or procedure is transferred to a utility
data set, the length of the record to be
transferred and the semicolon count (copied
from the corresponding entry in the Semi co-

Ion Table) are inserted in the heading
entry, as indicated in Figure 16.

8
9
o
4
10
11
,r-------------------,---------------------,.-----------,------,

1



I

L ___________________



=

1

1< K>
<1. G. 1 1i _____
No·>1J

~

<1<> X'8' for a type-procedure; X'O' in all other cases Figure 15. o Program block heading entry 2 5 6 8 10 9 11 r---------,--------------,------T---------~----------~-----, l <1.G·I iI- ____________ iI _____ iI __________ count> No.>1 No·>1J IL_________ iI __________ -L _____ Figure 16. Program block heading entry, as transmitted to the SYSUT3 data set FOR STATEMENT HEADING AND CLOSING ENTRIES the Identifier Group Number of the ing block or procedure. A for statement heading entry is constructed in the Identifier Table as soon as the delimiter FOR is encountered. If no labels are declared inside the for statement (or a nested for statement), the entry is deleted at the close of the for statement. If, however, any labels are declared inside the for statement, a for statement closing entry is constructed at the close of the for statatement. Where a label is declared inside a series of nested for statements, the entry for the declared label is preceded by a heading entry for each enclosing for statement, and is followed by a single closing entry containing o 4 5 6 8 emtrac- The first four bytes of the for statement heading entry are used as a save area in which the contents of the pointer LIGP are stored before that pointer is reset to the address of the heading entry itself. The Identifier Group Numter (I.G.No.) is copied from the counter IGN, which is incremented successively for every tlock, procedure, and for statement in the source module. The Identifier Group Number in the for statement closing entry is copied from the heading entry of the reentered scope. 9 10 11 r-----------------r-----,------T-----------,.-----------,------, IL________________ I I - iI _____iIX'2B'I _____i ___________ I __________ i _ _ ___ J ~ =
Figure 17. o For statement heading entry 5 6 7 8 9 10 11 r-----------------------T-----T-----T-----~---------T-----, I _______________________ iIX'2B'IX'FF'I L _ ____ i _____ i Figure 18. I __________ - iI ____ - lI ____ - i For statement closing entry Chapter 4: Scan 1/11 Phase 39 for statement closing entry is constructed following the entry for the label. At the close of a block or ~rocedure, the set of entries representing identifiers declared or specified in the block or procedure are transferred to the SYSUT3 data set. ~he transfer is handled by the PEICKEND subroutine on call from the END or SEMCO routine. PROCESSING OF THE IDENTIFIER TABLE The diagram in Figure 19 illustrates the processing of the Identifier Table in the Scan 1/11 Phase. At entry to every block or procedure, a program block heading entry, containing a new Program Block Number, is constructed. (In the case of a procedure, the heading entry is preceded by an entry containing the procedure identifier.> Program block heading entries are constructed by the BEG1 subroutine, on call from declaration-processing routines, and by the PROCID routine, entered from PROCEDUR. At entry to a for statement, a for statement heading entry is constructed by the FOR routine. At the close of a for statement, the heading entry may be deleted, or if any labels are declared in the for statement, a A pointer named LPBP at all tirres addresses the heading entry of the current (embracing> block or procedure. LPBP is used 1. In copying the Program Block Nurrber into the following identifier entries, 2. In transferring the Program Block Number of a reentered block to the Modification Level 1 text following the operator Epsilon, which closes a tlock Contents of Identifier Tobie Work Area in Scan 1/11 Phore at Varying Points in Soorce IVodule Source Module Block Structure (Letters refer to labelled positions in block diagram at left) c:::=E}-{tf~ 0 -- AITL b) PSl (bJo<.:k or procedure) e\ d) c) b) a) j Proc.Nome Proc.Nome !-{tfgph t----i * rDedaea,;ao.;s,e,;,;,a,;ao, c) L-_-'.__ I I I I AITl PB2 (block) Proc.Name'" ) 1 \ \ \ \ I I I '.B.l P,B.1 2 P.B.2 P.B.2 3 -{ti~~ '.B.2 \ For Hdg. LABEL: Proc.Name 'M4 ('ype-peaced,,, - Mm, '4) I Proc.Nome~' ) I 1 \ \ I I P.B.1 1 1 2 Proc.Name* I 3 m) P.S.3 for Hdg. Lobel J For Close .. - A1Tl , P.B.T P.B.l I I 3 !=-AITL 1------1 I I I I '.B.3 I I '-{tf~p 4 f-----l I P.B.2 2 I I 1'3 : SVSUT3'" 'a SVSUT3 I I '0 AITl I '.B.2 I L ___ J r---- I I ;----11+f--+---.-/ I P.B.l I Proc.Nam ~~ __ -l -{t~~ ;0 '4 SVSUTl P.SA L~~5!.2:......j Label '3 '4 '4 r----1 I \ P.B.2 / , .----2..,·1 ~tr~p f------I.' f---__2,,1 -{ti~p} '3 1 \I I I P.B.2 P3 I Proc.Nome Proc.Nome* ) \\ P,'B.1 P.B.2 n) LlGP AITl lPBP \ t,, EEsilon *< IGN>* Procedure Pi Epsilon ** Typeprocedure Phi Epsilon ** For Statement For Eta * Compound Statement Begin End * PBN or IGN of the reentered scope The Program Block Number (PBN) occupies one byte, the Identifier Group Number (IGN) two bytes. SCOPE HANDLING STACK The action required at the close of every scope depends on whether the scope is a block, a procedure, a for statement, or a compound statement. Thus, at the close of a block or a procedure, the set of entries in the Identifier Table representing the identifiers declared or specified in the block or procedure, is transferred to the SYSUT3 data set, and the operator Epsilon is transferred to the Modification Level 1 text. At the close of a for statement, a closing entry may be made in the Identifier Table and the operator Eta transferred. At the close of a compound statement, the operator End is Simply transferred. Owing to the fact that the same delimiter ( 'BEGIN') opens both a block and compound statement, and owing also to the fact that procedures and for statements may be closed by the delimiters 'END' or a semicolon, depending on their structure, a method of classifying each scope is required, so as to specify both the delimiter to be identified as the closing delimiter and the r---------------T------------------------------------------------~---------T-----------, IStack Opera tor I I 1 I .------~-------~ 1 I 1 I Name 1 Hex. I Significance IStacked bylReleased byl ~------+--------+------------------------------------------------+----------+-----------~ I I I I 1Begin I 08 Designates a compound statement, closed by 1BEGIN 1CO!!PEND I 1 'END'. IBeta 04 I I Proc* Designates a block, closed by 'END' IProc For OC Designates a procedure, closed by a semicolon or by 'END'. 'END' unconditionally closes the embracing scope. The procedure body consists of a procedure statement, a dummy statement or a delimiter 'CODE'. PROCEDURE IPBLCKEND I ~ _______ Figure 20. 42 1 I 1 Designates a for statement, closed by a semiFOR colon or by 'END'. A semicolon may close an embracing procedure or for statement. 'END' unconditionally closes the embracing scope. I I IPBlCKEND IPBLCKEND I 1 1 I I FOREND 1 I 1 1 00 1l ______ I I Designates a procedure, closed by a semicolon STATE or by 'END'. 'END' unconditionally closes the FOR embracing scope. The procedure body consists of a labelled statement or block, or a Single assignment, gato, conditional or for statement. 1 1 1Alpha 1 IPBlCKEND I I PBLCKEND I I BEGIN 18 1--- BEGIN I 1 Designates a procedure, closed by 'END' The procedure body consists of an unlabelled block or compound statement. 14 Proc** 1 10 1 I 1 I ~ 1 Marks the bottom of the stack. ALPHA is stackedlInitiali- 1Termination I only at phase initialization and released only I zation I I at phase termination I __________ I ___________ JI _______________________________________________ Scope Handling Stack operators ~ ~ particular action to be taken at the close. The device used for the classification of scopes is the Scope Handling Stack. The Scope Handling Stack employs a set of six stack operators, each of which identifies a characteristic scope structure. Whenever a delimiter is detected which marks the opening of a new scope, an appropriate operator is placed in the stack. If, subsequently, some feature is detected in the scope which indicates a change in structure, the operator originally placed in the stack is replaced by another operator which correctly reflects the structure of the scope. When the delimiter specified by the stack operator as the closing delimiter is encountered, the operator is released from the stack. In this way, all embracing scopes at every point in the source module are classified by the operators in the stack, the innermost scope being classified by the last stack entry. The list in Figure 20 indicates the stack operators, their significance, and the routines which stack and release the operators. Stack operators are tested in the SEMCO, STATE, BEGIN, CODE, FOR, END, PBLCI lof the fori I ____________________ I statement> L __________ JI Valid labels are transferred, but the colon following a declared label is replaced by the Label Colon. Entry forr---------------------T----------, a block I I zeros>1 d. o 2 3 ~ procedureL--------------------~----------J e. f. Parameter delimiters of the form ) LETTERS: ( are replaced by the Comma. If a parameter delimiter extends across two output buffers, the symbol Rho is inserted at the beginning of the second buffer, indicating to the Scan III Phase that the letters at the end of the preceding record are to be replaced by the Comma. The record-end operator Zeta is inserted at the end of every output record, except the last, in which the character Omega marks the end of the Modification Level 1 text. All operands (identifiers) contained in statements in the source module are transferred unchanged to the Modification Level 1 text, except for the initial translation to the internal code mentioned in item 1 above. Figure 21. Group Table entries for a for statement and for a block or procedure SCOPE TABLE (SPTAB) The Scope Table is constructed in the Scan 1/11 Phase and transmitted to the Scan III Phase in main storage. A one-byte entry is constructed for every for statement, indicating the Program Block Number (P.B.No.) of the enclosing block or procedure. The Scope Table is used in the scan III Phase in determining whether all terms of array subscript expressions occurring in for statements are declared outside the for statement (i.e. nct in a block enclosed by the for statement). Chapter 4: Scan I/II Phase 45 o 1 r-----------------------------------------, I I _________________________________________ L JI Figure 22. One- byte Scope Table entry PROGRAM BLOCK NUMBER TABLE (PBTAB1) The Program Block Number Table is constructed in the Scan 1/11 Phase and transmitted to the Identifier Table Manipulation Phase in main storage. A one-byte entry is constructed for every block and procedure, indicating the Program Block Number of the enclosing block or procedure. The Program Block Number Table is used in connection with the print-out of the Identifier Table listing in the next phase, in which the Program Block Number of the block or procedure embracing each block and procedure is shown. o 1 r-----------------------------------------, I JI Figure 23. One-byte Program Table entry Block Number specifies, in general, that scanning for the appropriate character sequence is to continue. STARTBIT = 1 (on) signifies that the opening delimiter has been found. The chart in Figure 24 shows the logical flow through the routines which process the opening delimiter, and the function of the STARTBIT. In the TESTLOOP routine the condition STARTBIT off has the effect of limiting the character search to an apostrophe (the first of two apostrophes enclosing a delimiter word). When an a~os­ trophe is found, control is passed to APOSTROF, which searches for the secend apostrophe and then branches to DELIMIT. In DELIMIT, the condition STARTBIT eff causes a branch to a s~ecial-purpose routine, called STARTDEL, whose function is to activate FIRSTBEG, PROCEDUR, or TYPE, according to whether the delimiter is 'BEGIN', 'PROCEDURE' or 'REAL', 'INTEGER', or 'BOOLEAN', respectively, and to return control to TESTLOOP in all other cases. If the source module is a ~rogram and the delimiter is 'BEGIN', STARTBIT is turned on by FIRSTBEG, thus signifying that the correct opening delimiter has been found. If the source module is a ~recompiled procedure and the delimiter is 'PROCEDURE' or '' 'PROCEDURE', STARTBIT is turned on by PROCEDUR. In all other cases, an error is stored in the Error Pool, and control returned to the TESTLOOP, which continues to scan for an apostrophe. PROCESSING OF OPENING SOURCE TEXT CLOSE OF SCAN 1/11 PHASE The source module as specified in the EXEC statement may be a program or a precompiled procedure. If the source module is a program, the operative (programming) text in the source module must be opened by the delimiter 'BEGIN'. If the source module is a precompiled procedure, the operative text in the source module must be opened by the delimiter 'PROCEDURE' or by one of the delimiter sequences 'REAL' 'PROCEDURE', 'INTEGER' 'PROCEDURE', or 'BOOLEAN' 'PROCEDURE'. Since the opening delimiter may be preceded by comment, provision is made in the Compiler to assure that, at the start, all text is disregarded until the correct delimiter or delimiter sequence is found. To facilitate the search for the correct opening delimiter, a number of specialpurpose routines, as well as a switch named STARTBIT, are used. STARTB1T = 0 (off) signifies that the opening delimiter has not been found and 46 The EODADIN routine, which closes the Scan 1/11 Phase and which transfers control to the succeeding phase, may be entered under four main conditicns: 1. At the logical close of the source module, when the logical terminal delimiter ('END ' in most cases) has closed the outermost scope of the source module 2. When an unexpected End of Data condition occurs 3. When a terminating syntactical error is detected in the source module 4. When a program interrupt or unrecoverable I/O error occurs. Charts A, B, C and D in Figure 25 show the flow of control through the various routines before EODADIN is finally entered, under the four conditions mentioned. Opening delimiter found AYe, '" , ,/"BraneR", <. accord. to "') ' .... chcr. /"" ",(/ r------t-------, t I I (COLON, POINT, SEMCO, etc. Operator DigitI Invalid character TYPESPEC • Ye, (Normal processing) ~ROCEDURE'~-------------------, Ye, Opening delimiter found Opening delimiter found Ye, /A, t (Normal processing) '" , .,.,"'Branch', acccrd. to " ,~e1imit~/ " <",""Branch accord. to < (Continue scanning for opening delimiter) r---'-----, 'y/ r------t-------, I t (NORMAL, TED, GIF, etc.) 'PROCEDURE' I '.e~imi~ .? y 1"'------+-----, I t t (NORMAL, TED, GIF, etc.) ERRS (Begin normal processing) Figure 24. (Continue scanning for opening delimiter) Chart showing the logical flow in the search for the opening delimiter and showing the function of the STARTBIT In Chart A, the logical close of the source module is detected by the PBLCKEND subroutine signifies that a procedure heading has been entered and specifies to declaration-processing routines that, until turned off, all declarative delimiters such as 'INTEGER', are to be processed as type specifiers of formal parameters, as opposed to type declarators. (turned off by the STATE, BEGIN, FOR, and CODE routines, when a statement, or the delimiter 'BEGIN', indicating the end of a procedure heading, is identified> specifies to declaration-processing routines that, until turned on, all declarative delimiters are to be processed as type declarators, not as specifiers. laration and upon entry to the SWITCH routine> signifies to all routines that, unless turned on, the character being processed forms part of a switch list. LISTBIT: Qg (turned on by the ARRAY routine on recognition of a comma following an array identifier> signifies that the next identifier is a continuation of a list of declared array identifiers with the same dimension list, and specifies that a Comma is to be transferred to the output buffer to separate the last identifier from the next. off has no significance. TERBIT: DELTABIT: on off: (turned on by declaration-processing routines> identifies the fact that a declaration has been detected and specifies to the SEMCO routine that the semicolon immediately following is to be replaced in the output string by the one-byte operator Delta. (turned off by the SEMCO routine> signifies that, unless subsequently turned on, the next semicolon is to be represented by the Semicolon operator. ~ (turned on by the ENDMISS routine after control has been passed to it by the Operating System at End of Data> speoifies to the PBLCKEND subroutine that control is to be returned to ENDMISS. off (turned off at phase initialization> has no significance. ENDBIT: on signifies that the delimiter which logically closes the source module has not yet been reached. IDBIT: on (turned on by the PROCID routine> signifies that the next identifier is the procedure identifier and specifies that a program block heading entry is to be made in the Identifier Table to mark the beginning of a new identifier group. Qff (turned off by the PROCID routine> Signifies that the procedure heading entry has been made in the Identifier Table and specifies that the formal parameter part of the procedure heading is being processed. COBIT: on specifies to the COM routine that the source string up to the next semicolon is to be deleted. The characters deleted may be a segment of the form: ' COMMENT' ;. off specifies that the source text up to the next semicolon or the delimiter "ELSE' or 'END', is to be deleted. This deletes: ARBIT: on off 50 (turned on by the ARRAY routine> signifies that an array declaration has been identified and specifies to all routines that the character being processed forms part of an array list. (turned off upon identification of a semicolon terminating an array dec- 1. Any comment enclosed as follows: 'END''ELSE'/'END'/: or 2. An erroneous statement or declaration (or portion thereof). lowing 'END', a branch is to te taken to the COMPEND2 routine. The latter activates the FCREND or PBLCKEND subroutine, depending on whether the stack operator is For or Proc**. STARTBIT: off (turned on by the F1RSTBEG and PROCEDUR routines) signifies that the opening delimiter of the source module has been found. off E11B1T: (turned off at phase termination) signifies that the opening delimiter of the source module has not been found. See "Processing of Opening Source Text". (turned on by ERRS) signifies that error No. 11 has been recorded, and that the error should not te recorded again. off VALBIT: (turned on by the VALUE routine) signifies to the SPEC routine that a value specification is being processed. (turned on by PROCID) signifies that the formal parameter list of a declared procedure is teing processed and that the end of the list has not been reached: and specifies to IER that control is to be returned to PROCID after a defective parameter has been processed. PROBIT: off (turned off at phase has no significance. (turned off by PRCCID when the serricolon following a formal parameter list is found) has no particular signif icance. NOFREE: (turned on in CLOSE2) signifies that main storage for the private area has not been acquired, and specifies to EODAD1N that a FREEMAIN macro instruction is not required. termination> FRSTPUT: (turned on by the GENERATE routine> signifies that the first PUT instruction has been issued, and that the address of an output buffer is available. off off signifies that the first PUT instruction has not been issued. ENDELSEBIT: (turned on by the END routine when, after the delimiter 'END' has closed a block or compound statement, a test shows that the stack operator is For or Proc**> signifies that the embracing scope is a for statement Or a procedure which may be closed by a semicolon, and specifies to the COM routine that, if a semicolon is found to terminate the comment fol- (turned off at phase initialization) signifies that error No. 11 has not previously been recorded. FMBIT: (turned off in the IDCHECK routine) signifies that, unless turned on, a type specification (not a value specification) is being processed. (turned on by EODAD1N in the event the source module is a precompiled procedure) specifies to PBLCKEND that control is to be returned to EODADIN, after Program Block 0 in the Identifier Table has been transferred to the SYSUT3 data set. (turned off by the END, COMPEND2" and TED routines) has no significance. off (turned off at initialization) signifies that no previous output has taken place on SYSUT3 and that, accordingly, a CHECK macro instruction is not required tefore the next output operation. PROCESD: on (turned on in the PROCEDUR routine) Chapter 4: Scan 1/11 Phase 51 signifies that the source module is a precompiled procedure and specifies to the PROCID routine that an ESD record is to be made for the procedure name. off (turned off by the PROCID routine) signifies that the source module is a program, or that the ESD record for a precompiled procedure has been generated. POOL L0 C AKOPOOL r SPCLT I (Space reserved for constants 0 - l5, stored in Constant Pool at phase termination - displacement 64) Constant Pool (4096) SP I t ATOPS TAK AITAB BUFF ScoE;e Handline Stocle (1000) Identifier Table Buffer (2000) CONSTITUENT ROUTINES OF SCAN 1/11 PHASE ADDA RI +4 Source Buffer No.2 The principal constituent routines of the Scan 1/11 Phase are described below. The page on which each routine is described and the flowchart in the Flowchart Section in which the general logic of the routine is set forth may be found with the aid of the Index in Appendix XI. AITAB LlGP LPBP 1 J AITL T I * (Heading entry for P .B.O constructed Identifier Table (ITAB). The position of the major routines in the overall logical organization of the phase may be determined by reference to Flowcharts 011 and 012 in the Flowchart Section. MGESlTL = ITAB length ELI * Area size specified by Area Size Table in Common Work Area. See Appendix VIII for the variation in area sizes as a function of the SIZE option. PHASE INITIALIZATION Figure 26. The Initialization routine gets main storage for the private work area shown in Figure 26; initializes pointers; specifies EOD and program interrupt-I/O error routines; assembles headlines for the source module listing; and activates the Change Input Buffer subroutine (CIB). The routine exits to TESTLOOP. The entry, ENoMISS, in the event of an End of Data (EOD) ccndition on the SYSIN data set is stored at EODIN, the location referenced by the End cf Data Exit routine in the Directory. The entry pOint of the routine activated in the event of a program interrupt or an I/O error (both of which terminate compilation) is stored in ERET, the location referenced by the Program Interrupt routine (PIROUT) and the I/O Error routines (SYNAD and SYNPR) in the Directory. The entry point CLOSE2, specified at entry is changed, after the GETMAIN instruction haS been issued, to EODADIN. Both CLOSE2 and EODADIN close data sets and transfer control to Diagnostic output Module IEX21. EODADIN in addition releases main storage. The GETMAIN instruction for the private work area is executed after the total area required has been computed. The area sizes needed for the Identifier Table and Source Buffer No.2, which depend on the capacity of the system used, are obtained from the Area Size Table entries named ITAB10S and SRCE1S, respectively. The areas allocated to the Constant Pool, Stack, and ITAE buffer are fixed at 4096, 1000 and 2000 bytes, respectively, for all systems. The various pointers initialized are shown in Figure 26. A fuller explanation of the pointers LPBP and LIGP is given under the heading "Processing of the Identifier Table". 52 Private Area acquired by the Scan 1/11 Phase., showing pcinters initialized r--------------------------------, (Source Buffer No.1) Ir----------------->IL ________________________________ JI o ADDARI I 4 8 r----+----~--------, IA(Buff l)IA(Buff 2)1 L ___ -L ___ -L ___ o t EAP (Reg. 3) APE ~----J r--------------------------------, I 1 t L _____ ~->IL ________________________________ (Source Buffer No.2) JI r--------, DISP IL ________ 0 or 4 JI Figure 27. Source text buffers and pointers Source Buffer No. 2 is the second of two buffers used for output of the modified source text generated by the phase. Buffer 'No. 1 is set up in the Common Area by the Initialization Phase, its beginning address being stored at SRCE1ADD and its end address at SRCE1END. The present initialization routine stores the addresses of both buffers in an eight-byte field named AD DARI, and then initializes the pointers EAP (Register 3) and APE for Source Buffer No. 1 (see Figure 27). EAP and APE are updated whenever buffers are exchanged by the Change Output Buffer subroutine (COB). The particular address loaded in EAP from ADDARI is determined with the aid of a control byte named DISP (reset from 0 to 4 and vice versa just before EAP is updated), which specifies the displacement (0 or 4) from ADDARI. A heading entry (Figure 28) for Program Block 0 (an arbitrarily defined block enclosing the source module) is constructed in the Identifier Table. The current entry position AITL is set to point to the next free entry in the Identifier Table. o 3 4 5 6 11 r----------T----~---y_---y_--------------, I __________ I____ FF L_ I ___ L_ I _2B I ______________ JI L _ _ L_ ~ Figure 28. Heading Entry constructed at initialization in Identifier Table for Program Block 0 The following dispositions are made in the Cornmon Work Area, in which the addresses of the various tables and other fields are defined by a dummy control section in IEX11. The address of an 88-byte dummy print area named SAVEPRNT is stored at APRINTAR. If the SOURCE option is not specified, the Change Input Buffer subroutine (CIB) moves each source record to SAVEPRNT, in order that strings may be stored in the Constant Pool in external code. If, however, SOURCE is specified, indicating that a listing of the source module is to be printed, source records are moved instead to a print toffer specified by the PRINT routine in the Directory. In this case, the address in APRINTAR will be replaced by the address of the print buffer. In preparation for the print-out of a source module listing, the headlines ("SOURCE PROGRAM" for the first line and "SC SOURCE STATEMENT" for the second line) are moved to a field named PAGE HEAD in the Common Work Area from the locations HDING1 and HDING2. The headlines are printed out by the Directory PRINT subroutine, on call from CIB, if the SOURCE option is specified. The BITS1 r--, I BEGBIT 01 11.--~IPROBIT BITS2 r--, IENBIT 01 .--i 41 IARB1T 51 I LISTBIT ~--i IE11BIT 11.--~ICOBIT 11 IFMBIT 31.--~IVALBIT 31 J--~ 41 IPBOBIT .-~INot used 51 ~--~ ~--~ ~--i J-~ 61 71 ITERB1T Figure 29. IFRSTPUT J--~ 21.--~I NOFREE .--i IFRSITB .--4IPROCESD 41 .--iI Not used 51 ~--i 61 I Not used 71L __JIENDELSEBIT 71 I Not used INot used 61 L __ J r--, 01 .-~ISTARTBIT 21.--~IDELTABIT 21 31.--~I IDBIT BITS3 .--i L-_J Switches Phase used in Scan 1/11 See "Switches" in this chapter. The Program Block Counter (PBC', Identifier Group Counter (IGC), Semicolon Counter (SC), For Statement Counter (FSN), and output Record Counter (ONC) are initialized at 0, and the first entries (0) for Progra~ Block 0 are made in the Program Block Number Table (PBTAB1), Group Table (GPTAB), and Scope Table (SPTAB). The control Chapter 4: Scan 1/11 Phase 53 switches used in the phase, which are contained in three bytes named BITS1, BITS2, and BITS3, are zero-set. The switches in each byte are shown in Figure 29. Their function and significance is explained elsewhere in this chapter under "Switches" • Hexadecimal Diselacemen t 00-03 04 08 OC 10 14 18 1C 20 24 28 2C 30 34 38 3C 40 44 48 4C 50 54 58 5C 60 64 68 6C 70 74 78 7C 80 84 88 8C 90 OPIN and LAPIN are the names of two special-purpose output buffer pointers. OPIN is always adjusted to point to the character that may precede a label or begin a parameter delimiter. These include Begin, ~, Do, Else, Delta, semicolon, and). At OPIN + 4 is noted the number of the output record (ONC) " in which the character pointed at by OPIN is to be found. LAPIN points to the first byte following that pointed at by OPIN, where the letter string or label may begin. OPIN and LAPIN may be separated by two or more characters. OPIN and LAPIN are used when declared labels are entered in the Identifier Table or when a letter string is replaced by a Coronia. T'eta /\ /\ /\ /\ I I I I I I I I OPIN LAPIN OPIN IAPIN Before exit to the TESTLOOP routine, the Change Input Buffer subroutine (CIB) is called. CIB activates the PRINT subroutine in the Directory (if SOURCE is specified), which, prints out the headlines assembled at PAGE HEAD and returns with the address of the print buffer. CIB then gets the first record in the Wor~ Area (WA), moves it to the print buffer (or a dummy print area), translates the record to internal code, and returns control to Initialization, after having loaded the address of WA in REGI (Register 1). In the TESTLOOP routine, which is now entered, as well as in all routines which scan or ins Fect characters in the translated source text, REGI functions as the Work Area pointer. Figure 30. All zeros Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of Address of The function byte assigned by TES'ITABL to each character, and the routines entered from TESTLOOP, are as follows: Blank * / TESTLOOP scans the translated source text in the Work Area, by means of a Translate and Test instruction, for anyone of 14 characters assigned a nonzero function byte in Translation Table TESTTABL; moves the scanned text to the output buffer; and branches to the routine whose address is specified in an entry of Branch Address Table BPRTAB. The displacement of the entry in BPRTAB is given by the value of the character's function byte. 54 TRANSOP TRANSOP TRANSOP TRANSOP TRANSOP TRANSOP CCLON SEMCO RIGHTPAR BLANK ERR1 POINT APOSTROF CIB ASSIGN DECPOIN'I ERRS BLKAPOS NPAFTAPO SCALE COLONLIST SEMCLST DELIMIT ZETAAPO EROUT LEFTPARL RIGHTPARL PZETA ASSIGN DECPOINT ERR5A COMMALS'I POINLST SLASHLST QUOTE SEMC60 Branch Address Table BPRTAB Character MAIN LOOP (TESTLOOP) Content of Entry ( > < Not ) Point Apostrophe Colon semicolon Invalid Character Zeta Function Byte Routine Entered 28 04 08 OC 10 14 18 24 30 34 1C 90 2C 38 00 BLANK TRANSOP " " " " " RIGHTPAR POINT APOSTROF COLON SEMC60 ERR 1 CIB (No branch, scanning continues) The branching action just described is dependent on the condition that the correct delimiter word opening the source module has been found (STARBIT=l). See "Processing of opening Source Text". The transfer of scanned source text from the Work Area to the output buffer is handled by MSBLOOP (Move Scanned Bytes Loop). Branch Address Table BPRTAB is referenced by most routines which determine a branch on the basis of a Translate and Test instruction. Resultant Current Expected Operator Operator Operator (RO) {CO} (EO) r--------T--------T--------, I * I * I Asterisk I Power Slash I Left Parenthesis Less than Greater than Not ~--------+--------+--------~ ] I / I } I ~--------+--------+--------~ I [ I I ( I I / I I I in TRANSCP ~--------+--------+--------~ I ~ I < I = I ~--------+--------+--------~ I ~ I > I = I ~--------+--------+--------~ IL________ :f: I ________ , I = L-_______ JI ~ Figure 31. BLANK (BLANK) BLANK steps the Work Area pointer REGI to the next nonblank character and returns control to the calling routine (TESTLOOP or LIST). A scan, using Translation Table BTABLE, is initiated if a string of blanks is indicated by a second blank following the first. BTABLE assigns function byte FF to all characters except a blank, which is assigned a zero function byte. KEYTAB keys routine used RIGHTPAR RIGHTPAR transers the ) operator to the output buffer, and sets the pointers CPIN and LAPIN (see "Phase Initialization"). TEST AND TRANSFER OPERATOR (TRANSOP) POINT TRANSOP determines if any of the characters *, /, (, <, >, or Not is associated with an immediately following character, and if so, transfers a one-byte operator representing the two characters in combination. Otherwise, the character is transferred unchanged. The determination is made by comparing the succeeding character with a key, contained in a table named KEYTAB (Figure 31). The key used is specified by the function byte assigned the particular character in the TEST LOOP or LIST routines, from which TRANSOP is entered. Current Operator (CO) represents the character in the source text which activates TRANSOP. The Expected Operator (EO) is the character with which the succeeding character is compared. The Resultant Operator (RO) represents the logical result of CO in combination with EO. RO is transferred to the output buffer, if the succeeding character agrees with EO. CO is transferred if the succeeding character is any character other than EO (excepting blank, which is disregarded, and the record-end operator Zeta, which causes the CIB subroutine to be called). POINT inspects the character which follows a point, using a Translate and Test instruction, and branches to one of six routines according to the value of the function byte assigned the character in Translation Table PTTABLE. The address of the routine entered is obtained from an entry in Branch Address Table (BPRTAE), whose displacement equals the value of the assigned function byte. The function byte assigned by PTTABLE to each character, and the routines entered from POINT, are as follows: Function Character Equal Sign Point Comma Zeta ~ 40 3C 1C 20 44 38 00 Routine Entered DECPOINT ASSIGN COLON SEMCO E~R5 CIB (No branch, scanning continues) Chapter 4: Scan 1/11 Phase 55 DECIMAL POINT (DECPOINT) DECPOINT operator. transfers the Decimal Point ASSIGNMENT (ASSIGN) ASSIGN transfers the Assign operator and passes control to STATE. STATEMENT (STATE) STATE is entered when a statement, identified by an assignment operator or a label, or by the delimiters 'GOTO', 'FOR', or 'IF', has been recognized. It serves to determine if the statement constitutes the body of a procedure, and if so, to stack the operator Proc in place of Proc** (see "Scope Handling Stack"). APOSTROPHE (APOSTROF) APOSTROF has the main function of determining if an apostrophe opens a delimiter or if it represents a scale factor. APOSTROF inspects the characters following the apostrophe by means of a Translate and Test instruction, and branches to one of six routines, determined by the function byte assigned the particular character in Translation Table ATABLE. The branch is made by reference to Branch Address Table (BPRTAB). The function byte assigned to each character in ATABLE, and the routines entered from APOSTROF, are as follows: Character Blank Zeta Invalid Character Apostrophe Not,Or,And,Comma,) or Point , / or ( Function Byte Routine Entered 50 SCALE 48 BLKAPOS ZETAAPO NPAFTAPO DELIMIT EROUT bypassed. The closing apostrophe, however, would terminate the scanning operation, and a branch would be taken to the Delirri ter routine (DELIMIT). The particular action taken by the SCALE, NDAFAPO, DELIMIT, and EROUT routines is governed by a control byte called FBYTE, which may have one of three hexadecimal values: 00, FO, or FF. FBYTE is set to X'OO' in APOSTROF; to X'FO' in TYPE and SPEC; and to X'FF' in COM. The function of FBYTE is to specify whether or not a specific choice of delimiter words is being sought in the source text. Thus, for example, when the TYPE routine determines that an apostrophe immediately follows one of the delimiters 'REAL', 'INTEGER', or 'BOOLEAN', indicating a second delimiter in a sequence '' 'PROCEDURE' or ' DC X'041C' On entry to the called subroutine. REGB contains the address of the i~nediately following parameter list, the first byte of which specifies the error pattern length while the second byte specifies the error number. Pool. except in the case of. Error O. ERROR2: Calculates the length of an identifier or delimiter addressed by a pointer named IN and storeS the length in the parameter list of the calling routine. ERR2D: Activates ERROR2 (which computes an identifier's or delimiter's length and stores the length in a pararoeter list), and ERROR! (which stores the length, error number and semicolon count in an error pattern); moves the identifier or delimiter addressed by IN to the Error Pocl entry addressed by REGY; and returns control to the calling routine. ERR2: The typical return to the calling routine from the called subroutine is of the form: BC 15,2(0, REG B) This specifies a return to the instruction following the parameter list in the calling routine. The error recording routines may be divided into service routines and call routines. Service routines are those which actually store message patterns in the Error Pool, or which handle the necessary processing preliminary to the storage of error patterns. Call routines are those which receive calls for the recording of an error and which, in turn, issue calls to the· appropriate service routines. Call routines may also move source text into an error pattern at an address specified by a service routine. The service routines are the following: ERROR1: Stores the first four bytes of every Error Pool entry, containing the entry length, error number, and semicolon count. The entry length and error number are fetched from the parameter list specified by the calling routine. ERROR1 also updates the Error Pool pointer (NEXTERR) in readiness for the next entry, making allowance for any source text to be subsequently inserted. The address of the current Error Pool entry is transmitted in REGY. In the event of an Error Pool overflow, a branch is made to ERRO. ERROR! is activated every time an error pattern is stored in the Error 58 No. Sets the pointer IN to the last entry for an identifier in the Identifier Table" then branches to ERR2D (which stores the error pattern with the aid of ERROR2 and ERRORl). ERR2B: Sets the pointer IN to an entry in the Identifier Table for a procedure identifier, then branches to ERR2D (which stores the error pattern with the aid of ERROR2 and ERROR!). ERR2E: sets the pointer IN to a location called IDBUCKET (see Type specification routine IDCHECK) containing a procedure parameter, then branches to ERR2D (which stores the error pattern with the aid of ERROR2 and ERROR1). ERR2C: Moves six characters of an erroneous delirriter to a location narred BUCKET, sets pointer IN to that location, and branches to ERR2D (which stores the error pattern with the aid of ERROR2 and ERROR1). ERR?: Activates ERRORl (which stores the length error number and semicolon count in an error pattern). ERR? is called where the error pattern ccntains no source text. ERRO: Records a terminating error indicating an overflow of the Error Pool, and transfers control to the terminating routine EODADIN (via COMPFIN, which turns the TERR switch on). The call routines are described below. certain of the routines handle specific errors and, in calling the service routine, specify a parameter list for the particular error. Other routines handle more than cne error. the parameter list being specified by the calling routine in which the error is detected. ERR1: Calls ERR7, specifying a parameter list for Error No.l. ERR3: Calls ERROR1, specifying a parameter list for Error No.3, then moves the characters previously stored at BUCKET by the Colon routine into the error pattern set up by ERROR1. ERR4: Calls ERROR1 and passes control (via COMPFIN) to the EODADIN routine. ERR4 is called by numerous routines on detection of any terminating error. (See also "Close of Scan 1/11 Phase"). ERRSA: Calls ERROR1, specifying a parameter list for Error No. 35. ERRS: Calls ERROR1, specifying a parameter list for Error No.2. Exits to TESTLOOP or LIST. ERR6: Depending on two switches (which may cause a branch to other routines), calls ERROR1 and moves six characters of a delimiter from the Work Area into the error pattern set up by ERROR1. ERR8: made to the PRINT subroutine in the Directory, which prints out the record previously moved to a print buffer, and transn:its the address of a new print buffer, to which the newly obtained source record will be moved. CIB is called by all routines which scan the source text, on recognition of the recorded operator Zeta. The latter is inserted by CIB at the end of each translated record in the Work Area. In the event the source module is in ISO code, each record is first translated to EBCDIC code by searching for the characters (, ), =, + and the apostrophe (the only characters whose representation differs between the EBCDIC and ISO codes) and replacing these characters by their EBCDIC combinations. This conversion simplifies the subsequent translation to internal code and facilitates printing the source text on the printer. in Which the code implen:ented is EBCDIC. The translation to internal code is made with the aid of translation table TRLTAE~E, and produces the character set shown in Appendix I-a. Depending on a switch~ calls ERROR1, specifying a parameter list for Error No.11. Exits to TESTLOOP or LIST. IDENTIFIER TEST (IDCHECK1) ERR18: Calls ERROR1, specifying a parameter list for Error No. 18. ERR9: Calls ERR7, then transfers control to EODADIN (see also "Close of Scan 1/11 Phase"). ERROR10: Calls ERR2B, specifying a parameter list for Error No. 10 (which indicates that certain parameters of a procedure have not been specified). On return, ERROR10 inserts an allpurpose internal name in the Identifier Table entries representing the unspecified parameters. ERR21: stores the length of a declarative delimiter in a parameter list for Error No.21; calls ERROR1, specifying the parameter list; and then moves the delimiter from the Delimiter Table into the error pattern set up by ERRORl. CHANGE INPUT BUFFER (CIB) CIB gets an SO-character record of the source text from the SYSIN data set into the Work Area (WA); copies the record into a print buffer or a dummy print area; and translates the record in the Work Area to the internal code (Appendix I-a). If the SOURCE option is specified, a branch is IDCHECK1 is entered from the PROCID, ARRYID, and SWITCH routines, after a test has determined that the first character of a procedure, array, or switch identifier is a letter. IDCHECKl transfers the letter to an entry in the Identifier Table and to the output buffer; inspects the following characters of the identifier, similarly transferring the next five characters. provided they are letters or digits; and returns control on detection of any character other than a letter or digit. CHANGE OUTPUT BUFFER (COB AND COBSPEC) See also "Phase Initialization". COB determines if the last byte but one in the current output buffer has been filled (by comparing pointer EAP (register 3) with buffer-end pointer APE), and if so., transfers the buffer-end indicator Zeta to the last byte pointed to by EAP; writes out the current buffer (whose address is stored at WADDARI); and resets pointers EAP and APE to an alternate buffer, addressed by ADDARI + DISP storing the address of the new buffer at WADDARI. If the current buffer has not been filled. COB returns control to the calling routine. COB is Chapter 4: Scan 1/11 Phase 59 called in advance of every transfer of one or more characters to the output buffer. ters, or if the comparison described above produces no corresponding Delimiter Table entry, control is passed to the Delimiter Error routine (EROUT). COBSPEC, a special entry point of COB, includes a test as to whether a variable number of unfilled bytes (two or more) remain in the current buffer. The test consists in comparing REGO (instead of EAP) with APE, where REGO, preset by the calling routine, indicates the current address value of EAP, incremented by the required number of bytes. COB SPEC is called when a unit of data may not be split between records (e.g. the three-byte unit transferred by SEMCO, containing the Semicolon (or Delta) and the semicolon count). After a delimiter has been correctly identified, a test is made of the STARTEIT to determine if the correct delimiter opening the source module has teen found (indicated by STARTBIT=l). If not. control is passed to STARTDEL (see "Processing of Opening Source Text"). Otherwise. the routine corresponding to the delimiter identified is entered. DELIMITER (DELIMIT) Before the comparison described above is initiated, a test is made of the switch named FBYTE. FBYTE=X'FO' signifies that one of the delimiters 'PRCCEDURE' or 'ARRAY' is being sought: while FBYTE=X'FF' signifies that one of the delimiters 'ELSE' or 'END' is being sought. In either of these cases, control is passed to TYFESPEC or COMSPEC (See also APOSTROF). otherwise (FBYTE=X'OO'), a normal comparison is initiated. DELIMIT is entered from APOSTROF when the second of two apostrophes enclosing a delimiter word has neen identified. DELIMIT compares the characters enclosed by apostrophes with a set of delimiter words in the Delimiter Table (W1TAB -- Figure 32), and when the corresponding word has been located, branches to the routine whose address is specified in an entry of the Branch Address Table (DELPRGTB). The displacement of the entry in the Branch Address Table is indicated opposite the delimiter in the Delimiter Table. The delimiter in the source text is compared with the group of words in the Delimiter Table having the same number of characters. The length of the delimiter in the source text is contained in REGL. The particular word group in the Delimiter Table, with Which the comparison is to be made, is found with the aid of a look-up table (L1TAB) consisting of ten four-byte entries each containing the address of the particular word group. Thus, the address of a given word group comprising words of the same length (REGL) as the source delimiter, is contained in the entry specified by L1TAB + 4*C(REGL). Within a given word group, the entries for all words are uniform in length, being equal to the number of characters in the word, plus three (a two-byte characteristic or operator and a one-byte displacement - the displacement of the corresponding entry in the Branch Address Table, DELPRGTAB). The number of entries in the word group is indicated in the byte preceding the word group (loaded in REGY). If the apostrophes enclose no characters, Error No. 12 is recorded. I f the apostrophes enclose more than ten charac60 DELIMITER ERROR ROUTINE (EROUT) EROUT is entered from APOSTROF, when the closing apostrophe of a delimiter word is mlsslng, and frorr, DELIMIT, when a misspelling is detected in a delimiter word. EROUT compares the characters following the opening apostrophe with each of the words in the Delimiter Table (W1TAB), moving dOwnward through the table, and if a matching word is found, branches to the routine specified. (See DELIMIT routine). If no matching delimiter is found., Error No.14 is recorded, the apostrophe is disregarded, and control is returned to TESTLOOP. The comparison proceeds by comparing (1) the first character of the defective delimiter with each of the entries in the first word group of the Delimiter Table., (2) the first two characters with the entries in the second word group, (3) the first three characters with the entries of the third word group, and so on, until a matching delimiter word is found, or until the last word group has been compared. The comparison is conditional on the switch FBYTE=X'OO'. If FBYTE=X"FO' or X' FF' , control is passed to TYPESPEC or COMERR directly (see below). After identification of a delimiter. the same test of the STARTBIT is made as that described under DELIMIT. DEL I MI TE R TABLE Hexadecimal 1 Word Group No. 2 3 4 No. of Entries in Delimiter Word One-byte Operator Notation used in this Manual (see column 6) I I 1 02 '(' 2 3 PI ::l ~~ GIF 'OR' 'END' Or 4E 51 22 00 00 NORMAL 44 4D 43 00 00 10 END 45 4E 51 00 00 14 FOR NORMAL 2) 04 3) 'AND' And 40 4D 43 23 00 'NOT' Nat 4D 4E 53 20 00 00 00 44 40 4B C2 12 18 09 H " Notes: ~ 52 53 44 4F 19 00 00 NORMAL Then 53 47 44 4D 1E 00 08 TED TED , ELSE' Else 44 4B 52 44 1F 00 08 'GOTO' Goto 46 4E 53 4E 17 00 OC GIF 53 51 54 44 07 00 1C BOLCON 4B 44 52 52 42 4E 43 44 11 00 00 NORMAL 00 00 20 CODE NORMAL < 3) ~ 2) OA Until 3) 21 00 00 41 44 46 48 4D 00 00 24 BEGIN 54 4D 53 48 4B 40 51 51 4058 lA CA 00 16 00 28 NORMAL 55 40 4B 54 44 00 18 2C 44 4B 00 CA 56 47 48 4B 44 1B 00 45 40 4B 52 44 00 00 05 10 4B 40 41 While 'POWER' Power , EQUAL' = 4F 4E 56 44 51 44 50 54 40 48 , EQUIV' ~ 44 50 54 48 55 3) 02 ' INTEGER' 05 4) 48 4C 4F 48 'WHILE' , FALSE' 30 00 4) BOLCON 00 00 00 NORMAL 00 NORMAL 24 00 00 NORMAL 52 56 48 53 42 47 52 53 51 48 4D 46 CA lC 34 SWITCH CB 10 30 SPEC 48 4D 53 44 46 44 51 C2 11 18 TYPE 41 4E 4E 4B 44 40 40 C2 13 18 TYPE 'COMMENT' 42 4E 4C 4C 44 40 53 00 00 38 COM ~ 4D 4E 53 4B 44 52 52 15 00 00 NORMAL I , GREATER' > 46 51 12 00 00 NORMAL I 13 00 00 NORMAL 9 ' PROCEDURE' ' NOTGREATER' 01 'f 3) ~ 44 40 53 44 51 40 4E 53 44 50 54 40 4B 51 4E 42 44 43 54 51 01 4F 01 40 4E 53 46 51 -- 44 44 40 53 44 51 -_._._- CA _ 14 .. __. - DO 3C PROCEDUR 00 00 NORMAL ----- I For the specifi-cators .. REAL", .. ARRAY", .. LABEL", .. SWITCH", "STRING', , INTEGER', .. BOOLEAN'" and" PROCEDURE', the two-byte cha'octeristic is copied into the Identifier Table entries of specified formal parameters. In the case of all other del imiter words (except for ~ TRUE~ and ~ FALSE~ ond all delimiters for which both bytes in the column representing the delimiter. The notation in column 3 indicates the nome by--w'hich the operator is identified in the text. = X ~ 00"), the first byte is transferred to the Mldification Levell text as a one-byte operator Oelimi"ter vcriously represented in t-he M:>dification Levelland 2 versions of source text by two or more one-byte operators, supplied by program. See "Scope Identification", "Iv\odification Levell Source Text"and Appendix I-b. PI CIl 3. Delimiter represented in the IVIodification Levell text by one-byte operator supplied by program. See Appendix I-b and "Iv\odification Level- 1 Source Text". 4. First byte specifies the displacement of the constant 0 {False} or 1 (True) in Constant Pool No. O. 0.... I , NOTLESS' 'U CD NORMAL lC 2. P" I ARRAY VALUE SPEC 'BOOLEAN' ' NOTEQUAL' H H NORMAL TYPE , THEN' 8 1. 51 ' REAL' , STEP' ' SWITCH' 10 TED OC 'STRING' en o STRING 08 , LABEL' ., NORMAL 04 00 03 , VALUE' rt 00 00 00 , ARRAY' ~ 04 00 00 06 03 lC ' BEGIN' , UNTIL' 7 Nome of Routine Entered 10 'IMPL' i '0 I 43 4E 48 45 LESS' 6 Delimiter Word Displacement of Full-Word Entry in lIranch Adcre.. Table DELPRGTAB, containing Entry Point of Routine Entered 8 If 'CODE' ("l 7 Do 'TRUE' 5 6 One-byte Operator (second byte = X' 00') Q[ Two-byte Characteristic for Specificators 9£ Null Operator {both bytes = X' 00') 'DO' , IF' 'FOR' 4 5 Word Group (F irst byte in Word Group) (WI TAB) Reoresentation Figure 32. Delimiter Table (WITAB) TYPE SPECIFICATION (TYPESPEC) TYPESPEC is entered from DELIMIT and EROUT by virtue of the switch FBYTE=X'FO'. FBYTE is set to X'FO' by the TYPE routine when a test shows that a type declarator ('REAL', 'INTEGER', or 'BOOLEAN') is immediately followed by another apostrophe, indicating a further delimiter. (Unless the latter delimi ter is 'PROCEDURE' or 'ARRAY', the source text is in error). TYPE passes control to ENTRAPR (an entry point of APOSTROF). which scans to the next apostrophe and branches to DELIMIT or EROUT, which branch in turn to TYPESPEC on finding FBYTE=X'FO'. TYPESPEC inspects the delimiter and passes control to TYPPROC or TYPEARRY, if the delimiter is 'PROCEDURE' or 'ARRAY', respectively. If any other delimiter is identified, control is passed to the Identifier Error routine IERSPEC. The latter serves to bypass the defective declaration and to record an error. COMMENT (COMSPEC) COMSPEC is entered from DELIMIT by virtue of the switch FBYTE=X'FF'. FBYTE is set to X'FF' by the COM routine when an apostrophe is found in a sequence of comment following 'END', indicating that the comment is terminated by a delimiter word. The, latter should be 'END' or 'ELSE'. COM passes control to ENTRAPR (an entry point of APOSTROF), which scans to the next apostrophe and branches to DELIMIT, which branches in turn to COMSPEC on finding FBY'I'E=X' FF'. COMSPEC inspects the delimiter and passes control to END or TED, if the delimiter is 'END' or 'ELSE'. If any other delimiter is identified, control is passed to COMCED2 (an entry point of the COM routine). The latter continues to scan to the next semicolon or apostrophe, disregarding the delimiter. OPENING DELIMITER transfers the operator Begin to the Modification Level 1 text. stacks Begin. and turns the BEGBIT switch on. If the stack operator is Proc. indicating that the delimiter 'BEGIN' opens the body of a procedure Closed ty 'END'. the stack operator Proc is replaced by Proc* and the PROBIT switch turned off. STRING (STRING) STRING is entered from DELIMIT and ERCOT on recognition of the first of two string quote signs' (' ••• ')' enclosing a character string. STRING stores the enclosed character string in the Constant Pool and transfers a five-byte internal name. referencing the location where the string is stored, to the Modification Levell text. The internal name (see Appendix II) is preceded by the Apostrophe operator. The string is stored in the Constant Pool in the external code (EBCDIC or ISO) of the source module -- it is copied from the print area (or dummy print area) to which each source module record is moved ty CIB, before the record is translated to the internal code. see Figure 7. NORMAL ACTION (NORMAL) NORMAL is entered from DELIMIT or ERCUT when any cne of the following delimiters is identified: "/", 'OR'. 'AND', 'NC'I', 'STEP', 'LESS', 'UNTIL', 'NOTLESS', 'EQUAL', 'EQUIV', 'IMPL', 'WHILE' , 'GREATER', 'NOTEQUAL', and 'NOTGREATER'. NORMAL transfers the corresponding one-byte operator in the Delimiter Tatle (Figure 32) to the output buffer and returns control to TESTLOOP or LIST. (ST&~TDEL) BOOLEAN CONSTANT (BOLCON) See "Processing of Source Module Opening Text" • BEGIN (BEGIN) BEGIN is entered from DELIMIT and EROOT on reCOgnition of the delimiter 'BEGIN'. BEGIN inspects the Scope Handling stack and, unless the stack operator is Proc, BOLCON is entered from DELIMIT or ERCUT when the boolean constant 'TRUE' or 'FALSE' is encountered. A five-byte internal name (Figure 33) is transferred to the output buffer, indicating the character of the boolean constant, and referencing a location in the Constant Pool where the constant 0 (False) or 1 (True) is stored. The internal name is preceded by the Apostrophe (X'2E'), which signals the Scan III Phase that an internal name follows. (Character istic) o 1 (Constant (Displacement) Pool> 2 3 4 5 output text and in the Scope Handling Stack. It also constructs entries in the Group Table, Program Block Number Table and Semicolon Table. r------,-----~------T------T------, , TRUE' IL______ C8 L-_____ I 03 L-_____ I 00 I ______ 00 I ______ 07 JI ~ ~ r------,------.------T------T------l END (END) Figure 33. END is entered from DELIMIT or EROUT when the delimiter 'END' is recognized. Its function is to inspect the operator in the Scope Handling Stack and to activate the appropriate closing sutroutine, according to the stack operator detected: ~ , FALSE' IL______ C8 L-_____ I 0 3 L-_____ I 00 LI ______ 00 I ______ 00 JI Internal Names of boolean constants 'TRUE' and 'FALSE' GOTO-IF (GIF) GIF is entered from DELIMIT or EROUT on recognition of the delimiters 'GOTO' and 'IF'. The one-byte operator given in the Delimiter Table (Figure 32) is transferred to the output buffer and control passed to STATE. Stack operator Subroutine Activated Beta, Proc Proc*, --pr;jc** PBLCKEND COMPDEND FOREND THEN-ELSE-DO (TED) ERR8 (see "Close of Scan I/II Phase") The subroutines are described below. TED is entered from DELIMIT or EROUT on recogni tion of the delimiters 'THEN " 'ELSE', or 'DO'. A one-byte symbol representing the delimiter in the Delimiter Table (Figure 32) is transferred to the output buffer. Before control is returned to TESTLOOP or LIST, pointers OPIN and LAPIN are set to point, respectively, to the delimiter symbol transferred and to the next byte in the output buffer (see "Phase Initialization"). COMPOUND END (COMPDEND) COMPDEND releases the stack operator Begin and transfers the operator End to the output text, marking the close of a compound statement. See END. FIRST BEGIN (FIRSTBEG) See "Processing of Source Module Opening Text" • PROGRAM BLOCK (BEGl SUBROUTINE) BEGl is activated as soon as a new block has been identified. It is entered from all declaration-handling routines (e.g. TYPE, PROCEDUR, ARRAY) processing the first declaration following the delimiter 'BEGIN' (indicated by the switch BEGBIT=l). BEGl constructs a program block heading entry in the Identifier Table, containing a new Program Block Number; resets the pointers LPBP and LIGP to the new heading entry; and replaces the operator Begin by Beta in the FOR STATEMENT END (FOREND) FOREND, which is entered from END and SEMCO on detection of the delimiter 'END' or a semicolon closing a for statement, constructs a for statement closing entry in the Identifier Table, if the closed for statement contained a declared lacel. If the closed for statement contained no declared labels, the for statement heading entry is deleted. FOR END also transfers the operator~, followed Cy the Identifier Group Number., to the output text, and releases the stack operator For. Pointer LIGP is reset to point to the heading entry of the reentered for statement, if any, or to the heading entry of the enClosing clock or procedure. Chapter 4: Scan I/I1 Phase 63 PROGRAM BLOCK END (PBLCKEND SUBROUTINE) PBLCKEND, which is called by END and SEMCO on detection of the delimiter 'END' or a semicolon closing a block or procedure, transfers the set of entries in the Identifier Table representing identifiers declared or specified in the block or procedure to the SYSUT3 data set. The program block heading entry which heads this set of identifiers is indicated by the pointer LPBP. Before the transfer is executed, pointers LPBPand LIGP are reset to the address of the heading entry corresponding to the enclosing block or procedure (see "Processing of Identifier Table"). PBLCKEND also transfers the operator Epsilon to th~ output text, followed by the Program Block and Identifier Group Number of the enclosing block, procedure or for sta tement, and releases the stack operator. ning continues until a semicolon is found. This deletes all source text beginning with the declarator and extending up to (but not including) the next semicolon. When the semicolon is found, SEMCO is entered. FOR STATEMENT (FOR) FOR is entered from DELIMIT and EROUT on recognition of the delimiter 'FOR'. A for statement heading entry is constructed in the Identifier Table and entries are made in the Scope and Group Tables. If the stack operator is Proc, it is replaced by Proc**. The operator For is stacked and transferred to the output text, followed 1:;y a new Identifier Group Number. TYPE DECLARATION (TYPE) COMMENT (COM) COM has two main fUnctions: to bypass comments, and to delete (or bypass) erroneous declarations. The routine scans the source text (using translation table COMTABLE) for a semicolon, an apostrophe, a blank, or Zeta. The function 1:;ytes assigned these characters specify displacements to subprograms of the COM routine. There are three entry points: COM, COMMEND, and COMERR. COM is entered from DELIMIT and EROUT when the delimiter 'COMMENT' has been encountered. scanning continues until a semicolon is found. This deletes (or bypasses) all source text beginning Hith , COMMENT' and extendl.ng up to and including the semicolon. COMMEND is entered from END when a comment of the following form is to be eliminated: 'END' 'END'/;/ 'EI.SE'. scanning terminates when a semicolon or an apostrophe is found, deleting the preceding comment. In case a semicolon is found, SEMCO is entered. If an apostrophe is found, the switch FBYTE is set to X'FF' and control passed to ENTRAPR (an entry point of APOSTROF). APOSTROF scans to the next apostrophe, branches to DELIM!'l' (or EROUT). which branches to COMSPEC on finding FBYTE=FF. COMSPEC inspects the delimiter and branches to END or TED if the delimiter is 'END' or' ELSE', respectively. In all other cases, CO~illRR is entered. COMERR is entered from several declaration-processing routines when an erroneous declaration is identified. Scah64 TYPE is entered from DEI.I~IT and ERCUT on recognition of any of the declarators 'REAL', 'INTEGER', or 'BOOLEAN'. The rcutine makes an entry in the Identifier Tatle for each of the identifiers following the declarator, provided the identifier is valid. If any invalid character is fcund in the identifier, control is passed to the Identifier Error routine (IER), which deletes the entry made in the Identifier Table and records Error No. 5 or 16. If the declarator is immediately followed ty another apostrophe, indicating a furthe·r delimiter, the switch FBYTE is set"" X'FO' and ENTRAPR (an entry point of APCSTROF) is entered. At entry, the switchesPROBIT and BEGEIT are tested, in that order. If PROBIT=l, indicating that the delimiter specifies a formal parameter in a procedure heading, control is passed to the SPECENT routine. If BEGBIT=l, indicating that the declarator represents the first declaration following 'BEGIN' and that, accordingly, a new tlock has been entered, a call is made to the BEGl subroutine (which assigns a new Program Block Number) before entries for the declared identifier(s) are made in the Identifier Table. IOENTIFIERERROR (IER) IER is entered from declaration- processing detection of a defect in a declared ident.ifier. The routine deletes all or part of an entry for the identifier in the Identifier Table and reCords .Error No. S or 16, depending on the entry point HER or Form Y33-8000-0, Page Revised by TNL Y33-8001, 12/15/67 IERSPEC). It also skips over the source text up the next comma, semicolon, or ri'Jht parenthesis, in the case of a formal parameter list. CODE PROCEDUHE (CODE) CODr; is entered from 1)ELDUT or EROUT on recoqnition of the delimiter 'CODE', representinIJ the body of a code procedure. The routine verifies that 'CODE' follm-1s a procedure heading; modifies the characteristic in the entry previously made (by the PROCEDUR and PROCID routines) for the p~ocedure identifier in the Identifier Table, so as to designate a code procedure, and transfers up to six characters of the procedure identifier, follo"Ted by t,'lO nlanks, to the output text, preceded by the operator Gamma. After finding the semicolon ';>1hi~hould follo"1' CODE' , the PI3LCKEHD subroutine is called and control tl1cn passed to SEliCO. At entry, the s,,1itches PROI3IT and BEGm~ are tested, in that order. If PROBIT=l indicating that the delimiter specifi:es a formal parameter in a procedure: heading, control is passed to the SPECENT routine. If 3EGBIT=1, indicating thatthe declarator represents the first delimiter follo,,1ing 'BEGIN', and that, accordingly, a new block has been entered, a call is made to the BEGl subroutine ("1hich assigns a ne," Program Block Number) before processing continues. SPECIFICATION (SPEC) SPEC is entered from DELIMIT or EROUT on recognition of the specificators 'LABEL' and 'STRING'. Its function is to verify that the specificators occur in a procedure heRding. If they do, control is passed to the Type Specification routines (SPECENT and IDCHECK). If not, Error No.25 is recorded, and the declaration is skipped by branching to COMERR. VALUE (VALUE) VALUE is entered from DELIMIT or EROUT on recognition of the delimiter 'VALUE' After testing the s';>1i tch PROBIT to insure that the delimiter occurs in a procedure heading (signified by PROBIT=l), the switch VALBIT is turned on and control is passed to IDCHECK. The latter locates the Identifier Table entry corresponding to each formal parameter which follows'VALUE', and, by virtue of VALBIT=l, sets the value bit in the identifier characteristic (Figure 9) so as to designate a value-called parameter. PAIU\:lE'rER SPECIFICATION (SPECENT and IDClIECK) SPECEu'r is entered from TYPE, ARRAY, S';nTCH and PROCEDUR, when a specificator is ~ncountered in a procedure heading (indicatecl by PROBIT=l). SPECENT moves the corresponding two-byte characteristic contained in the Delimiter 'I'able (Figure 32) to a field named 1m and then enters IDCHECI<. IDCHECK is entered from SPECENT Rnd from VALUE. IDCHECK~s function is to locate the appropriate entry (entries) in the Identifier Table and a) to insert the characteristic and Program Block ::~umber, or b) to set the value hit in the characteristic. (Before the value or specification parts of a procedure heading are processed, the external names of all formal parameters are copied into a sequence of Identifier Table entries, from the parameter list "lhich follmls the procedure identifier. The first of these entries is addressed by the pointer PRIlvlPAR). The characteristic is inserted by ORing the relevant bytes of the Identifier Table entry \'lith the contents of the location KB. TYPE ARRAY (TYPEARRY) TYPEARRY is entered from TYPE SPEC when a delimiter sequence of the type '' 'ARRAY' has been identified. If PROBIT=l (indicating the delimiter sequence occurs in a procedure heading) control is passed to IDCHECK which proceeds to complete the Identifier Table entry for a type-array parameter of a procedure. If BEGnIT=l (indicating the delimiter sequence represents the first declaration following 'BEGIN', and that accordingly 'BEGIN' opens a block), the BEGl subroutine is called. Thereafter, control is passed to the ARRAY routine (by way of ARRYDaEl), which constructs an entry for a type-array identifier in the Identifier Table. ARRAY DECLARATION (ARRAY) ARRAY is entered from DELI~UT and EROUT on recognition of the delimiter 'ARRAY'. The routine constructs an entry in the Identifier Table for each array identifier following the declarator (by call to the IDCHECKl subroutine); and transfers the operator Afray to the output text, followed by up to s~x characters of each identifier. On recognition of the left bracket, (/, marking the beginning of the dimension list, the operator [ is transferred to the output text and control passed to the LIST routine. The LIST routine analyzes the dimension list, records a count of the number of dimensions in the corresponding Identifier Table entries, transfers the dimension list to the output text, and returns control to ARRAY if the dimension list is followed by a further identifier. Chapter 4: Scan I/II Phase 65 At entry, the switches PEOBIT and BF.GBIT are tested, in that order. If PROBIT=1, indicating that the delimiter specifies a formal parameter in a procedure headins, control is passed to the SPECENT routine. If BEGBIT=1, indicating that the declarator represents the first declaration following 'BEGIN' and that a new block has teen entered, a call is made to the BEG1 subroutine (which aSSigns a new Program Block Number), before entries for the declared array(s) are made in the Identifier Table. cOITponent list; and record the dimension count or component count in the correspcnding Identifier Table entries made by the ARRAY or SWITCH routines for the array or switch identifiers. The actual dimensions in a dimension list or the components in a component list are transferred to the cutput text by the LIST routine before branching to the routine concerned. The switch ARBIT=1 specifies an array dimension list, while ARBIT=O specifies a switch component list. ARRAY/SWITCH LIST (LIST) POINT IN LIST (PONTLST) The LIST routine is entered frOI,] the ARRAY and SWITCH routines upon recognition of a din,ension list in an array declaration or a component. list in a switch declaration. LIST scans the source text (beginning with the first character following the left bracket in an array declaration or the first character following the assignment operator in a switch declaration) for anYone of 15 characters assigned a non-zero functior, byte in Translation Table (ARTABLE); moves the scanned text to the output buffer; and branches to the routine whose address is specified in a full-word entry of Branch Address Table (BPRTAB) given by the value of the character's function byte. PONTLST inspects the character following tbe point and passes control to CCLONLST or SEMCLST or transfers a Decimal Point. The fUnction bytes assigned by ARTABLE to the chal:acter set and the routines entered from LIST are as follows: Character Apostrophe >* < Not Zeta Blank Invalid Character' Comma / ) ( Point Colon Semicolon Function Byt 5E Routine Entered 34 04 14 10 18 38 28 2C APOSTROF TRANSOP 80 88 6C 68 84 54 58 00 COMVlALST SLASHLST RIGHTPARL LEFTPARL PONTLST COLONLST SEMCLST (No branch, scanning continues) " " " CIB BLANK ERR1 The latter seven routines recognize separators in a dimension on component list; transfer re~resentative operators to the output Luffer; count the number of dir,lensions or components in a dimension or 66 RIGHT PARENTHESIS IN LIST (RIGHTPARL) RIGHTPARL transfers a right parenthesis and deorements the bracket count. LEFT PARENTHESIS IN LIST (lEFTPARl) LEFTPARL transfers a left parenthesis or a left bracket, [ , representing (/, and increments the bracket ccunt. CO~MA IN LIST (COMMALST) CONll,ALST increl~ents the dirrension and transfers the Comma operator. ccunt COLON IN LIST (COLONLST) Transfers a colon, provided it occurs in an array dimension list. If it occurs in a switch component list, the colon is disregarded and Error No.3 is recorded. SEMICOLON IN LIST (SEMCLST) SEtJiCLST stores the component count in the Identifier Table entry specified by a pointer named DIM, and transfers control tc SJ:::MCO, after specifying the return address of TESTLOOP. If the semicolon occurs in an array dirrension list, Error No.32 is recorded, deleted. and the identifier entry is Block Number for the procedure identifier, followed by a program block heading entry., and copies the external names of the formal parameters in the parameter list into the following entries. SLASH IN LIST (SLASHLST) SLASHLST inspects the character following the slash and transfers the slash or a right bracket, 1; enters the dimension count for a declared array in the Identifier Table entry indicated ~' pointer DIM; and transfers control to ARRAY, SEMCO, or COMERR, according to whether the character following is a comma, a semicolon., or any other character, excepting Zeta or a blank. Initially., the PROBIT and BEGBIT switches are tested, in that order. If PROBIT=l (indicating that the delimiter 'PROCEDURE' specifies a formal parameter in a procedure heading), control is passed directly tc SPECENT. If BEGBIT=l (indicating that the delimiter represents the first declaration following 'BEGIN' and that., accordingly" 'BEGIN' opens a new block), a call is made to the BEG1 SUbroutine. PROCEDURE IDENTIFIER (PRCCID) SWITCH DECLARATION (SWITCH) At entry to the routine, the switches PROBIT and BEG BIT are tested, in that order. If PROBIT=l (indicating that the delimiter specifies a formal parameter in a procedure heading), control is passed to the SPECENT program. If BEGBIT=l (indicating that the declarator represents the first declaration following 'BEGIN' and that., accordingly, a new block has teen entered), the subroutine BEG1 is called before entries for the declared switches are made in the Identifier Table. PROCID is entered from PROCEDUR when a procedure declaration has teen encountered. PROCID first constructs an entry in the Identifier Table for the procedure identifier. The external name (up to six characters) is copied into the entry and transferred to the output text ty call to IDCHECK1. The characteristic for the procedure identifier will have been stored in the entry by PROCEDUR. When a left parenthesis (opening a parameter list) or a semicolon (following the identifier of a parameterless procedure) is encountered., a program block beading entry is constructed. If the procedure is a type-procedure., a second identifier entry for the procedure identifier is made immediately after the heading entry. The external names of the formal parameters, represented by a maximum of six characters, are now copied into the following entries of the Identifier Table and the output text. The two-tyte characteristics of these parameters are inserted immediately after, by the SPECENT routine when the specifications in the procedure heading are processed. Control is passed to SEMCO as soon as a semicolon following the closing right parenthesis of the parameter is encountered. PROCEDURE DECLARATION (PROCEDUR) TERMINATION (EODADIN) SWITCH is entered from DELIMIT and EROUT on recognition of the declarator 'SWITCH'. SWITCH constructs an entry in the Identifier Table for the identifier following the declarator, and transfers up to six characters of the identifier to the output text, preceded by the operator Switch. On detection of the assignment operator marking the beginning of the component list, the Assign operator is transferred and control passed to the LIST routine. LIST transfers the component list to the output text, counts the number of components in the list, and enters the component count in the Identifier Table entry for the switch identifier. PROCEDUR is entered from the DELIMIT and EROUT routines on recognition of the delimiter 'PROCEDURE'. PROCEDUR makes entries in the Group, Semicolon, and Program Block Tables; transfers the operator Pi to the output text and the Stack; inserts the characteristic for a declared procedure identifier into the next entry of the Identifier Table; and passes control to PROCID, which constructs an entry in the Identifier Table, containing a new Program EODADIN is entered from: 1. PBLCKEND (via CO~MEND and READRCUT) when the stack operator Alpha (marking the bottom of the Scope Handling Stack) indicates that the outermost scope of the source module has been closed; 2. ENDMISS when an unexpected End of Data condition occurs; Chapter 4: Scan 1/11 Phase 67 3. PI ROUT (in the Directory) when a program interrupt or unrecoverable I/O error occurs; and 4. ERR 4 when a terminating error detected in the source module. is See also "Close of Scan I/ II Phas e". EODADIN transfers the closing operator Omega to the Modification Level 1 text; writes out the last record of the modified source text (by calling COB), except when the entire text occupies less than a full buffer (in which case it is transmitted to the Scan III Phase in the Common Area buffer): generates TXT records of the character strings in the Constant Pool (ty calling the GENERATE - GENTXT5 subroutine) on the SYSPUNCH and/or SYSLIN data sets, provided the DECK and/or LOAD options have been specified; closes the SYSIN., SYSUT1, and SYSUT3 data sets; releases main stor- 68 age; and transfers control to the Identifier Table Manipulation Phase (IEX20), or, if a terminating error has occurred, to Diagnostic Output Module IEX21. If the source module is a precompiled procedure, Prcgrarr Block No. 0 in the Identifier Table, containing an entry for the procedure narre, is transferred to the SYSUT3 data set (by call to PBLCKEND) and an ESD record for the procedure narre is generated (by calling GENERATE-GENESD). The precompiled procedure name will have been stored in external code at the location named ESDPARAM by the PROCID routine. GENERATE SUBROUTINE See Chapter 8. CHAPTER 5: IDENTIFIER TABLE MANIPULATION PHASE (IEX20) PURPOSE OF THE PHASE contents of the Identifier Table, if the SOURCE option has been specified. The main purpose of the Identifier Table Manipulation Phase is to complete the construction of the internal names of all identifiers listed by the Scan 1/11 Phase in the Identifier Table. Except in the case of entries for declared procedure and switch identifiers and labels, the last two bytes of the internal name provide space for the relative address of the identifier's object time storage field (Figure 36). The Identifier Table Manipulation Phase assigns an object time storage field to each identifier, and stores the corresponding relative address in the space provided in the identifier's internal name. The processing of the Identifier Table, which forms the main input to the Identifier Table Manipulation Phase, may be divided into the following functions. 1. To search each group of identifiers in the Identifier Table for repeated declarations of the same identifier, and to record appropriate error patterns in the Error Pool. IDENTIFIER TABLE MANIPULATION PHASE OPERATIONS The diagram in Figure 34 illustrates the principal operations performed in the Identifier Table Manipulation Phase. The bracketed numbers in the following text refer to the numbered positions in the diagram. IDENTIFIER TABLE MANIPULATION PHASE (lEX20) 1. Identifier Scan (READBlK) Reads on IT AB record into the work oroa and stores the record '$ work (lists addresses of ITAB records in oscending Program Block Number order) IIT~B) Outputs IT AS when all records have been processed. Records ore output in ascending Program Block Number sequence, with the aid of AlAB. Posses control to ITABPRNT if the SOURCE option is specified; otherwise, to CLOSE. orea address in AlAB. Scans the record for multiple declarations and records errors in the Error Pool. Posses control to AllOSTOR. SYSUT3 Identifier 3. Write ITAB ('NRITITAB) SYSUT3 Identifier Work Areo f - -........_-+L.-I ___ _ f---....l.--~ rIT~B) (Records not in Progrom Block Number order) (Records in Progrom Block Number order) om {Records in Program Block Number order} SySPRINT 2. 3. To allocate object time storage fields to the identifiers listed in the Identifier Table, and to record the relative address of each identifier's assigned storage field in the identifier's internal name. The relative address represents a displacement from the beginning of a Data Storage Area, comprising the total number of bytes assigned to identifiers declared or specified in the particular block or procedure. To construct Program Block Table II (PBTAB2), indicating the size of the Data Storage Area required at object time for every block and procedure in the source module. Program Block Table II is transmitted in main storage to the Compilation Phase, in which the space requirements recorded in the table are augmented by additional space allocations for the storage of intermediate results. 4. To transmit the completed Identifier Table (via SYSUT3) to the Scan III Phase according to ascending Program Block Number sequence. 5. To generate a printed listing of the Allocotes (I storage field in on object time Doto Storage Area for each identifier in on ITAB record, and records the relative address in !~: !~:t~:i~:~!i;Bf~~tJI' i~::t~~ fiers, in PBTAB2. Retums to Identifier Scan, unless the lost record has been read, in which case control is passed to WRITITAB. Identifier L-_---' 4. Print ITAB (tTABPRNT) If~~ Prints a listing of ITAB, if the SOURCE option is t~S~~~d, exits fo end 5. Termination (CLOSE) ~r~:sf:~ ~:~~~;~~ar~o~nd Module IEX21 (for output of diagnostic meS50ges reflecting errors recorded in Error Pool). I (XCTl to IEX21) t Figure 34. Identifier Table Manipulation Phase. Diagram illustrating the functions of the principal constituent routines. Identifier Table records (1) are read into a work area an~ processed, one at a time, in the order ~n which they were stored on the SYSUT3 data set by the Scan 1/11 Phase, that is, according to the sequence in which the blocks and procedures were closed in the source module. To enable the records to be output in ascending Program Block Number sequence, the address of each record is stored ~n the Address Table (ATAB), in an entry determined by the record's Program Block Nureber. Initially, each record is scanned by the Identifier Scan routine to determine if multiple declarations were made for the same identifier. Chapter 5: Identifier Table Manipulation Phase 69 After the record has been scanned and appropriate errors recorded in the Error Pool, the Storage Allocation routine (2) allocates an object time storage field to each identifier, and records the address of the allocated bytes (relative to the beginning of the Data storage Area comprising the total allocation for the block or procedure) in the corresponding identifier entry. The Identifier Table listing is compiled by the lTABPRNT routine and printed on SYSPRINT, line by line, by call to PRINT in the Directory. Phase Input/Output IDENTIFIER TABLE (ITAB) When all records of the Identifier Table have been read in and processed in this manner, the Identifier Table is (3) retransferred to the SYSUT3 data set, records being output in ascending Program Block Number sequence. If the SOURCE option was specified, (4) a listing of the Identifier Table is printed; otherwise, (5) the termination routine (CLOSE) is entered. CLOSE transfers control to the next phase. PHASE INPUT/OUTPUT Figure 35 pictures the data input to and output from the Identifier Table Manipulation Phase. The figure also shows the tables transmitted to and from the phase in main storage. Figure 36 shows the space provided (last one-and-one-half bytes) in the typical identifier entry for the relative address of an identifier's storage field in the particular block's or procedure's object time Data Storage Area. The figure is not representative of identifier entries for declared labels and declared procedure and switch identifiers, in which the last 1 1/2 bytes contain a displacement address in the object time Label Address Table, inserted by the Scan 1/11 Phase. o 6 8 9 10 11 r------------T---------T-----T------------, I I I I ____________ Name> L I _________ teristic> I _____ I ____________ JI ~ ~ ~ <--------Inserted by Scan-------> VII Phase r-~~;o:9:--1 II I ~:b~~m ~f:Tc~B~)umber Error Pool I SYSUT2 - Identifier Table (ITA') SYSUT3 Identifier Table (lTAB) I IDENTIFIER TABLE I f----~-tl MANIPUlATION J-1f------t PHASE r--- ----, I Main Storage in the block's or procedure's Data Storage Area> II I L_-T-_J I = I _________________________________________ L lI Figure 37. Two-byte entry in Program Block Table II (PBTAB2) PBTAB2 is constructed by the ALLOSTOR routine. The total storage allocation for a particular block or procedure is stored in the entry corresponding to the particular Program Block Number. CONSTITUENT ROUTINES OF IDENTIFIER TABLE MANIPULATION PHASE The principal constituent routines of the Identifier Table Manipulation Phase are described below. The index in Appendix XI indicates the page on which each routine is described and the flowchart in the Flowchart Section in which the general logic of the routine is set forth. PHASE INITIALIZATION The Initialization routine gets main storage for the private work area shown in Figure 38; initializes pointers and switches; specifies EOD and program interrupt-I/O error routines; calls the PRINT subroutine in the Directory, after assembling headlines for the Identifier Table listing, provided the SOURCE option is specified, and exits to READBLK (which reads in Identifier Table records from the SYSUT3 data set). The program interrupt-I/O error exit, CLOSE2, is stored at ERET, a location in the Common Work Area referenced by the PI ROUT routine in the Directory. The exit is changed, after the GETMAIN instruction, to CLOSE. CLOSE releases main storage and transfers control to Diagnostic Module IEX21, while CLOSE2 simply transfers control to IEX21. The GETMAIN instruction for the private work area is issued after the total area required for the Identifier Table (ITAB) and the Address Table (ATAB) has been computed. The area allotted to the Identifier Table is fetched from the ITAB20S entry in the Area Size Table in the Common Work Area. The area provided for the Address Table is fixed at 1024. SAVEPB, SAVE, and BITS1 are three Common Work Area locations defined by a dummy control section in Load Module IEX20 (ITAE Manipulation). SAVEPB is the name of the Program Block Counter which is incremented by 1 in the Lastrec routine for every Identifier Table record processed. SAVEPE is compared with PBN (the program tlock count transmitted by the Scan 1/11 Phase in the Con:mon Work Area)., and if the count is identical (indicating that all Identifier Table records have been read in from SYSUT3 and processed), control is passed to WRI'IITAB, which outputs the table on SYSUT3. SAVE is a location used (ty the ITABPRNT routine) in converting numerical data, in connection with the print-out of the Identifier Table. BITS1 contains a switch, named PROCEIT. PROCBIT=l (turned on in the ITABPRNT routine on recognition of a procedure identifier) signifies that the Identifier Table entry being processed is that of a procedure identifier, and that the parameter count in the internal name is the actual count and should net te increased ty 1 when the entry is printed out. PROCBIT=O signifies that the Identifier Tatle entry teing processed is that of an array or switch identifier, and that the dimension count or component count in the internal name represents the actual count" less one., and should be increased by 1 when the entry is printed out. I f the SOURCE option is specified., the headlines "IDENTIFIER TABLE" for the first line, "PBN SC PBN NAME TYPE DM DSP NAME TYPE DM DSP NAME TYPE DM DSP" for the second, and "SURR PR LN PR LN PR LN" for the third line, are moved to a field named PAGE HEAD in the Common Work Area. A call is then made (via PRINTITB) to the PRINT subroutine in the Directory, which prints out the headings on a new page.. Resetting to a new page is governed by presetting the line count to 128 (in LINCNT) tefore calling PRINT. If short prec~s~on has been specified (determined by testing the LNG switch in the HCOMPMOD Control Field), the value 4 is stored in the half-word named C, displacing the defined constant 8, and specifying t.c the ALLOSTOR routine that arithmetic identifiers are to be allocated four bytes each. If short prec~s~on has not been specified, C rereains unchanged at 8, and real (or floating point) identifiers will accordingly be assigned eight tytes each. Chapter 5: Identifier Table Manipulation Phase 71 (at initializatian) AITAB Notes: Identifier Table (ITAB) Work Area READBLK Routine ALLOSTOR Routine AlB (reg. 8) AlB (reg. 8) (An ITAB record) RAID (reg.7) -~-AKOM (reg.9) RAID (reg. 9) I I ll _________ _ AI TAB AI TAB 2. In the ALLOSTOR routine, AlB and AI TAB point to the beginning and end of the record. RAID addr.esses successive identifier entries in the record. -----------==== (An ITAB record) REGY (reg. 10) -+---11-- 1. In the READBLK routine AITAB initially addresses the lacation in the Identifier Table Work Area to which the next record is read from SYSUT3. After read-in of the record is cO'IIPlete, AI B is set equot. to AITAB, and AITAB is then incremented by the length of the record (in the heading entty), so that AlB and AITAB now point to the beginn ing and end of the record. RAI D addresses successive identifier entries in the record, maving progressively through the record, while AKOM addresses each of the entries following RAID, with which the identifier addressed by RAID is compared. RAID (reg. 9) AITAB (at initialization!.,.)-If--------------f ATABAD AddreS5 Table (ATAB) (r024) 3. In the ITABPRNT routine, AlB arid AITAB point to the beginn.ing and end of the record currently being processed. For each record processed, AlB and AITAB are set by loading AlB with the address contained in the Address Table entry corresponding to the next sequential Program Block Number, and then setting AITAB = AlB + (the length of the ITAB record addressed by AlB, the length being contained in the heading entry). Identifiers are printed out in alphabetical order, three on each line of printed text. To find the next identifier in alphabetical order, RAID and REGY are initializedat the first identifier entry in the record. REGY then addresses the following identifiers in tum, each identifier being compared with the identifier addressed by RAID. When REGY addresses an identifier of higher alphabetical order than RAID, RAID is reset to REGY. This procedure is repeated until the end of the record is reached, so that RAID now addresses the next identifier in alphabetical order. After the identifier has been processed, it is deleted, by shifting the identifier en tri es at the bottom af the record upward by the entry length. * Area size specified by Area Size Table- in Common Work Area. See Appendix VIII for the variation in area sizes Figure 38. -procedures, for which the area reserved is 32 bytes). Object time storage space is allocated with the aid of a set of displacement pointers named DP (Double Word Pointer). WP (Word Pointer), HP (Half Word Pointer), and BP (Byte Pointer). These pointers are zero-set at the beginning of every Identifier Table record. DP reflects the total displacement at any point in terms of double- words. It is incremented at double and full-word boundaries by 4 or 8 bytes, depending on the precision specified. Where the allocation to be made for an identifier is less th~n a double word, pointer BP, BP, or WP may be set equal to DP and incremented by one, two, or four bytes, so as to minimize the number of unused bytes. See Note 2 in Figure 38. WRITE IDENTIFIER TABLE (WRITITAB) WRITITAB is entered from AllOSTOR when all Identifier Table reccrds have been reao into main storage and processed. After repositioning SYSUT3 by a Type T CLOSE, WRITITAB transfers the Identifier Table records in the work area to the SYSUT3 data set, in ascending Program Block Nurrber sequence.. The address cf the record corresponding to the next sequential Program Block Number (in REGZ) is determined by reference to the Address Table (ATAB) entry for that Program Block Number. Control is passed to the ITABPRNT routine when the Program Block Number in REGZ equals the program block count stored in PBN by the Scan 1/11 Phase. PRINT IDENTIFIER TABLE (ITABPRNT) ITABPRNT generates a listing of the contents of the Identifier Table, containing the external name of each identifier and indicating (by means of a system of coded symbols) the characteristics of the identifier. Output of the listing, whose format is described in the OS ALGOL Programmer's Guide, is dependent on the SOURCE option being specified. The identifier groufs are listed in ascending Program Block Number sequence, and within each group the identifiers are listed in alphabetical order. See note in Figure 38. TERMINATION (CLOSE) CLOSE releases the main storage area occupied by the Identifier Table and the Address Table, and transfers control to Diagnostic Output Module IEX21 (see Chapter 9) • Chapter 5: Identifier Table Manipulation Phase 73 CHAPTER 6: SCAN III PHASE (lEX30) PURPOSE OF THE PHASE The subscript Table is transmitted (on the SYSUT3 data set) to the Subscript Handling Phase" in which optimizable subscript expressicns are identified and copied into the Oftimization Tatle (OPTAB) for transmission to the CORpilation Phase. To be optimizable, no assignment may be made in the for statement to the factor F or the addend A in the subscript expression. The test for oftimizability is performed in the Subscript Handling Phase by comparing the faotor and addend with the variables listed in the Left Variable Table (see next item). The purpose of the Scan III Phase is to read the Modification Level 1 source text output by the Scan 1/11 Phase and to perform the following princifal tasks: 1. To replace the external names of all identifiers in the modified source text by their corresponding internal names in the Identifier Table (see Chapter 4). 2. To store constants in the source text in the Constant Pool, and to replace each constant by a five-byte internal name, referencing the location where the constant is stored. A constant is stored in the Constant Pool in fixed or floating point representation, depending on whether the constant is an integer number or a real number. TXT records of the constants stored in the Constant Pool are generated on the SYSLIN and/or SYSPUNCH data sets, according to the Compiler options specified (see Item 5. To construct the Left Variable Table (LVTAB) , listing" under each for statement" the integer left variables in the iterated fart of the for statement. The Left Variable Table is transmitted (on the SYSOT3 data set) to the subscript Handling Phase. It is used in identifying subscript expressions listed in the Subscript Table which are not optimizable (see preceding item). 6. To generate a transformed sourc~ text (called Modification Level 2). 'Ihe principal change made in this version of the source text consists in the replacement of externally represented identifiers and constants by five-byte internal names (see items 1 and 2). Other changes are set forth under "Modification Level 2 Source Text". 7. To replace the external names of standard mathematical functions and input/outpu~ procedures by five-byte internal designators. The internal designators are stored in the Identifier Table work area by the Initialization routine" before the first record of the Identifier Table is read into main storage from the SYSUT3 data set. 8. To recognize syntactical errors in the source text and to store appropriate error patterns in the Error Pool. The contents of the Error Pool are printed out in the form of diagnostic messages by the Error Message Editing Routine in the immediately following Diagnostic Output Module (IEX31). 9. To generate TXT records of the Constant Pool on the SYSLIN and SYSPONCH data sets, if the LOAD and/or DECK options have been specified. 9) • 3. 4. 74 To construct the For Statement Table (FSTAB), indicating the critical features of every for statement in the source text. The For Statement Table., which is transmitted to the two subsequent phases via main storage, serves to determine the structure of the loop generated in the object code for each for statement. Among other things" the For Statement Table assigns each for statement to one of three loop classifications (Normal Loop, Elementary Loop, or Counting Loop) and indicates the character of the for list (e.g. if the for list contains a step or while element). It also indicates if subscript optimization is to be performed for optimizable array subscripts in a for statement. To construct the subscript Table (SUTAB) listing~ under each for statement, all subscript expressions of a defined character occurring in the iterated part of the for statement. The expression must be of the type ±F*V±A, where V is the contrOlled variable, and the factor F and addend A must be integer variables or constants. ( SCAN III PHASE OPERATIONS The primary Phase are: functions of the Scan III 1. To replace externally represented operands in the Modification Level 1 text by their corresponding internal names in the Identifier Table; 2. To store constants found in the Modification Level 1 text in the Constant Pool and to replace the constants ty internal names; and 3. To detect critical logical features of all for statements and record these in the For Statement Table. A closely related function is to list integer left variables and linear subscripts of arrays in for statements, in the Left Variable and Subscript Tables. The diagram in Figure 39 illustrates the main operations performed in the Scan III Phase (the overall logic of the phase is indicated in Flowcharts 044 and 045 in the Flowchart Section). The following description provides a brief comment on the diagram. The modified source text is scanned, in the first instance, by the GENTEST routine, which branches to approximately 30 other routines, according to the character identified in the source text. Control is in every case returned to GENTEST after the required processing has been completed. Modification Level 1 text records are read from the SYSUT1 data set by the ICBA subroutine, which is called by all routines on detection of the record-end operator Zeta. The Modification Level 2 text records are output on SYSUT2 by the OUCHA subroutine on call from all routines which transfer operators and internal names to the modified text. OPENING AND CLOSE OF BLOCKS AND PROCEDURES At the opening of a block or procedure (indicated by the operators Beta, Pi or Phi), the next sequential Identifier Table record is read into the work area provided. Records are read from the SYSUT3 data set by the ITABMOVE subroutine, on call from BETA or PIPHI. When the end of the current (embracing) block or procedure is reached (indicated by the operator Epsilon), the corresponding Identifier Table record in the work area is deleted by EPSILON. This procedure insures that the Identifier Table work area at all times contains those identifiers which have been validly declared or specified in the current block or procedure, as well as in all enclosing blocks or procedures. The handling of the Identifier Table is described more specifically in a later section. IDENTIFIER HANDLING A letter indicateS the beginning of an externally represented identifier. The LETTER routine scans the following characters, and when the end of the identifier has been found, branches to IDENT. IDENT initiates a comparison (between the identifier in the source text and the external names contained in the entries in the Identifier Table work area)., designed to locate an entry for the same identifier declared or specified in the current (or an enclosing) block or procedure. If no matching identifier is found in the Identifier Table, the identifier in the source text is undefined: an error is recorded in the Error Pool, the Compiler enters Syntax Check Mode (Chapter 9), and, after an all-purpose internal name has been transferred to the Modification Level 2 text, control is returned to GENTEST. If, however, a matching identifier is found in the Identifier Table (indicating that the identifier was duly declared or specified) control is passed to FOLI, which branches to one of four routines (NOCRI. PROFU, SWILA, and CRITI), according to the character of the identifier, indicated by the characteristic in the Identifier Table entry. The main function of the NOCRI. PROFU, SWlLA, and CRITI routines is to determine if the identifier in the source text is contained in an embracing for staterrent (that is, in the for list or in the iterated part of an embracing for statement); and if so, to make entries in the Left Variable and/or critical Identifier Tables; and to classify the embracing for statement(s) in the For Statement Table, according to whether the presence of the particular type of identifier in the for statement affects the logical structure of the code to be generated for the for statement(s) in the Compilation Phase. ~he processing of for statements is discussed in more specific detail in a later secticn. The SWILA routine, entered if the identifier is a label or a switch, serves to verify the validity of a branch. Chapter 6: Scan III Phase 75 ...fk SCANmPHASE (lEX30) ITABNOVE .... .,d.lo ldeolili., T"bl ..... a>rlIl",,,, LETAAf hubro<.oti ... of C~IMtI _..,. NOC~I f--_ _ _-+_---1f--_-=;ond CRITII CRlTlde,.,,,,I" •• if 'ho Id.",m., l,eo""'lnod in Ih. I", 1i,I Or In :~.i:.:~:~6:r~ !,~: ~"'lrCR:j'.g ~~;;o~i':-;I~"~~i~:~h';:!~'1 ~-- r---.,._,. ::":;;.~P:':'::;;jt:g ""ho".. Tobl. 1_ 110.' .. "",' G"", •••,",,,. '"' in ~. " '"'~'''''"''.", '".,_~""'_'""."'~""."'." """"'-I~"" I f~'1 - --",",,,,,'U - ,. . ,."._..-. wth.hoodollhoGroupTablo,ola",I,e. r:;;tof;~~~ ::::::~:(:~!!~:.o;tb::ndificatiorit.,,,,,, n 2 OUCHA .. lehar<><- t~i.~;l~;:~~f~;~ F= !!r'?S~E:~Ci:l:f~i~~~~~:t{~~!;I~~ M>dlflcollon level I Sourcer..1 alor, -tJJ ,"0," .- bracingfor."" ...."I(.) 0) N" .... al Loap(.), Ilafor 11."idontifi.,otho, Ih.", ,ho..,n'rall.d va,Iobl. oc~v"o. variabl. th.for "alemon' (•• g. ". ,hotantrolleclvoriablool o oe.lod lor ,1"le_ ",ont) or;! tho dificalio" ~~!:TW F=FOR ""dOOen.r..y itoh,e- ~========t=========t=================~~=il l .....1I t .. t,anca!l lramoll routln., which d .. ' .. e. COMM/\ ",,<:ICLQBRACK). .. ,oriobt.ofon •• 'ecI for ltolemonl, a,if theoonlraHed, _ _ vo,lobl. occv" in 0 n""-al'timl~al>le ",b,c,ipt .. ",... i"n. ~ =phe F=~::~~a~n~IS~I!;~y'::::::~~o~:;'~::i:o.::r:hlb" =================================",'&=","",=","","",'=0;/ !t~dgC·~~·~Rtcrc."ing 1 F=~~~o:"'Q~bTt,h~~~~~~",,~~~.o~tae~~ra<_ ==",============================r:"~!o~:~d,,,~!:",~~m=Q:~=~~=":ha=-b;=o'C<-=i1 '.x'k>I~e 1 ,.r,,';ng, ImmthelYladifkoHon L.."ol I M>di/ieolio"LoveI2te~'. the F ~e~~f; ,:,;,~,re" lox'.'nal ""me' 01 cod. by QPeRACK, COMMtI opero'or 10 .h& M,dTfi'oHon ================================,,0 toll f"'m INTHAN, REALHAN and OMEGA. OUCHA, "",in ,'o,~e: "rid (XCTl to IEX31) Scan III Phase. Diagram illustrating the functions of the principal constituent routines NOCRI, PROFU, SWlLA, and CRITI all return control to LETTER (directly if the identifier is not contained in a for statement). LE.'TTER thereafter transfers the identifier's five-byte internal name to the Modification Level 2 text, replacing the external name in the Modification Level 1 text, and returns control to GENTEST. The internal name is obtained from the Identi'fier Table entry previously located by IDENT. An overall survey of the identifier-handling routines Can be found in the Flowchart Section with the aid of the Index of Routines in Appendix XI. optimizable, that is, if the expression is a linear expression satisfying certain constraints (defined in a later section). If the sutscript expression is optimizable, the terms of the expression, together with their signs and a serial number identifying the for staterrent, are entered in the Sul::script Table. HANDLING OF OTHER OPERATORS NUMBER HANDLING Constants in the Modification Level 1 text are handled, in the first instance, by the DIGIT19, DIGITO, DECPOIN, and SCAFACT routines. The function of these routines, in the case of real constants (e.g. 457.725 or 0.0095'86), is to represent the constant as the product of a mantissa (with the decimal point immediately to the left of the first significant digit) and a power of ten. Thus the constants in the illustrations above would be represented as 0.457725 x 10 3 and 0.95 x 10 84 • When this transformation is complete, control is passed to the REALCON routine, the mantissa being transmitted in a storage location and the exponent in a register. REALCON converts the constant, represented by the mantissa and exponent, to floating point representation in a register. Thereafter, control is passed to the REAL HAN routine, which stores the constant in the Constant Pool and transfers a five-byte internal name, referencing the constant's storage location, to the Modification Level 2 text. Integer oonstants are handled by the DIGIT19 and/or DIG ITO routines. When the last digit in the constant has been located, control is passed to the INTCON routine. INTCON oonverts the constant to fixed point notation in a register, and exits to INTrlAN, which stores the constant in the Constant Pool and transfers a fivebyte internal name to the Nodification Level 2 text. For a majority of the operators in the Modification Level 1 text, the processing is limited to the transfer of the operator to the Modification Level 2 text (l::y OTHOP). In the case of the operators For and Do, a switch is turned on to indicate, respectively, entry to and exit from a for list, while the appearance of the operators Step, While, Power, or / in a for list is recorded in the appropriate entry of the For Statement Table. The Apostrophe operator indicates that the internal name of a character string or a logical value follows, and in this case the internal name alone is simply transferred to the Modification Level 2 text. PHASE TERMINATION The Scan III Phase is terminated on recognition of the closing operator Omega. The OMEGA routine writes out the last records of the Sul::script and Left Variatle Tables, releases main storage,. and transfers control (XCTL) to Diagnostic Output Module IEX31 (Chapter 9). PHASE INPUT/OUTPUT ARRAY SUBSCRIPT HANDLING Subscript expressions, identified by the operators [, Cmnma and], are handled by the OPBRACK, COMMA, and CLOBRACK routines. If a subscript expression relates to an array in a for statement, an analysis of the subscript expression is initiated to determine if the subscript expression is Figure 40 pictures the data input to and output from the Scan III Phase. The figure also indicates the tables transmitted via main storage. Chapter 6: Scan III Phase 77 ~ r---- Constant Pool TXT records (if LOAD specified) r---------, J I I I I SYSUTI L__ Modification Level 1 Source Text I I Identifier Table (lTAB) I--- I I I I Main Storage Scope Table (SPTAB) Group Tobie (GPTAB) [loAodificotion level I Source Text *] -r_J SCAN III PHASE I I Main Storage SVSUT3 Source Text*] (lVT AB) Subscript Table (SUTAB) I I L _______ -1I I r--- left Variable Tobie , ~ST~B)ement Tobie I ~;::~i~:~tion level - I I r---L--l I SY$UT2 Ncdificotlon level 2 Source Tex' 2 SY$PUNCH Constant Pool TXT records (if DeCK ______ specified) '" Source text transmitted in main storoge if it occupies less thon a full buffer. Figure 40. Scan III Phase input/output The Modification Level 1 source text is input from the SYSUT1 data set, unless the text occupies less than a full buffer. In the latter case the modified source text will have been transmitted from the Scan 1/11 Phase in main storage. Similarly, the Modification Level 2 source text is output on SYSUT2 or transmitted via main storage, depending on whether the text occupies more than or less than a full buffer. Input of the Identifier Table (ITAB) proceeds in parallel with output of the Subscript Table (SUTAB) and the Left Variable Table (LVTAB) on the same data set (SYSUT3). ITAB input is handled by the ITABMOVE subroutine, while SUTAB and LVTAB output is handled by the WRITE subroutine. SUTAB and LVTAB records (fixed length = buffer size) are output in random order, accordingly as the respective buffer is filled, starting at the SYSUT3 data set address immediately following the last ITAB record output by the Scan 1/11 Phase. The data set address is saved at initialization and transmitted to the Subscript Handling Phase in readiness for input of the first SUTAB/LVTAB record. To enable the records to be differentiated in the Subscript Handling phase, each output record contains a leading four-byte key (SUTB in SUTAB records, LVTB in LVTAB records). Before every input and output operation on SYSUT3, a test is made in both the I TAB MOVE and 78 WRITE SUbroutines, to determine if the operation to be performed differs from the last operation (i. e. input of I TAB or output of SUTAB/LVTAB). If the operation to be performed is the same as the last performed operaticn, input/output is initiated directly from or to the current data set position. If, however, the operation to be performed differs from the last performed operation, the data set position of the last transferred record is saved (with the aid of a NOTE macro) in one of the pointers NOTER or NOTEW (see Figure 41); the data set is then repositioned (by a POINT macro) to the address previously saved in NOTER/NOTEW; and input/output is started at the data set address to which SYSUT3 is positioned. NOTER (data set address of next ITAB record to be read) SYSUT3 - --- fo----- NOTEW (data set address for next output operation) Figure 41. -ITAB-- ----SUTAB LVTAB SUTAB Notes: NOTER is updated by the WRITE subroutine when the data set must be repositioned from an ITAB record to the next free record, for output of a SUT AB or LVTAB record. NOTEW is updated by the ITABIvIOVE subroutine when the data set must be repositioned from the end of the last written LVTAB or SUBTAB record, to the beginning of the next ITAB record to be read into main storage. Function of pointers NOTER and NOTEW in input/output operations on the SYSUT3 data set PROCESSING OF THE IDENTIFIER TABLE A descripticn of the entries in the Identifier Table (ITAB) is given in Chapter 4. See also Appendix II. In the Scan III resented operands in replaced by their names constructed in Phase, externally repthe source text are corresponding internal the Identifier Tatle. The processing of the Identifier Tatle is approximately as follows. A new I TAB record is read into a wcrk area from the SYSUT3 data set, as soon as a new block or procedure is encountered in the ~odifica­ tion Level 1 source text. When the end of a block or procedure is reached, the corresponding record in main storage is erased. In this way, the work area at all times contains those identifiers which have been duly declared I IL _________ I _______________________________ JI ~ = Figure 43. 82 Entry in Left Variable Table (LVTAB) CRITICAL IDENTIFIER TABLE (CRIDTAB) The critical Identifier Table provides a temporary record of the critical identifiers in the embracing for statement(s), that is, the nonarray identifiers found in the for list(s) of the embracing for statement(s}. It is used primarily in determining if an identifier in the iterated part of a for statement also occurs as the controlled variable in the for list. It also provides a means of identifying the for statement, in whose for list a critical identifier occurs. The latter function assumes importance in the case of a series of nested for statements, where an assignment is made to a critical identifier which occurs in the for list(s) of one or more enclosing for statements. This condition affects the lcgic of the enclosing for statement(s), and must be reflected in the For Statement Table. o 4 1 7 10 12 11 14 r-----T------------------T---------------r---------------y---T----T------------~ IIII 1 factor> 1 addend> 1 1 1 of left I I I 1 1 1 1 1 cracket in 1 o/p buffer> JI I _____ 1__________________ 1_______________ 1_____________ __i1___ I ____ i1_____________ L ~ ~ ~ Bit 0 1 2 = o = -> = -> (used only in Subscript Handling Phase) = 3 Figure 44. ~ Fourteen-byte subscript Table entry for an optimizable array sucscript expression in a for statement 1 4 5 7 9 r------T-----------------------T------T-----------T-----------, I I l
l
1 critical identifier> i I ______ iI ___________ L1 __________ JI IL ______iI _______________________ = : Bit 0 on = Identifier is controlled variable Bit 1 on CRIDTAB contains a preceding entry for same identifier Bit 1 off = This entry is the first or only entry for the identifier Bit 2 on = CRIDTAE contains a succeeding entry for the same identifier Bit 2 off This entry is the last (or only) entry for the identifier
First or only entry: Second or subsequent entry:
= Any entry except the last: Last or only entry: (Not used) Figure 45. Entry in Critical Identifier Table (CRIDTAB) Chapter 6: Scan III Phase 83 An entry is made in CRIDTAB by the CRIMA subroutine as soon as it is determined that an identifier is contained in a for list. At exit from a for statement, all entries for identifiers in the for list are deleted. If the same identifier occurs in the for lists of a series of nested for statements, each entry for that identifier is flagged to show that there is a preceding and/or succeeding entry for the same identifier. If a for statement is classified a Normal Loop, all CRIDTAB entries for identifiers in the for list are deleted (by the DELCRIV subroutine). In the event of CRIDTAB overflow, the entries for the outermost for statement are deleted (by the CRIFLOW subroutine) • As indicated above, CRIDTAB lists the identifiers in the for list(s) of the embracing for statement(s), each entry indicating, first, if the identifier is the controlled variable, and second" if the identifier occurs in any other embracing for statement(s). As soon as it is detected (by NOCRI) that an identifier occurs in a for list, the Special Use Bits (see Figure 9) in the corresponding Identifier Table (ITAB) entry for the identifier are set to binary 11, to indicate that the identifier is a critical identifier, and an entry is made for the identifier in CRIDTAB. The Special Use Bits remain set to binary 11 until exit from the for statement" or until the for statement is classified a Normal Loop, at which time they are reset to their original value by the CRIFODEL routine. When an operand is encountered in the iterated statement (or in the same for list) whose corresponding ITAB entry shows that the identifier is a critical identifier, control is passed by FOLI to the CRITI routine. CRITI locates the corresponding entry in CRIDTAB, and then proceeds to modify the classification byte (in FSTAB) of the for statement(s) corresponding to each entry for the identifier, according to the particular circumstances surrounding the identifier in the iterated statement and in the for list. These may show, for example, that the identifier occurs as the controlled variable or as some other variable in the for list; that the identifier appears to the left of, or to the right of, an assignment operator in the iterated statement; or that the identifier appears only in a subscript expression. Depending on the circumstances identified, the corresponding for statement's classification byte may be modified to change the loop classification, or to specify that subscript optimization is or is not possible. 84 ARRAY IDENTIFIER STACK (ARIDSTAB) An entry is made in the Array Identifier Stack for an array identifier in a for statement when the opening bracket following the identifier is encountered. The entry is deleted when the bracket which closes the array list is found. In a series of nested arrays {as, for example: (ARRAYl [K, ARRAY2 [L, ARRAY 3 [M, N]] ] ) , an entry is made for each array, as soon as the opening bracket for the particular array is recognized. The stack entries are released as the relevant closing bracket is identified, the last entry for the innermost nested array being released first" the entry for the embracing array being released second., and so cn. o 3 4 5 7 r------------------y-----T------T---------, I, ,
1 I __________________ array identifier>1 _____ , ______ I_________ JI L ~
Figure 46. ~ ~ = = (set to X'OO· if the array does not occur in an embracing array list) = Entry for an array identifier in the Array Identifier Stack (ARIDSTAB) The Array Identifier Stack provides temporary storage for information concerning an array in a for staterrent. The recorded information may subsequently be transferred to one or more entries in the subscript Table, depending on whether the subscript expression(s) in the array list are optirrizable. A subscript expression containing an array is not optimizable., but the subscript expressions of the nested array may be optimizable. MODIFICATION LEVEL 2 SOURCE TEXT The Scan III Phase generates a seccnd transforroation of the source text., called Modification Level 2 (the first transforrration being that of Modification Levell, produced by the Scan I/II Phase). The Modification Level 2 text, which forms the primary input to the Compilation Phase, is transferred to the SYSUT2 data set, unless it occupies less than a full buffer, in which case it is transmitted via Source Text Buffer 1. The principal changes reflected in the Modification Level 2 source text, as compared to Modification Levell, are as follows: 1. 2. 3. 4. 5. All externally represented operand identifiers are replaced by five-byte internal names (Appendix II). The internal names are obtained from the Identifier Table. Undeclared identifiers are replaced by an all-purpose internal name. Constants are replaced by five-byte internal names specifying the type of constant (real or integer) and the field in the Constant Pool where the constant is stored., and the Constant Pool Number. Defective constants are replaced by an all-purpose internal name (Appendix II). The two-byte Identifier Group Number following the operators which mark the opening and closing of blocks, procedures, and for statements in the Modification Level 1 text (see dscope Identification" in Chapter 4) is eliminated in the Modification Level 2 text. The Apostrophe preceding the internal names of character strings and boolean constants is removed, but the internal names are transferred to the Modification Level 2 text unchanged. The operator Rho (inserted by the Scan 1/11 Phase at the beginning of a record when a parameter delimiter extends across a buffer boundary) is removed, together with the preceding letter string. The right parenthesis at the beginning of the letter string is replaced by a Comma. X'80' (set to X'80' ty CRIMA after the controlled variatle in a for statement has been recognized) signifies that a for list fcllowing the controlled variable is being processed. 10 BYTE (Bits 0 thru 3 are named as follows. They are tested and turned on or off in the ITABMOVE, WRITE" and CHECK subroutines). READM=l signifies that the last SYSUT3 operation was a READ. WRlTEM=l signifies that the SYSUT3 operation was a WRITE. last READC=l signifies that the last SYSUT3 operation was a CHECK following a READ. WRlTEC=l signifies that the last SYSUT3 operation was a CHECK follOWing a WRITE. SCATEST (Bits 0 thru 4 are named as follows. They are tested and turned on or off in the DIGIT19, DIGITO" DECPCIN, SCAFACT, and REAL CON routines). SFSIGN=l signifies that the Scale Factor is followed by a +/- sign. SFLO=l signifies that a scale factor exponent contains one or more leading zeros. SF19=1 signifies that a significant digit has been encountered in a scale factor exponent. SF=l signifies that a scale factor has been encountered as part of a real number. PRECERR=l signifies that the precision of a real constant exceeds the machine capacity. STATUS (Bits 0 and 4 are named as follows. They are tested in the OPBRACK,. COMMA" and CLOBRACK routines.) SWITCHES The following switches are used routines of the Scan III Phase. in the ZFORTEST X'OO' (set to X'OO' on detection of operator Do) indicates that the source text-Currently being processed is not part of a for list. X'CO' (set to x'CO' on recognition of operator For) Signifies that a for statement has been entered. SARRAY=l (turned on ty ARRAY on detection of the operator Array) signifies that an array declaration is being process ed,. (turned on by SWITCH on SSWITCH=l detection of the operator SWitch) signifies that a switch declaration is being processed. SARRAY and SSW ITCH are both turned off by SEMIDELT at the close of the declaration. ZCLOBRA X'OO" (set to X" 00" by COMMA and Chapter 6: Scan III Phase 85 OPBRACK on detection of the operators [ or Comma in a subscript expression) signifies that SUSCRITE is to be called. X'FF' (set to X'FF' by CLOBRACK on detection of an array element in a subscript expression) signifies that the rest of the expression cannot te optimized and specifies that SUSCRITE is not to be called. X'OO' The maximum capacity of SUTAB or LVTAB has not yet been reached. X'FF' (set to X'FF' in LETRAF and SUTABENT) signifies that the maximum capacity of LVTAB or SUTAB has been reached" and specifies to SUSCRITE and LETRAF that no more entries are to be made in these tables. CONSTITUENT ROUTINES OF SCAN III PHASE The principal constituent routines of the Scan III Phase are described below. The Index of Routines in Appendix XI provides a guide to the flowchart in the Flowchart Section and to the text in which each routine is outlined. PHASE INITIALIZATION (INITIATE) The Initialization routine acquires main storage for the private work area shown in Figure 47; initializes pointers; issues a SPIE macro to take care of exponent overflow and underflow interrupts; stores a set of 28 standard procedure designators in the Identifier Table (ITAB) work area; reads in the first Modification Level 1 text record from the SYSUTl data set; and exits to the GENTEST routine. TERMl is the address of the routine entered in the event of a program interrupt or input/output error. It is stored at ERET, the location referenced by the Program Interrupt routine (PIROUT) and the I/O Error routines (SYNAD and SYNPR) in the Directory. TERMl is changed to TERM2 after the GETMAIN macro has been issued. 86 A SPIE macro is then issued to provide for special handling of interrupts due to exponent overflow or underflow. By execution of this macro,. the Directory routine PIROUT (the routine specified in the SPIE macro executed in the Initialization Phase) is replaced as the program interrupt exit, by a routine named INTERUPT. INTERUPT determines the type of interrupt involved" and if it is any interrupt other than an exponent overflow, passes control to PIROUT, which then passes control to the entry address TERM2 stored at ERET (see preceding paragraph) • If, however" the interrupt is due to exponent overf low., INTERUPT records Error No. 82" disregards the constant in the Modification Level 1 source text, transfers an all-purpose internal name to the Modification Level 2 text" and passes control to the GENTEST routine. The GETMAIN instruction is issued after the area sizes for all work areas have teen totalled. The area sizes are obtained frorr the Area Size Table in the Common Work Area. After initializing a pointer to Source Text Input Buffer No. 1 in the Common Area., a call is made to the Change Input Buffer subroutine nCHA)., provided the ONEREC switch in the HCOMPMOD Control Field shows that the source text has not teen transmitted from the Scan I/II Phase in main storage. ICHA reads in the first Modification Level 1 text record. A set of 28 eleven-tyte entries containing the external and internal names of all ALGOL standard I/O procedures and mathematical functions., is moved into the Identifier Table area from a tatle named FIXITAB. Appendix III lists the internal names of standard I/O procedures and mathematical functions. After fetching (by means of a NOTE macro) the data set address of the last Identifier Table (ITAB) record on SYSUT3, and saving the address in NCTEW and SULTSTRT., the data set is repositioned to the first ITAB record" and a call is rr.ade to the ITABMOVE subroutine, which reads in the first record. The data set address in NOTEW is referenced by the WRITE subroutine in the present phase; SULTSTRT is referenced in the Subscript Handling Phase., when SUTAB and LVTAB are read into main storage. ZKOPOOL ZWP=Z DWP=ZLlTST A (ZWP) (ZDWP) =,:== I ZKOPEND ZIBSTAO ZCURITEN ZITREC ZITEND ZIN=ZIBREAD (Space reserved for strings stored Phas'!L _ _ _ _ _l!!...S~!L!!. Notes: 1. Source Text Input Buffer No. 1 is located in the Common Area acquired by the Initialization Phase. Its address is obtained from the Common Work Area location SRCEIADD and stored at ZIBRUN. In the ICHA subroutine, input buffers are exchanged by exchanging the contents of ZIBRUN and ZIBREAD and setting ZINR=ZIBRUN, where the latter point to the next record to be processed, while ZIBREAD paints to the alternate buffer into which read-in of the following record has been started. The end of a record is identified by the operator Zeta. 2. In the OUCHA subroutine, source text output buffers are exchanged b~_ exchanging the contents of ZOBWORK and ZOBWRITE and setting ZOUT= ZOBWORK, where the latter paint to the vacant buffer to be filled next, while ZOBWRITE paints to the alternate buffer from which output of a record has been started. Pointers ZFILE1, ZFILE2, •••.• , ZFILE9 point to the end of the current buffer, less 1, 2, ••••• , 9 bytes. In the Constant Pool, ZLiTSTA paints to the next free entry, allowing for strings stored by the Scan 1/11 Phase. The displacement by ZLiTStA from the start.C)f the pool is obtained from the displacement painter . PRPOINT, transmitted from Scan 1/11 in the Common Work Area. Constant Pool (4096) -- ZTEXTCO (Standard Pracedure Designatars) ~ ~-------.- Identifier Table (lTAB)* Source Text Input Buffer No.2 * (ZIN) I- I 3. ZOUT=ZOBWORK Source Text ZFILEI ZFILE2 ZFILE3 ZFILE5 ZFILE6 ZFILE9 Out~t Buffer No.l* ,-t (ZOUT) ZOBWRITE ZWP and ZDWP paint to the next free entry at a word or double word boundary. Source Text Output Buffer No.2 * ZTEXTCO is set equal to ZWP + 56 after a TXT record has been output. A TXT record is output as soon as ZWP >ZTEXTCO. PFA=PFANO 4. In the Identifier Table, ZCURITEN points to the end of the set of IT AB records representing identifiers declared or specified in the embracing blocks and procedures. ZITREC points to the next entry. 5. A four-byte key is stored at the start of SUTAB and LVTAB records. The key permits the Subscript Handling Phase to identify each record read from SYSUT3. Critical Identifier Table (CRIDTAB)* (PFA) 0-- I ZSUTA PO=ZSUDAD SUSTRT ---iii (ZSUTAPO) SUTB I Subscri pt Tabl e (SUT AB) * T" ZLEVA=ZLESTA=LVSTRT lvrs Left Variable Table (LVTAB)* (ZLEVA) ,f ZLEMAX * Area size specified by Area Size Table in Common Work Area. See Appendix VIII for the variation in area sizes as a function of the SIZE option. Figure 47. Private Area acquired by Scan III Phase Chapter 6: Scan III Phase 87 GENERAL TEST (GENTEST) Character GENTEST scans the Modification Level 1 text in the current input buffer by means of a Translate and Test instruction, and branches to one of 26 routines" according to the function byte assigned the particular character in Translation Table GENER. The fUnction bytes assigned by GENER to the character set and the routines entered from GENTEST are as follows: Character Function Byte Routine Entered 04 08 OC 10 14 18 1C 20 24 28 2C 30 34 38 3C 40 44 48 4C 50 54 LETTER DIGIT19 DIG ITO DECPOIN SCAFACT QUOTE BETA PIPHI FOR EPSILON ETA DO WHILE SEMIDELT OPBRACK COMMA CLOBRACK ZETA GAMMA OMEGA OTHOP Decimal Point Scale Factor Apostro~he Beta Pi, Phi For EPSilon Eta Do While semIColon, Delta [ Comma ] Zeta Gamma Omega +, -, *, + , (, ), <, >, S, 2:, =, *, Assign, llot, Impl, or, And, lliIuiv, Label Colon, Begin, Goto, ~, If, Then, Else, End, Power Rho ---- --- ----- 58 Step 5C Array 60 Switch 64 Power,/ 68 RHO STEP ARRAY SWITCH DIPOW IDENTIFIER TEST (LETTER) See Function Byte 00 Zeta Rho D€ciIl1al Peint Scale Factor, Apostrophe 04 08 Oc 10 Routine Entered (No branch scanning continues) ZETALET RHO ERROR 1 !DENT Entry to IDENT signifies that an identifier in a valid context has teen encountered. IDENT searches the Identifier Tatle for the corresponding entry, and when the entry is found, passes control to FOLI (see below). Contrel is sutsequently returned to LETTER1, which transfers the internal name of the identifier to the Modification Level 2 text, replacing the external naIl1e in the Modification Level 1 text. ZETALET exchanges source text buffers, by call to the ICHA subroutine, and returns contrel to LETTER. ERROR1 branches to INCOROP, which reeords Error No. 80, transfers an allpurpose internal name to the output text and switches the Compiler to Syntax Check Mode before returning control to GENTEST. ITAB SEARCH (IDENT) IDENT moves up to six characters of the identifier in the source text to a field named ZIDEX, and then cOIl1pares the identifier with the external names listed in the Identifier Table. When a matching entry is found, control is passed to the Identifier Classification Routine (FOLI). If an identical external name is not found, the identifier in the source text is undeclared: Error No. 81 is recorded, Syntax Check Mode is entered, and an all-purpose internal name at ZALLPU is addressed. Central is then returned to LETTER (via LETTER1) which transfers the internal name to the output buffer, and returns control to GENTEST. "Identifier Handling" in this chapter. IDENTIFIER CLASSIFICATION (FeLl) LETTER, which is entered from GENTEST on recognition of a letter, scans the source text to the next nonletter, nondigit character, and branches to one of four routines, according to the fUnction byte assigned by Translation Table IDENTI. The function bytes aSSigned to the character set and the routines entered from LETTER are as follows: 88 FOLI inspects the internal name located by IDENT in the Identifier Tatle, corresponding to the identifier in the source text, and branches to one of four routines, according to the class of identifier designated by the Special Use Bits in the characteristic (Figure 9): Special Use Bits Identifier Class Program Entered PROCEDURE/PARAMETER (PROFU) PROFU is entered when the FOLI routine has detected a procedure identifier or a formal parameter. PROFU erases all entries (if any) in the Array Identifier Stack in the event the procedure identifier or formal parameter occurs in an array list; and, if the procedure or formal parameter occurs in a for statement (indicated ty entries in the Critical Identifier Table), calls the DELCRIV subroutine, which classifies the embracing for statement(s) Normal Loops and erases CRIDTAB. Control is returned to the LETTER1 routine, which transfers the internal name of the identifier to the output text. 00 Declared simple variable or array identifier NOCRI 01 Procedure identifier or formal parameter PROFU 10 Label or switch identifier SWILA 11 Critical Identifier (the identifier occurs in the for list of the embracing for statement) CRITI Only the first three classes are represented in the Identifier Table as constructed in the Scan 1/11 and Identifier Table Manipulation Phases. A declared real, integer, or boolean simple variable is classed a critical identifier (the fOUrth class) as soon as it is detected in a for list. In practical terms, this means that the Special Use Bits of the corresponding entry in the Identifier Table are set to binary 11 and that an entry for the identifier is made in the Critical Identifier Table. At exit from the for statement, all identifiers in the for list are restored to the noncritical class by resetting the Special Use Bits of the corresponding Identifier Table entries to 00, and the entries in the Critical Identifier Table for those identifiers are deleted. SWILA is entered when the FOLI routine has identified a switch or label identifier. The function of SWILA is to determine whether the label or switch implies a branch out of the current scope. If so, it is determined (by reference to the Group Table) if the branch is into a scope enclosing the current scope, or into a scope enclosed by the current scope. In the first case, the jump is valid, tut if the current scope is a for statement, its optimization is affected, and the corresponding for statement's classification byte is modified. NONCRITICAL IDENTIFIER (NOCRI) In the second oase, the tranch is invalid, as it is into a for statement, and an error is recorded. In every case, control is returned to the LETTERl routine. NOCRI determines whether the identifier encountered in the source text occurs in a for list, in the iterated part of a for statement, or outside a for statement. If the identifier occurs in a for list (indicated by ZFORTEST* X'QO'), a call is made to the CRlMA subroutine, which sets the Special Use Bits of the corresponding Identifier Table entry to 11, classifying it a critical identifier, and makes an entry for the identifier in the critical Identifier Table. If the identifier occurs in the iterated part of a for statement and if it occurs as an integer left variable, a call is made to the LETRAF subroutine, which makes an entry in the Left Variable Table. If the identifier occurs outside a for statement, control is returned to the LETTER routine, which transfers the internal name in the corresponding Identifier Table entry to the output text, replacing the external name in the Modification Level 1 text. SWITCH/LABEL (SWlLA) CRITICAL IDENTIFIER (CRITI) CRITI is entered when the FOLI routine has identified an operand that is a critical identifier, i.e. the SOUrce identifier occurs in the for list of an embracing for statement. (An entry for the identifier will have been previously made in the Critical Identifier Tatle). The action taken depends on whether the operand occurs in a for list or nct (indicated ty the switch ZFORTEST). Identifier in For List: A branch is made to the CRlMA subroutine which constructs an entry for the identifier in the Critical Identier Tabl e. CRITI then searches the Critical Identifier Table for the previous entry for the Chapter 6: Scan III Phase 89 identifier. When the earlier entry has been found, the two entries are chained together, the flag byte in each entry being set so as to indicate respectively that the entry is preceded or followed by another entry for the same operand, and the relative address of the preceding or following entry being stored in byte 5 and 6 or byte 7 and 8 (see Figure 45). indicates that the identifier occurs in the for list as the contrclled variable, the classification byte of the corresponding for statement is modified to show that subscript optimization is not possible. If the identifier is a left variable and occurs in the for list as an operand other than the controlled variable, the for statement is classified a Normal Loop. Tests are now made of the appropriate bit in the flag-byte of the two entries to determine whether or not the identifier constitutes the controlled variable in the respective for statements. The action taken for the various alternatives is as follows: If the identifier in the source text is not a left variable but occurs in the for list as the controlled variable, the current for statement is classified an EleRentary Loop. No entry is made in the For Statement Table if the identifier occurs in the for list as an operand other than the controlled variable. If the identifier occurs as the controlled variable in the current for statement as well as an enclosing for statement, the classification byte in the For statement Table for the enclosing for statement is modified to show that subscript optimization is not possible. If the identifier in the current for statement is the controlled variable, but in the enclosing for statement is not the controlled variable, the enclosing for statement is classified a Normal Loop. If the identifier occurs twice in the current for list (once as the controlled variable), the current for statement is classified a Normal Loop. A test is now made to determine if the preceding entry in the Critical Identifier Table is chained to another preceding entry. If it is, the for statement referenced by that entry is classified in the For statement Table in the manner described above, according to the position of the identifier in the current for statement and in the enclosing for statement. Identifier Not in For List: If the Array Identifier Stack contains any entries, indicating that the identifier occurs in a subscript expression, control is returned immediately to GENTEST. If, however, the Array Identifier Stack is empty (indicated by ZARSPO = ZARNO), the processing continues as follows: A search is made in the Critical Identifier Table for the entry corresponding to the identifier in the source text (the search is made by comparing the contents of bytes 1, 2, and 3 in the Critical Identifier Table entries with the contents of bytes 8, 9, and 10 of the Identifier Table entry previously located by IDENT). If the identifier in the source text is a left variable (followed by :=), and if the entry in the Critical Identifier Table 90 After the action described above, ccntrol is returned to the LETTER routine, Which transfers the identifier's internal name in the Identifier Table to the ~odi­ fication Level 2 text. MAKE CRIDTAB ENTRY (CRIMA) CRIMA is entered when the NOCRI or CRITI routine has determined that an identifier occurs in a for list. Provided the identifier is not an array, CRIMA makes an entry in the critical Identifier Table, indicating if the identifier is the controlled variable or not; classifies the for statement a Counting or Elementary Loop, depending on whether the identifier is an integer or not; and changes the Special Use Bits of the corresponding Identifier Table entry to mark the identifier a critical identifier. If the for statement is enclosed by another for statement~ and the identifier is a controlled integer variable, a call is made to the LETRAF subroutine, which makes an entry for the identifier in the Left Variable Table. If the identifier is an array, the for statement is classified a Normal Loop and a call is made to the CRIFODEL subroutine, which erases all entries in the Critical Identifier Table for identifiers in the for list of the for statement. CRIDTAB OVERFLOW (CRIFLOW) CRIFLOW is called by the CRlMA subroutine in the event of overflow of the Critical Identifier Table (CRIDTAB). CRIFLOW deletes all CRIDTAB entries for the outermost enclosing for statement and classifies that for statement a Normal Loop. ERASE CRIDTAB (DELCRIV) Function ~ Character DELCRIV is called by the PROFU routine, when it is determined that a procedure or a formal parameter occurs in a for statement. DELCRIV erases all entries in the Critical Identifier Table, representing identifiers in the for list(s) of the embracing for statement(s); resets the special Use Bits of the corresponding Identifier Table entries (to indicate they are no longer critical); and reclassifies the embracing for statement(s) Normal Loops. Decimal Point Scale Factor Apostrophe Zeta ~o Routine Entered 04 08 OC DECPTM SCAFACTM QTCRLT 10 14 18 00 ZETAM BHC OTHER (No branchscanning continues) Before scanning is initiated, registers are set to specify the address and length of a 19-byte field named NUMBER to which the digits of a constant are subsequently moved. UPDATE CRIDTAB (CRIFODEL) CRIFODEL is called by the ETA routine and by the CRIMA subroutine when an array has been encountered in a for statement. CRIFODEL deletes the entries in the CritiIdentifier Table for identifiers in the for list. . MAKE LVTAB ENTRY (LETRAF) DECPTM is entered when the Decimal Point in a real constant (e.g. 640.325) is encountered. DECPTM moves the significant integer digits (640 in the example) to the 19-byte field named NUMBEB, computes the number of digits moved in REXCOBR (register 7), and branches to DECPOIN (see below). The digit count in BEXCORR is treated as the exponent of a power-of-ten correction factor which must be applied to the constant, regarded as a mantissa, with the Decimal Point shifted to the left of the high order digit. Thus, the constant 640.325 is treated as the ~roduct .640325 x 10 3 • LETRAF is called by NOCRI when a left variable is encountered in the iterated part of a for statement, and by CRIMA when a controlled variable is identified and it is determined that the current for statement is enclosed by another for statement. LETRAF makes one entry in the Left Variable Table (LVTAB) for the left variable, for every for statement which embraces the left variable. If the LVTAB work area is filled, the WRITE subroutine is called. SCAFACTM is entered when the Scale Factor in a constant (e.g. 28"45) is encountered. SCAFACTM moves the significant digits preceding the Scale Factor to the 19-byte field named NUMBER, computes the number of digits moved (in REXCORR), and branches to SCAFACT (see below). The digit count in BEXCORR is treated as the exponent of a power-of-ten correction factor which must be applied to the mantissa in which the implied decimal point has been shifted to the left of the high-order digit. The digit count is subsequently added (by SCAFACT) to the exponent following the Scale Factor. NONZERO DIGIT (DIGIT19) QTORLT is entered if a constant contains an invalid character or if a constant occurs in an invalid context. QTORLT exits to INCOROP, which records Error No. 80, transfers an all-purpose internal name, and returns to GENTEST after switching to Syntax Check Mode. ZETAM exchanges input buffers (after moving the preceding digits to NUMBER and computing the digit count in REXCORR) and returns to DIGIT19. which then scans the remainder of the constant in the new buffer. See "Number Handling n in this chapter. DIGIT19 is entered from GENTEST on detection of any nonzero digit in the Modification Level 1 text, and from DIGITO on recognition of a nonzero digit following a zero. DIGIT19 scans the source· text to the next nondigit character, using Translation Table DIG19, and branches to one of six routines according to the assigned function byte. The function bytes assigned to the character set and the routines entered from DIGIT19 are as follows: RHO returns control directly to GENTEST, disregarding the preceding digit(s). The operator ~o signifies, in this particular Chapter 6: Scan III Phase 91 context, that the preceding digit(s) form(s} part of an invalid identifier that is to be disregarded. DECIMAL POINT (DECPOIN) DECPOIN is entered ZERO DIGIT (DIGITO) DIGITO is entered from GENTEST when a lone zero or a nonsignificant zero at the beginning of a constant is encountered in the Modification Level 1 text. DIGITO Scans the source text to the next nonzero character, using Translation Table DIGO and branches to one of seven routines, according to the assigned function byte. The function bytes assigned to the character set and the routines entered from DIGITO are as follows: Character Function Byte Apostro12he Decimal Point Scale Factor Zeta Rho Routine Entered 04 08 DIG191 QTORLT OC 10 14 18 1C 00 DECPOIN1 SCAO ZETAO RHO OTHOPO (No branchscanning continues) Before scanning is initiated, registers are set to specify the address and length of a 19-byte field named NUMBER to which the nonzero digits following the zeroes) are subsequently moved. DIG191 (an entry point of the DIGIT19 routine) is entered when a nonzero digit is encountered in a constant (e.g.064) beginning with zero. DECPOIN1 (an entry point of the DECPOIN routine) is entered when a Decimal Point is encountered in a real constant (e.g. 0.325). SCAO is entered when the Scale Factor is encountered immediately following a zero (e.g. 0'45). SCAO loads the value zero (the equivalent value of a constant of this type) and exits to the SCAFACT routine. OTHOPO is entered when the integer zero is identified. afHOPO transfers a fivebyte internal name, referencing a location in Constant Pool No. 0 where the constant zero is stored, to the Modification Level 2 text and returns control to GENTEST. QTORLT and RHO perform the same functions as those described under the DIGIT19 routine. ZETAO exchanges input buffers and returns control to DIGITO. 92 1. From GENTEST on recognition of the Decimal Point at the begining of a real constant (e.g. .325). 2. From DIGITO on recognition of the Decimal Point following a zero (e.g. 0.325). 3. From DIGIT19 on recognition of the Decimal Point in a real constant (e.g. 640.325 or 1.325'45). In this case, the integer digits will have teen moved, before entry to DECPOIN. to a 19-byte field named NU~BER, and register REXCORR will contain the exponent of a power-of-ten correction factor to be applied to the constant. regarded as a mantissa with the decimal point shifted to the left of the high order digit. DECPOIN scans the source text to the next character other than a 1-9 digit. using Translation Table DECPO, and branches to one of five routines, according to the assigned function byte. The function bytes assigned to the character set and the routines entered are as follows: Character , Decimal Point or ApostroEhe Scale Factor Zeta Function Byte Routine Entered 04 08 DECPO QTORLTP OC 10 14 00 DECPSCA DECPZETA DECPOT (No branchscanning continues) Before scanning is initiated. registers are set to specify the address and length of a 19-byte field named NUMBER, to which the digits following the Decimal Point are subsequently moved. DECPO is entered when any zero following the Decimal Point is encountered. Provided the zero is not preceded by a significant digit (as in 0.0325). DECPO decrements REXCORR (register 7) for each zero following the Decimal Point, and returns to DECPOIN. If the zero is preceded by a significant digit (as in 6.0325 or 0.3025). REXCORR is not decremented. The resulting count, if any, in REXCORR is treated as the (negative) exponent of a power-of-ten correction factor to be applied to the constant, regarded as a mantissa with the decimal point shifted immediately to the left of the first nonzero digit. Thus, for example, the constant 0.0325 is regarded as the product 0.325 * 10- 1 DECPSCA is entered when the Scale Factor is encountered in a real constant (e.g. 1.325'+45 or 0.0125'-45). DECPSCA moves the decimal digits preceding the Scale Factor to the 19-byte field NUMBER, adjoining the integer digits (if any) previously moved by DIGIT19, and passes control to SCAFACT. DECPOT is entered when the end of a decimal constant (e.g. 1.25) is identified. Provided the constant is not zero, DECPOT passes control to the REAL CON routine. If the constant is equivalent to zero, register XFLOAT is loaded with the value zero, and control is passed to REALHAN. QTORLTP and DECPZETA perform essentially the same functions as QTORLT and ZETAM in the DIGIT19 routine. SCALE FACTOR (SCAFACT) SCAFACT is entered: 1. from GENT EST on recognition of the Scale Factor in a constant having no , 45) ; mantissa (e.g. 2. from DIGITO on recognition of the Scale Factor following a zero mantissa (e.g., 0'45); 3. from DIGIT19 on recognition of the Scale Factor following an integer mantissa (e.g. 28'45); and 4. from DECPOIN on recognition of the Scale Factor following a decimal mantissa (e.g. 1.325'+45). Character Function Byte Routine Entered 04 08 OC 10 SCA19 SCAZERO SCASIGN SCAQL 14 18 SCAZETA SCAOT + or , Decimal Point, Scale Factor or AEostroEhe Zeta SCA19, SCAZERO, and SCASIGN each set a switch (named SF19, SFLO, and SFSIGN, respectively) to indicate the detection in the exponent following the Scale Factor of (a) a nonzero digit,(b) a leading zero, or (c) a leading +/- sign. These s~itches are inspected in SCASIGN to determine if a +/sign marks the beginning or end of the exponent, and in SCAOT to determine if the exponent is syntactically correct. If a +/- sign precedes the exponent (indicated if none of the switches have been turned on), SCASIGN stores the sign for use ~hen the exponent is converted to tinary (in SCAOT). SCAOT in entered when the end of a floating point constant (e.g. 28' 45 or 1.325'+45) has been identified. SCAO'!' moves the digits of the exponent following the Scale Factor to a nine-byte field named SCAWORK; converts the exponent (together with the previously saved exponent sign) to binary form, and adds the resultant to the exponent of the power-of-ten correction factor (if any) in REXCORR. This action has the effect of transforming a floating point constant to a standard format, ccnsisting of a fractional mantissa, with the decimal point shifted to the left of the high-order nonzero digit, and an integer exponent.. where the mantissa is stored at the 19-byte field NUMBER and the exponent is contained in REXCORR. SCAQL and SCAZETA perform essentially the same functions as QTCRLT and ZETAM in the DIGIT19 routine. INTEGER CONVERSION (INTCON) In both cases (3) and (4), the significant digits of the mantissa will have been moved, before entry to SCAFACT, to a 19-byte field named NUMBER, and register REXCORR will contain the exponent of a power-of-ten correction factor to be applied to the mantissa, in which the decimal point (expicit or implied) has been shifted to the left of the high-order nonzero digit. SCAFACT scans the source text, using a Translate and Test instruction, and branches to a routine determined by the assigned function byte. The function bytes assigned to the character set and the routines entered are as follows: INTCON converts an integer constant to binary form (in register RBIN) and passes control to INTHAN. which stores the constant in the Constant Pool and transfers a five-byte internal name representing the constant, to the Modification Level 2 text. If a constant exceeds ten digits. Error No. 83 is recorded, the constant is moved to the 19-byte field NUMBER, and control is passed to REALCON. INTCON is entered from DIGIT19, the limits of the constant in the source text being specified by two pointers, its length being contained in register REXCORR. Chapter 6: Scan III Phase 93 REAL CONVERSION (REALCON) REALCON converts a real constant to floating point form (in floating point register XFLOAT) and passes control to REALHAN, which stores the constant in the Constant Pool and transfers a five-byte internal name respresenting the constant to the Modification Level 2 text. REALCON is entered 1. From DECPOIN when the end of a decimal constant (e.g. 32.125) haS been identified; 2. From SCAFACT when the end of a floating point constant (e.g. 1.25'47) has been identified; and 3. From INTCON when an integer constant exceeds ten decimal digits or the maximum range of a fixed point constant. At entry to REALCON, the constant to be converted will have been transformed to the standard format of a decimal matissa, with the implied decimal point to the left of the high order digit, and an integer exponent (the constant being equal to: Mantissa *10**Exponent). The mantissa is stored in decimal form in a 19-byte field named NUMBER, while the exponent, in binary form, is contained in REXCORR (register 7). The conversion to proceeds as follows: 1. 2. 94 floating point form The mantissa is tranformed to an integer mantissa, the implied decimal point being shifted to the right of the lowest order digit, by subtracting the number of digits in the mantissa from the exponent in REXCORR. The mantissa is converted to binary and stored in the second four bytes of an eight-byte field named ZFLOFIEL containing the power-of-sixteen characteristic of 78 (X'4E') in the highorder byte. The contents of ZFLOFIEL are then loaded (normalized) in floating point register XFLOAT. The characteristic of 78 (equivalent in excess-64 notation to a power-ofsixteen exponent of 14) is the exponent required to compensate for an implied 14-place leftward shift of the radix point, i.e., from a position to the right of the low-order mantissa digit (see item 1). The characteristic is reduced, when the mantissa is normalized in XFLOAT, by the number of hexadecimal places the high order digit is shifted left. 3. The mantissa in XFLOAT i~ multiplied by the hexadecimal equivalent of the power-of-ten exponent in REXCORR. 'Ihe hexadecimal equivalent is obtained from one of two power-of-ten tatles named ZEXTABP and ZEXTABN, the forner for positive powers of ten, the latter for negative powers of ten. Each table contains fifteen entries, the first seven for exponents in the range ±1 to ±7, the last eight for the exponents ±8, ±16, ±24, and so On up to ±64. Multiplication of the mantissa is carried out in one or more steps, depending on whether the particular power-of-ten is exactly represented in the table. Thus, for example, if the power-of-ten is 12 (decimal) the mantissa is multiplied first by the equivalent of 10 4 and secondly by the equivalent of lOB. INTEGER HANDLING (INTHAN) INTHAN stores a fixed point constant (contained in register RBIN) in the next free entry of the Constant Pool, and transfers a five-byte internal name to the output text, referencing the location where the constant is stored. If the constant is in the range 0 to 15 inclusive, the internal name references the relevant constant previously stored in the Constant Pool in the Scan I/II Phase. INTHAN is entered from INTCON and from REALHAN if short precision is specified for real constants. REAL HANDLING (REALHAN) REALHAN stores a floating point constant (transmitted in floating point register XFLOAT) in the next free entry of the Constant Pool and transfers a five-tyte internal name, referencing the location where the constant is stored, to the Modification Level 2 text. If short precision is specified, the constant in XFLOAT is transferred to fixed point register RBIN and the INTHAN routine is entered. After the constant has been stored in the Constant Pool, control is returned to GENTEST. REALHAN is entered from REALCON. CHANGE CONSTANT POOL (CPOLEX) CPO LEX is called by INTHAN and REAIHAN in the event the Constant Pool is filled. CPOLEX generates TXT records for the last constants in the Pool" assigns a new Constant Pool number, and resets pointers to the beginning of the Pool area. OUTPUT TXT RECORD (TXTTRAF) TXTTRAF is called by INTHAN and REALHAN when the end of a 56-byte record in the Constant Pool has been reached. TXTTRAF updates Constant Pool pointers and calls the GENTXT subroutine, if the LOAD and/or DECK options are specified. GENTXT generates TXT records of the Constant Pool and outputs the records on SYSLIN and/or SYSPUNCH. GENERATE (GENTXT) READ ITAB RECORD (ITABMOVE) ITABMOVE reads the next Identifier Table record from the SYSUT3 data set into the work area (see Figure 42) and resets a pointer, ZCURITEN, to the end of the previously input record reprsenting identifiers declared or specified in the newly entered block or procedure. It is called by BETA and PIPHI on recognition of the operators Beta, Pi, or Phi, opening a new block or procedure. See "Processing of the Identifier Table". Identifier Table (ITAB) records are input from sYSUT3 in parallel with the output of Subscript Table (SUTAB) and Left Variable Table (LVTAB) records on the same data set. For this reason" the data set must be repositioned to the appropriate ITAB record, before reading can begin, in the event the immediately preceding operation involved output of a SUTAB or LV~AB record. See "Phase Input/Output". See Chapter 8. FOR STATEMENT (FOR) APOSTROPHE (QUOTE) QUOTE transfers the five-byte internal name which follows the Apostrophe, to the output buffer. The internal name references a location in the Constant Pool where a string or logical value was stored in the Scan 1/11 Phase. FOR sets the switch ZFORTEST=X·CO". to indicate that the next operand is the controlled variable, and transfers the operator K2!. PROGRAM BLoCK END (EPSILON' The operator Epsilon marks the close of a block or procedure. BLOCK BEGIN (BETA) The operator Beta opens a new block. in the source text BETA calls the ITABMOVE subroutine, which reads in the next Identifier Table record; and transfers Beta and the following Program Block Number to the output text. EPSILON resets a pointer in the Identifier Table work area so as to delete the block of identifier entries representing identifiers declared or specified in the block or procedure closed by Epsilon. See "processing of the Identifier Table" in this chapter. Epsilon and the following Program Block Number of the re-entered block are transferred to the output text. FOR STATEMENT END (ETA) PROCEDURE DECLARATION (PIPHI) The operator Eta in the input text marks the close of a for statement. The operator Pi opens a declared procedure, while Phi opens a declared procedure. PIPHI calls the IT ABMOVE subroutine, which reads in the next Identifier Table record, and transfers Pi (or Phi> to the output text. ETA sets the switch ZFORTEST=X' 00'. to indicate the exit from a for statereent" and calls the CRIFODEL subroutine, which deletes all entries in the critical Identifier Table for the indentifiers in the closed for statement's for list. Eta is then transferred. --Chapter 6: Scan III Phase 95 00 (DO) Do sets the switch ZFORTEST = X'OO', to indicate exit from a for list, and transfers the operator Do. WHILE (WHILE) WHILE modifies the current for statement's classification byte in the For statement Table (FSTAB) to indicate the presence of a while element in the list, and transfers the operator While to the output text. possible, COMMA calls the SUSCRITE sutroutine., which makes an entry in the SubscriFt Table (SUTAB) for the sutscript expression preceding the Comma, Frovided the subscript expression is optimizable (see "Optimizable Subscript Expression"). If subscript oFtimization is not possitle, a call is made to SUCRIDEL, which scans the subscript eXfres sian to determine if it contains a controlled variable, and, if so, reclassifies the corresponding for statement(s) to Elementary Loops. CLOSING BRACKET (CLOBRACK) an The closing bracket, 1, marks the end of array list, if the SARRAY Switch is on. SE1UCOLON/DELTA (SEMIDELT) or SEMIDELT transfers the Semicolon Delta operator, together with the following semicolon count, to the outFut text, after recording the semicolon count. OPENING BRACKET (OPBRACK) The opening bracket, [, marks the beginning of an array list, if the SARRAY switch is on. If the array oocurs in a for statement I I of [ in I I I lfactor> tuffer> L ________________ laddend> ________________ 4I _____ I _____ lo/p ________________ JI ~ ~ ~ ~ ~ = Bit 0 Bit 1 Bit 2-3 = (Chain Bits:* Binary 10 or 00 Compilation Phase) = Bits 4-7 not used in *The use of the Chain Bits in the Sutscript Handling Phase is discussed under the "Scan SUTAB" and "Construct OPTAB" routines. Figure 50. Optimization Table (OPTAB) entry Private Area':' during Subscript Table Sarting TSTART ZST AD=TST ART+4 Subscript Table (SUTAB (Unsorted) TSTART ZSTAD=TSTA RT +4 Private Area" during Left Variable Table Sorting r- Left Variable Table (LVTAB) (Unsorted) RPO (reg. 10 RPO (reg. 10) f" ZLEVEN = length ZSUTEN = length REND (reg. 9) =ZSORTSTA =ZLESTA WORKX (reg.3) RSUDEN =REND (reg. 9) • +-, I ZOTAWRI ZOTA FILL &QTPO (reg.B) ZOT/lMX (Unused) WORKX (reg.3) ZSUDAD Table PTAB ) (A) X'CO 31' (C) X'CO 31' < DISP-C> I I ---1--------1 (C) 1L (Other opera ds) " ______ --'I r------, I OPDK I (B) I--------J X'CO 31' I I (A in RE GX) X'90 31' (A) I 1 (C) X'CO 31' (B) 1 1 1-------1 -E I(Other ..... - - - - - - - / OPTK L + REGX ,(CDSA) tPRPOINT (Other operands) 1-------., I 'O"":'O")1 (C) 1 P ---I-_____ I ~ (X) L I ______ ..lI I r-----...,1 I OPTK OPDK I-------~ 1 I (A) 1 1 ~I 1-------1 I--________-L____~________~ A REGX,(CDSA) (Other I [j t PRPOINT I--------l (Bil' 1-------1 P £!J..------~ (XI"L _____ - l r------, 1 1 t-------1 1 I 1-------1 OPTK l(Other I loperators) I OPDK "I ST REGX, (CDSA), PRPOINT (Other operands) (Alii 1------ --I P (B) I - ____ ----/1 -'='-I(C) L I _____ --'1 Nates: 2. Painters OPDK (reg. 9) and OPTK (reg. 10) point to the last entry in the Operand and Operator Stacks. DISP-X Displacement of Register X's reserved storage field in the object time Data Storage Area. Displacement pointer P (reg. 7) indicates the displacement of the last reserved storage field in the abject lime Data Storage Area (DSA) of the current block or procedure. Whenever a change in scope occurs, the PBNHDL subroutine stores the contents ofP, representing the DSA displacement for the last block or procedure, in a corresponding entry of PBTAB2, and loads P with the DSA displacement for the newly entered (or reentered) block or procedure, contained in the corresponding entry of PBTAB2. X Number of the object time register containing the intermediate value. The register may be any oneaf the registers available for general computational use (see "Control of Object Time Registers"). P is incremented whenever additional storage bytes are reserved in a Datu ~b~~e~rti;' '9~c~~~~~t~~t,er:ei~i~h: ill~s~r~~i~~~riTc~d: ;se~~::b:e;7ntly b! generated to store on intermediate value (address) in the reserved sh>roge fi eM. If, however, code is actually generated to store the intermediate value (address), the displacement in P is stored (by the MAXCH subroutine) in a corresponding entry of PBTAB3, thus recording the minimum length required (up to that particular point) for the particular Data Storage Area at object time. 3. ~h;;P;:~;:bi::,';:~: ;~:;,;;;~:" (~~',;. 6~.;;:i~,~';: :::~i;~lr~:m;;; :;o~(~~' ~!"_ ::~~e~~o~f ~~deO isPgR:~~~~di~ ~:;h:e:o~p;~:r ;r~r~~~~h~~r:~~~hei:f;RPOINt is used as a relative address in specifying branch addresses (as well as addresses of declared labels) in the object module. In such cases, the displacement in PRPOINT is stored in the appropriate entries of the Label Address Table. At linkage edit time, the relative addresses in the Lobel Address Table are converted to absolute addresses. 4. The abbreviations in the Operand Stock entries have the following significance. PBN DISP-A DISP-B DISP-C Program Black Number of the block or procedure in which the identifier is declared or specified. Displacement of the identifier's assigned stort"ge field in the object time Data Storage Area. Figure 54. 112 Concerning the characteristic in the first twa bytes of the stock operand, see the accompanying lext. Compare alsa with Appendix II. 5. The notation in the illustrated object code has the following significance. REGX The name of the object time register whose number (X) is ~~:t~:nth! ir:~~s~e~~~a~ra~;tr T9~n:~~iS~';;mr;ra~i::~ruse (see "Control of Obje'c;t Time Registers"). DISP-A DISP-B DISP-C inh~h:i~~f~:t~~~e °6:~: ~~·r~~~i~;~:~s~~:~i:~I:~~~~in~l~s obroined from the relevant stack operand. CDSA The nome of base register 10, containing the address of the current Data Storage Area, i.e. the object time Data Storage Area of the current block or procedure. CDSA appears in all of the illustrated instructions because, in the assumptions of this simple case, all of the identifiers are declared in the immediately embracing block. If anyone of the identifiers hod been declared outside- the embracing black, the base register in the instruction involved would hove been GDSA (reg. 9) -- Global Dolo Storage Area. In the abject module, GDSA is always used to address the relevant Data Storage Area, where an operand is not declared or specified in the current block or procedure; CDSA at all times addresses the current Dora Storage Area. Diagram illustrating the function of the Operator/Operand Stacks Figure 55 indicates the contents of the operand representing an intermediate value or address contained in a register or contained in a Data Storage Area field, i. e., the Data Storage Area of the block or procedure having the Program Block Number . o 2 4 3 5 r----------------,-----,-----T------------, I II lment in DSA>IJ ____________ ~ 010 an intermediate value contained in a Data Storage Area field 101 an address contained in the register indicated in the oferand 011 an address contained in Data Stcrage Area field a ~ - (See text) CONTROL OF OBJECT TIME REGISTERS Figure 55. or if operand in Data Storage Area Of the 16 general purpose registers available for use by the object module. seven registers are restricted to specific addressing functions. The remaining eight general purpose registers .• as well as all four floating-point registers" are available for general computational or addressing purposes. The division of register assignments is as follows: Available for general computational use General Purpose Registers 0-7 (GPRO, ••• ,GPR7) Floating Point Registers 0,2,4, and 6 (FPRO, ••• ,FPR4) Five-byte operand representing an intermediate value or address contained in an object time register or temporarily stored in the register's reserved storage field in a Data storage Area. Except for certain special-purpose operands, the location and type of every operand at object time is indicated by specific binary settings in the characteristic of the relevant stack operand (namely, bits 0, 1., and 2 of Byte O). The significance of the various settings is as follows: Characteristic Byte 0 Significance (Bits 0, 1, 2) Operand represents: 110 100 a variable or constant with an assigned storage field in a Data Storage Area or a Constant Pool, or the address of a declared procedure, switch or label with an assigned entry in the Label Address Table a value contained in the register indicated in the operand Available for general addressing use General Purpose Register 8 (ADR) Restricted to Specific Addressing Functions General Purpose Registers 9-15. The use of each of these registers is indicated in Chapter 11, under "otject Time Register Use". To provide for the logical and efficient assignment of the registers available for general computational and addressing use, two systems of register control are employed,. one for general purpose registers. the other for floating-point registers. These control systems,. which are administered by a set of sutroutines indicated telow, have two purposes: 1. To ensure that, whenever a competing demand arises for the use of a given register, any intermediate value contained in that register is duly saved; and 2. To minimize the number of Store Register instructions in the object module (in other words" to maximize the register holding time). Figure 56 illustrates the control fields used in the control of otject time general purpose registers. Chapter 8: Compilation Phase 113 Object Time General Purpose Regi"sters 0 - 8 GPR 0, GPR 10 r======~(A~II~Z~.~ro;:.~-;un~Used~)=====31~0~l=0~1~1 . . . I!~o~1 . . ~::lrts~=O~~:t:h 7 ned (Number of lastassi9. [:1 E--CAII xeros - unUsed>----1 1 (Registers: 6 4 0 ) I'- _ _ _ _ _ _ ....1I GPR 3, ,-------, '- ______ ...J GPR 4, ,-------, L ______ - last assigned register GPR 2) Fixed Point Register Use Indicator (RH) o ,------.., ,-------, 2 GPR 50 In use in object code. I'- ______ ...JI GPR 21 Fixed Point Cycle Indicator (ell) o r-------, IL.. _ _ _ _ _ _ ...JI I I X X X I ....II r-------, I'- _ _ _ _ _ _ ....1I ,-------, GPR 60 1'- _ _ _ _ _ _ ....1I GPR 7, IL.. _ _ _ _ _ _ -...II GPR 8, L ______ J r-------, ,-~----..., X (ADR) Fixed Point Operand Address Table (RUTI) Entry far GPR 0, A (Stack aperond) Entry for GPR 1: A (Stack operand) Entry for GPR 2, A (Stack aperond) Operand Stack* Object time Data Storage Area (of current block or procedure) 2 I 1 I Entry far GPR 3, ; Entry for GPR 4, Entry for GPR 8 S, I r--------------, I I I I I I I I I (Storage fields reserved for identi ... fiers declared or specified in the current block or procedure) I Entry for GPR 6, oI Entry for GPR 7, Entry for GPR 8: A (Stack operand) Starage fields rEtreserved for obiect time general p,lrpose and floating r:i:;:er:g:~t:' ~e; for the current block or PNlcedure, and for other object time data .. * Th Operand Stack may at the $Orne time contain operands (not specifically identified in the fi;re) representing intermediate values in object time fI~ting point registen, and pointing to 8-byte.storage fields in the Data Storage Area - see Figure 57. Figure 56. Control Fields governing use of object time general purpose registers" showing relationships to Operand Stack,. Data storage Area and registers The two-byte Fixed Point Cycle Indicator (CII) indicates the number of the last assigned register among general purpose registers 0 through 7. When a register is required for computational purposes, CII is increased by one (or reset to 0 if CII~7). The resulting number is the number of the register to be used. This rotational assignment of registers ensures a maximum register holding time. (Where an even or odd pair of registers is required for 114 integer division or multiplication, CII may be increased by two). The two-byte Fixed Point Register Use Indicator (RIl) indicates the registers currently in use among general purpose registers 0 through 8. A register 1n use is indicated if the corresponding tit is turned on. I f the register is currently in use, a store Register instruction must be generated before the register can be used in the subsequent object code (see telo~). The 36-byte Fixed Point Operand Address Table (RUTI) provides a full word for each of registers 0 through 8. Whenever code is generated to load a value (or address) in a register, a four-byte storage field, or save area, is reserved for the register in the current Data storage Area. The relative address of the save area is recorded in the relevant Operand Stack entry, while the address of the Operand Stack entry is stored in the register's full-word entry in the Operand Address Table (RUTI). If, when a given register is to be used, the Register Use Indicator (RII) shows that the register is currently in use, code is first generated to store the contents of the register in the storage field specified by the relevant Operand Stack entry. Thereafter, a new save area is reserved for the register in the current Data Storage Area, its displacement being recorded in the current Operand Stack entry, and the address of the Operand Stack entry ceing stored in the appropriate entry of the Operand Address Table (RUTI). When a register is released (i.e., as soon as it is no lcnger needed), the register's save area in the Current Data Storage Area is relinquished, and the corresponding bit in the Register Use Indicator (RII) is turned off. The Cycle Indicator (CII) is reduced by one (or reset to 7 if CII=O), and the Operand Address Tatle (RUTI) is unaffected. Object time register control is handled primarily by ROUTINE1, ROUTINE2, ••• , through ROUTIN15. Figure 57 illustrates the control fields used in the control of object time floating-point registers. The fUnction of these fields is entirely anologous to that of the control fields which govern the assignrr.€nt of general purpose registers (Figure 56). Object Time Floating Point Registers 0,2,4,6 Floating Point Cycle Indicator (CIR) i I I I - - - - - - ( A I I zeros - unUSed)------I_1 0 : 1 0 0 (Number of last assigned floating point register - FPR 4) r- -- - - --- --- ---, L ______________ FPR 2, rL -------- ------, ______________ .J x FPR 4, r--------------I L ______________ ..J x m& r---------------, L ______________ ..J Floating Point Register Use Indicator (RIR) o 2 (Registers: Floating Point Operand Address Tobie (RUTR) 4 0 ) Operand Stack* Entry for FPR 0: Entry for FPR 2: A(Stock operand) Entry for FPR 4: A(Stock operand) Entry for FPR 6: In use in object FPR 0, COde ~ Object Time Data Storage Area (of current block or procedure) '" ~ r ---------------, (Storage fieJds reserved for identifiers declared or specified in the current block or procedure) 4 I 2 I " f- -------r-------l I I I l- - - - - - - - - - - - - ----l I t- ---------------1 I * The Operand Stack may at the same time contain operands (not specificollr identified in the valu.esor addresses in object time ge~ero purpose registers, In the Data Stbrage Area - see Figure 56. ~~~r~i~~r~;s:~~yte storage fIelds intermediat~ Figure 57. I I l- -------~-------l I _______ I1___ - ----II L ______________ I Storage fields reserved for object time general purpose and floating rniZer~g:~:trsc~:d for the current block or procedure, and for other object time data. ~ Control Fields governing use of floating point registers, showing relationships to Operand Stack, Data Storage Area and registers Chapter 8: Compilation Phase 115 DECISION MATRICES The basic control framework of the Compilation Phase is expressed by a set of three decision matrices named the Program Context Matrix, the Statement Context Matrix and the Expression Context Matrix (Appendices V-a, V-b, and V-c). Each matrix specifies a particular compiler program to be activated (by the COMP routine) for every possible pair of operators in the source text and in the Operator Stack. The operative decision matrix at any particular point in time depends; in general, on the logical context of the source module currently being processed. Matrix changes are effected by the compiler programs according to changes in logical context, as indicated by the operators in the source module. A switch from one matrix to another is effected by incrementing or decrementing the matrix base register CCT (register 11). A prospective change to a specific decision matrix may be specified by the storage of an appropriate operator (PRC, STC, or EXC) in the Operator stack, whose -SUbsequent detection will cause the relevant compiler program to switch to the appropriate matrix. The operative decision matrix is referenced (by the COMP routine) with the aid of a Column Vector and a Row Vector. The Column Vector consists of a series of 2-hyte elements, each containing a displacement value associated with any given operator in the source text. The Row Vector consists of a series of 2-byte elements, each containing a displacement value associated with any given operator in the Operator stack. The sum of the displacements for the source operator and the stack operator gives the displacement of an appropriate half-word in the operative decision matrix addressed by pointer CCT. The half-word thus specified multiplied by four contains the relative address of an entry in the Address Table, containing the absolute address of the relevant compiler program. COMPILE TIME REGISTER USE The general purpose registers are used in the Compilation Phase as follows: 116 Register Number o Register Name 5 (Variable) (Variable) (Variable) (Variable) (Variable) SBR 6 PRPOINT 7 P 8 SOURCE 9 OPDK 10 OPTK 11 CCT 12 BASE 13 WAREG 14 15 (Variable) (Variable) 1 2 3 4 Variable use Variable use Variable use Variable use Variable use Base register of the Subroutine Pool Displacement pointer to the next instruction in the generated code Displacement pointer to the last reserved storage field in the otject time Data Storage Area of the current block or procedure Pointer to the current operator in the Modification Level 2 source text Pointer to the latest entry in the Operand Stack Pointer to the latest entry in the Operator Stack Base register of the operative decision matrix Base register of the operative compiler program Base register of the Common Work Area Variable use Variable use The use of registers 6 (PRPOINT), 7 (P), 9 (OPDK), and 10 (OPTK) is illustrated in Figure 54. CONSTITUENT PHASE ROU~INES OF THE CO~PILATICN The principal constituent routines of the Compilation Phase are described below. The relevant text and flowchart in which each routine is discussed or outlined can be found with the aid of the index in Appendix XI. The diagram in Figure 58 provides a guide to the various routines from the standpOint of the logical elements of the source module processed by each routine. All primary control routines., i.e., all routines entered directly from COMP, are referred to as "compiler programs". Subsidiary routines are referred to as "routines" or "subroutines". COMPILATION PHASE ( IEXSO) (from Subscript Handling Phase) Blocks C1nd Compound Statements Switches lobels Goto Stotements Arrays Proeedures Code Procedures Stondard Procedures For Statements Assignment Statements Conditional Statements Conditional Expressions Arithmetic Expressions Boolean Expressions Semicolon Handling Context Switching logical Error Recognition Close of Source Module Figure 58. Diagram showing the compiler programs in relation to the logical elements of the source module Chapter 8: Compilation Phase 117 A summary of the compiler programs, showing, among other things, the stack operators and operands at entry and exit, errors detected, and subroutines called, is provided in the table in Appendix X. PHASE INITIALIZATION HCOMPMOD Control Field. Except for the first two records" which are read in by Control Section IEX40001, 9ptimiz at ion Table records are read from the SYSUT3 data set by the NX~OPT subroutine, on call from Compiler Programs 40, 47, and 49. IBUF2 SOURCE compilation Phase initialization is divided between Control Section IEX40001 in Load Module IEX40, and a short initializating routine at the start of Load Module IEX50. Control Section IEX40001 acquires main storage for the private area pictured in Figure 59; constructs Program Block Table III in the Common Work Area; reads in the first two records of the Modification Level 2 source text and the Optimization Table; and transfers control (XCTL) to Load Module IEX50. -- OPBUFl AOPTABE OPUBF2 AOPTABE OPTK °Etimization Table Buffer 1* -- -- Optimization Table Buffer 2* I ~ The initializing routine at the start of Load Module IEX50 addresses the Program Context Matrix in the Common Work Area: specifies new program interrupt, I/O error and End of Data exits; and enters the Scan to Next Operator routine. Source Text Buffer 2* ALPHA I °Eerator Stack* At entry to IEX40001, the address of the terminating routine INERRl is stored at ERET, the location referenced by the Program Interrupt routine (PIROUT) and the I/O Error Routines (SYNAD and SYNPR) in the Directory. INERR1 is replaced by INERR2 after the private area has been acquired. The GET MAIN instruction for the private area 'pictured in Figure 59 is issued after the area sizes of all work areas have been totalled. The area sizes are obtained from the Area Size Table (see Chapter 3) in the Common Work Area, except in the case of the Label Address Label, for which the area is fixed at 4096 bytes. Source Text Buffer 2 is acquired only if the Modification Level 2 source text is to be read into main storage from the SYSUT2 data set (i.e., the buffer is not acquired if the entire source text was transmitted by the Scan III Phase in Source Text Buffer 1 in the Common Area, indicated by the SPIC switch in the HCOMPMOD control Field). Except for the first two records, which are read in by Control Section IEX40001, Modification Level 2 text records are read from the SYSUT2 data set by the JBUFFER subroutine on call from SNOT (Scan to Next operator), and Compiler Programs 4, 51, and 66. Similarly, buffers for the Optimization Table are acquired only if the table was constructed by the Subscript Handling Phase, indicated by the OPT switch in the 118 OPDK LATAB 1- 0Eerand Stack* Label Address Table ( 4K) reserved (28 fullwords for object time address ~_.2~ st~dard_J:ZE~ed~.r~l!l ___ LN -~ (Space reserved for object time addresses of labels, switches and procedures declared in the source module) ----------------- *Area size specified by Area Size Table in Common ~vork Area. See Appendix VIII for the variation in area sizes as a function of the SIZE option. Figure 59. Private Area acquired by Control section IEX40001 for the Compilation Phase (IEX50) The Operator and Operand Stacks occupy opposite ends of a comrined Operator/Operand Stack area. ~he handling of the Operator and Operand Stacks is discussed elsewhere in this chapter. A total of 4096 bytes are allocated for the Label Address Table. This includes space for entries assigned in the Scan 1/11 Phase to labels, switches, and procedures declared in the source module. The remainder of the Label Address Table is used in the Compilation Phase for branch addresses produced by the compiler in the object code. The displacement of the last assigned entry is indicated by displacement pointer LN (Label Number), transmitted from the Scan 1/11 Phase via the Common Work Area. The first 28 full-words in the Label Address Table are reserved for the object time addresses of standard procedures which may be called in the source module. At initialization, the first bit in each fullword is set = 1. If, subsequently, a call for the standard procedure is detected, the bit in the corresponding entry is reset to o (by Compiler Program No. 64). In the Termination Phase, ESD records are generated for all standard procedures which were called, indicated by the first bit in the entry being equal to o. Program Block Table III is constructed in the Common Work Area by transferring the contents of each two-byte entry in Program Block Table II (see Chapter 5) to the first two bytes of the corres ponding four- byte entry in Program Block Table III. The last two bytes in the new entry are zero-set. Program Block Table III is located in the Common Work Area. In the same way, space is provided for various other tables, inclUding: Data set Table (DSTAB) I/O Table (IOTAB) Subscript Table (SUTABC) The tables are described elsewhere in chapter. this As soon as the first two records of the Modification Level 2 source text and the Optimization Table have been READ (and CHECKed) from the SYSUT2 and SYSUT3 data sets, control is passed (by XCTL) to Load Module IEX50 (Compilation Phase proper). Before the respective READ instructions are issued, the address of a point to be entered in the event of an End of Data conditon, is stored at EODUT2 and EODUT3 in the Common Work Area, the locations referenced by the End of Data routines EODAD2 and EODAD3 in the Directory. If the entire source text was transmitted by the Scan I I I Phase in the Common Area buffer, or if no Optimization Table was constructed (indicated, respectively" by the SPIC and OPT switches in the HCOMPMOD Control Field), the corresponding READ and CHECK macro instructions are bypassed. On entry to Load Module lEX 50" the address of the terminating routine CPERR1 is stored at ERET" the location referenced by the Program Interrupt routine PIROU~ and the 1/0 Error rcutines SYNAD and SYNPR in the Directory. After loading register 11 (CCT) with the address of the Column Vector of the Program Context Matrix (see Appendix IV-a), the End of Data exits JB3 and NX4 are specified for the SYSUT2 and SYSUT3 data sets, and the Scan to Next Operator routine (SNOT) is entered. SCAN TO NEXT OPERATOR I_________ Code> Iparameters>1 L ___________ J ~ ~ : X' 00' X'04' X'08' X'10' Figure 60. - Block Non-type procedure Type procedure Code procedure (LAT) f L ADR, (LAT) L GDSA, (PST) S CSWE2 (FSA) CSWE2 reactivtltes the intervening lower level Data Storage Area(s), if any; reloads CDSA with the address of the Data Storage Area of the block containing the switch ~;s~fH~tor; and retums to the return oddreS'S AOR with the label oddre$$, and branches to the Fixed number of components) T- (Constant: (Address Constant: < L1> ) I 'GOTO'; 5'[2]; CD GDSA, 0 (pST) L SRR, 8 (GDSA) L ADR, < LN> (LAT) L GDSA, < PSN> (PST) CSWEI deactivates t"'e intervening higher _-:c-----BAL 5TH, CSWEl (FSA) level Data Storage Area(s), jf any; loads I CDSA with the address of the DSA where L - - 8 RETPROL (FSA) the switch is declared; and branches to the relevant component code $eCluence. . I ~fE!!::'~f ~hC:bl!~k(~o;:i;!d~~:~srecclsJA ~.------' with the address of the Data Storage Area of the block containing the switch component address; and branchs to the component address. (To component address) I Figure 61. (Comma or Delta) generates all or part of a code sequence For ~component in the switch list, depending on whether 'the component is a simple label or a ~ol~b~i~ ~h~i~::~~:ree;~;r~tl!J~ CpGI:~sis L ADR (LAT) L GDSA (PST) B cswd (FSA) .---------+_' (~) stores the displacement (PRPOINT) of the next instruction, in 0 stock operand, to represent the address of the first component code sequence. context, if a switch component is represented by an expression enclosed by porenthesesJ CP~9 L_(Addres$ Constant: < l2>') -!Address Constant: < l3» : CP85 ~P56 stacks the left parenthesis and switches to expression L ADR, (LAT) _ _ _ _ ~ ~~ti (F~~~N> (pBT) (Switch designator in goto statement) CP4 (Switch) generates code to branch around the declaration, I.e. the code for the components in the switch list. ~ ~:~;r:x ~~:rg:~~~~:IC!c~;s~l~fn ;~~::~i:i~~5 tt:. :n if clause or a switch designator), the code to evaluate the expression and to load ADR with the component address will have been generated by some other compiler program, before entry to CP59, and the code generatecl by CP59 will consist solely of the final branch to CSWE2. CP59 also stores the displacement (PRPOINT) of the next object code instruction in a stack operand, to represent the address of the next switch component code sequence. At the end of the switch list, CP59 generates a constant specifying the number of components in the list, and an address constant for each component, specifying the address of the corresponding code sequence. The displacement (PRPOINT) of this I ist of constants is stored in the switch identifier's Label Address Table entry. Lastly, the displacement of the next instruction in the object code is stored in the Label Address Table entry referenced in the bronch instruction at the head of the declaration. B=P6 stocks the operator Goto - see "Goto Statements" t .J CP41 ([) switches to statement context and stacks the [ . CP38 [CP62 ~~~~,e7::s~tSAh!~~hl~:sa:~e:;: ~~: ~s1:h~~~ the switch is declared, loads ADR with the addre$$ of the switch, and branches to the Fixed Storage Area routine CSWE1. If the switch identifier is a formal parameter in a procedure body, the code will include a call for the actual parameter (see "Procedures"). ~:t%~t7:E~pdJ:>to _b::~~d~t:hS~a~xe:e~!~'~1e Area Diagram showing code generated for switch declaration and switch designator The opening branch instruction ensures that none of the component code sequences is executed until a call for a switch component is actually executed. The length of the code sequence depends on the complexity of the component in the switch list. The code for a switch designator consists essentially of instructions to load the component number specified in the switch designator, and the switch address (the address of the address ~onstants in the switch declaration), and to branch to the Fixed storage Area routine CSWE1. If the switch identifier in a designational expression is a formal parameter, the code may be more involved (see "Procedures"). The Object time starting point in the execution of the code for a switch is the code corresponding to a switch deSignator (in Figure 61, the starting point is marked by a circled S). When the code is executed, registers are loaded with the switch address and the component number, and a branch is then taken (via the Fixed Storage Area routine CSWE1) to the relevant component code sequence in the declaration. The component code sequence loads the component address (in the illustration, the address is a simple label address) in a register and returns (via the Fixed Storage Area routine CSWE2) to the next instruction following the call to CSWE1. Compiler Program No.4 (CP4) CASE A CASE B Source Operator: Switch, Array, (all stacked) CASE C Pi" Phi Stack Operator: Beta, Pi, Phi or Alpha CASE A: The source operator Switch marks the beginning of a switch declaration. Code is generated to branch around the object code to be subsequently generated for the cdmponents in the switch list. See Figure 61. CASE B: See "Arrays". CASE C: See "Prodedures". Chapter 8: Compilation Phase 121 Compiler Program No.85 (CP85) Source Operator: Stack Operator: Compiler Program No.41 (CP41) CASE'A Assign Switch Source Operator: Stack Operator; The combination of source and stack operators indicates the start of a switch list in a switch declaration. The operator Switch:= is stacked, replacing switch, and control is returned to SNOT. Compiler Program No.56 (CP56) Stack Operand: CASE B Identifier> CASE A: The o~erators and the stack operand identify a switch designator, e.g., S[2]. After stacking an operator to specify a return to the current matrix" the Statement Context Matrix is addressed and the source operator is stacked. Control is then returned to SNOT. CASE B: See "Arrays". CASE A CASE B compiler Program No.38 (CP38) Source Operator: Stack Operator: Switch:= or CASE A CASE A: The operator < in this context indicates the beginning of a switch component enclosed by parentheses. The operator is stacked and a shift made to the Expression Context Matrix, before control is returned to SNOT. CASE B: See "Goto Statements". compiler Program No.59 (CP59) Source Operator: Comma or Lelta Stack Operator: SWItCh:= Identifier) CASE A: The source operator] follows a component number or expression in a switch designator. Code is generated to branch (via the Fixed Storage Area routine CSWE1) to the component code sequence corresponding to the specified component num~ ber, as indicated in Figure 61. The stack operators and all o~er­ ands are released, a shift is made to the decision matrix specified ty the next stack operator, and central is returned to SNOT. CASE B: See" Arrays .... LABELS Either source operator marks the end of a component in a switch declaration. CP59 generates the code sequence indicated in Figure 61 for the component. If the source operator is ~elta, indicating the last component in the switch list, a constant, representing the number of components in the list, and a series of address constants, each pointing to one of the preceding component code sequences, are generated. Compiler Program No.1 (CP1) Source Operater: Stack Operator: Label Colon Alpha" Beta, Pi" Phi, Begin, Semicolon" Then-s, Else-s or Do The source operator follows a declared label, represented by the operand at the top of the Operand Stack. 122 ~ The displacement (PRPOINT) of the next instruction in the oDject module is stored in the Label Address Table entry addressed by the label operand, and the operand is released. If the stack operator is Beta, Pi, or Phi, a Semicolon is stacked in order to ensure that an error is subsequently recorded if a declaration follows. Expression Context Matrix, and centrol is returned to SNO~. compiler Program No.62 (CP62) Source Operator: GOTO STATEMENTS Stack operator: semicolon, Anyone of the source operaters marks the end of a goto statement. Compiler program No.6 (CP6) CASE A CASE B Source Operator: Goto or For Stack Operator: Begin, Do, SemIcolon, Then-s, or Else-s CASE A: The source operator identifies a goto statement. The operator is stacked, a switch is made to the Statement Context Matrix, and control is returned to SNOl'. CASE B: See "For Statements n . Compiler Program No.56 (CP56) CASE A Source Operator: Stack Operator: switch:= Epsilon, Eta, End, or Else Goto -- CASE B or CASE A: See nswitches". CASE B: The source operator beginning of a expression. The stacked, a switch indicates the designational operator is is made to the Code is generated to cranch to the address designated by the stack operand, either directly or via the Fixed Storage Area routine RETPROL. The stack operand may represent a simple label declared in the current block or in soree higher level cleek, or an address contained in register ADR representing the computed address of a designational expression other than a simple label. In the last case register GDSA is loaded with the address of the Data Storage Area in which the latel was declared. If the operand represents a simple label declared in the current block cr procedure, code is generated to branch directly to the label address, loaded in register ERR. If the operand represents a sirrple latel declared in some higher level block or procedure, the generated code loads the label address in ADR, loads GDSA with the address of the Data Storage Area corresponding to the clock in which the label is declared, and branches via RETPROL to the lacel address. If the operand represents an address in ADR, the code branches to that address via RETPROL. The latter routine releases the Data Storage Area of every block or procedure exited when the branch is taken. Chapter 8: Compilation Phase 123 ARRAYS The address of any particular element, A[S~,S2,Sa, ••• ,s~], of ••• ,Ld:Ud]' may be expressed by the for~ula: the array declared A[L~:U~,L2:U2,La:Ua, + (S~-L~){(U2-L2+1)(Ua-La+l) ••• (Uor-Ld+l)Pd+1} + (S2-L2){(Ua-La+1)(U4-L4+1) ••• (Ua-Ld+l)Pa+1} + (Sa-La) {(U4 -L 4+1) (Us-Ls+l} ••• (Ud-Ld+l)Pd+1} + where d= the number of subscripts in the array, ••• ,Ld] is the address of the first element, and 1 is the length in bytes <1, 4" or 8) of each element. A[L~,L2,La, Pd+ The expressions within braces { ••• } in formula (a) are called address increment factors, and represent the incremental displacement associated with an increment of 1 in the particular subscript value. The address increment factor, P j + 1 , for any given subscript position i in the array A[S~,S2,Sa, ••• ,sa] is defined by a p. II I where Pa + 1 pOSition, a = j=i (U.-L·+1)" J J length of array element address increment factor of the last subscript • Replacing the address increment factor expressions in the address formula (a) abcve, by the notation Pj, the following abbreviated form is obtained: (b) address of A [s~, S2, S3, ••• , sa] Expanding and rearranging: This may be reduced to = {address of A[L~,L2,L3,···,La] - L i=l 124 LjPj+1} The quantity enclosed by braces { ••• } represents a constant value, which holds independently of the address of the particular array element. It is called the zero-base address of the array and represents the address of the array element (an imaginary or actual element) with zero subscripts. The zero-base address of an array is computed at object time, and stored in the array's storage Mapping Function, by subtracting the calculated value of the quantity Byte 0 I 4 < Number of subscri pts, a > < Array's zero-bose address, i. e. address of A [L I , L2, L3 , ... , a La] - L i=1 LiP i+l > 8 < Address of fi rst array element, i. e. address of A [L I , L2, L3, ... , La]> 12
16 a Number of subscripts in the orray A. L. I U. Upper bound of the jth subscript. Lower bound of the jth subscript. I Pa +1 Figure 62. Length of array element (= address increment factor for lost subscript). 8bject Time storage FUnction of an array Mapping rhe storage Mapping Function for a particular array is constructed in the object time Data Storage Area of the particular block in which the array is declared. The area acquired for the array, on the other hand, is located outside the Data storage Area, in any part of main storage provided by the control program. An array's storage area is released, simultaneously with the release of the particular block's or procedure'S )ata storage Area, at exit from the block or procedure in which the array is jeclared. Chapter 8: Compilation Phase 125 ~rray declarations are handled by CP4, CP52, :P36, :P51, and CP54. rhe object code which issues the GErM~I~ instruction for the array storage area and which constructs the array's storage Mapping Function, is generated by CP51. The steps followed in this object time process are as folloNs: 1. rhe range (OJ-Lj+l) of each dimension of the declared array is computed and stored in a corresponding four-byte field of the storage Mapping Function, beginning at byte 16 for the first di:nension. 2. Nhen all of the array dimensions have been processed as in item (1), the array element length P«+1 (1~ 4, or 8 bytes, depending on whether the array is a boolean, integer or real array) is stored in the last entry of the Storage Mapping Function, to represent the address increment factor P, for the last dimension. array size is acquired" by call to the Fixed storage Area routine GETMSTO, and the addresses of the first element and the last element + 1 of the array are stored in bytes 8-11 and 12-15 of the storage Mapping Function. The displacement of the storage Mapping Function in the current Data Storage Area is recorded in bytes 12-15 of the Data Storage ~rea (Figure 88), the previous contents of bytes 13-15 being moved to bytes 1-3 of the storage Mapping Function. 5. 3. The address increment factors for the renainin; subscripts, and the array size, are now computed and stored in the Storage ~apping Function. The conputation consists in multiplying the dimension range in each entry (beginning with last entry but one and moving IIp,lard) by the address increment factor in the entry below, and storing the result in the entry, displacing the previously recorded dimension range. For a three-dinension array, ~[LL:UL,Lz:Uz,L3:U3]' with array elenent length d, the contents of the storage ~apping Function from byte 16 onwards, after this complltation, would be as follows. 15-19 20-23 24-27 23-31 !l.rray Size, PL=P;z(U 1 -L 1 +1) P;z=P 3 (U;z-L;z+1) P 3 =p .. W 3 -L 3 +1) P.. =d ~t the same time, the prodllct LjPj+1 is computed for each dimension and the result added to a cllmillative total, so as to calculate the ~uantity d. I: i=1 Li Pi+1 rhe zero-base address of the array cr - I: L. Pi + 1) , i=l I is derived by subtracting the computed value of the quantity (see item 3) from the address of the first element of the a:ray (item 4). The zero-base address ~s stored in bytes ~-7 of the storage Mapping Function. 6. The nunber of subscripts in the array is stored in byte 0 of the storage Mapping Function. Subscripted variables in source module statements are processed by CP41 and CP38. The object code generated by these programs depends primarily on whether the subscripted variable occurs in an embracing for statement, and if so, whether the subscripted variable contains subscripts optimized (precalculated) at entry to the iterated part of the for statement. To be optimizable, a subscript expression must be of the type (±F*V±A), rhis quantity is used in deriving the array's zero-base address (see item 5). rhe Lj values are saved in conseclltive entries of the current Data Storage ~rea. ~. 125 ~ain storage equal to the computed where F denotes a factor which must be an integer variable or constant, V denotes the for statement's controlled variable, and A denotes an addend which must be an integer variable or constant. F and/or A may be zero constants. where a for statenent contains a subscripted variable with one or more optim1zable sabscripts, c~de is generated (see "For Statements"), at entry to the iterated part of the f~r statenent, to compute (in the next available register named NXTR) the sam of the array's zer~-base address and the initial valae of the product SjPj+1 for every optinizable sabscript in the array" viz. (e) iihere a:ldress ~f I\.[O,O,0, ••• ,01+Es j'P j + 1 , denotes the initial value of the the address increment factor for the subscript position. In addition, code is generated to compute the cyclical address increment for all optimized subscripts, to be added to NXTR in each cycle of the for statement (except the first), viz. So' ~~timiza6le subscript and Pj+1 denotes (f) rhe result of this treatment at object time is to derive the particular array element address, by adding the contributions of each subscript to the array's zero-base address. If the subscripted variable contains subscripts optimized in an embracing for statement, the sum of the zero-base address and the initial contributions of the optimized subscripts is computed at entry to the iterated part of the for statement; the contributions of the non-optimized subscripts, together with a cyclical address increment for the optimize:l subscripts, are added in each cycle of the for statement. If the subscripted variable contains no optimized subscripts, on the other hand, the particular array element address must be wholly derived in each cycle by computing the contributions of all subscripts and adding these to the zero-base address. E±F*Pj+1 *(step Value), ~here F denotes the factor in the subscript" P j+ 1 denotes the address increment factor, and (Step value) denotes the increment to the contr~lled variable in each cycle of the for statement. At object time, the contents of NxrR in any given cycle of the for statement will thus be Compiler Program No.4 (CP4) CASE A (g) CASE B CASE C address of 1\.[0,0,0, ••• ,01+l:sj'Pi+1 + (N-1){E±F*Pj+1 * (Step Value)} ~here N denotes the number cycles of the for statement. Source Operator: Switch Arr~ Pi or Phi stack Operator: Beta" g!. gh!, or-MPh2--- of executed CP41 is entered when the opening bracket" [, in a SUbscripted variable is encountered. If the subscripted variable occurs in an embracing for statement and if the sabscripted variable contains one or more optimize:l (precalculated) subscripts, CP41 generates code to load the precalculated a:l:lress (expression (g) above) in a register reserved to h~ld the address of the subscripted variable. If, however, the subscripted variable contains no optimize:l subscripts, CP41 generates code which simply loads the reserved register with the array's zero-base ad:lress. CP38 is entered when the £QmIDa separating tiiO subscripts., ~r the closing bracket, 1, at the end of an array operand, is encountere:l. If the array subscript was optimize:l (i. e. " precalculated) in an embracing for statement, :P38 generates no Object code for the subscript~ If, however" the subscript was not optimized, CP38 operates code to compute the product SjPj+1 for the subscript and to add this product to the address previ~usly loaded (by CP41) in the reserved register. CASE A: See "Switches",. CASE B: The source operator identifies a following array declaration. The operator is stacked, the Statement Context Matrix is addressed, and control is returned to SNOT. CASE C: See "Procedures". ~iler Program NO.52-1£E521 Source Operator: Comma or [ Stack Operat~r: ~ay rhe source operators represent delimiters in an array declaration, e.g., 'ARRAY' A" B [1: 10];. If the source operator is a CO!lli!!~', a count of the array identifiers associated with the following bound pair list" is inc'l7emented. If the source operator is the opening bracket [, the operator • is stacked. Chapter 8: Compilation Phase 127 ( :J pper So~rce St~=k Operat~r: Jperator: C~l~n --i-- The source oper~tor represents the colon separating a bound pair in an array declar~tion, the lower bound being represented by the last entry in the Operand Stack. :ode is ~enerated to store the lo~er bound in the next entry in the Data Storage Area, and the :~lonis stacked. If the related stack operand-sho~s that the lower bound is not an inte~er, a call is first made to the TRREI~ subroutine, which generates code to br~n=b to the Fixed stor~ge Area routine C~VRDI for conversi~n ~f the l~wer bound to inte~er (fixed point) form. Boun d. (J j ) - (Lower Bound" L j ) + 1, and of storing the resultant in the relevant entry of the array's Storage Mapping Function (Figure 62). The contents of the operator and operand stacks after this adjustment are as follows: o o 5 -->r--------------------, I I ~--------------------~ I I ~--------------------1 I I r--------------------1 I I L ____________________ J 1 r-------, I Ar~S!y I ~-------1 I t I t-------~ I For:= I --> t-------~ I I L _______ J The contents of the source text pointer SOURCE (register 8) are saved, and the p~inter is reset to address a special field containing the following dummy Modification Level 2 text: S~ur=e Operator: St~ck Operator: £Q~~~ or ] £Q!QQ r----T----------------------T----' I + I ______ I ____ JI I ____ I _______________ L ~ The source and stack that the last stack operand represents the upper bound of a bound p~ir in an array declaration. The operator and ~perand stacks and the source text pointer are n~w adjusted, preparatory to entering CP69 (via entry point DHZB1), so as to specify the ~peration combinati~n ~perators indicates 128 ~f ~ ~ 1\ I The sequence of compiler programs and routines subsequently entered, and the actions taken# as a result of these adjustments, is as follows: Proqran/Routine ~Q~Qiler O~erators ~~ at Exit: Stack + CP69 (DHZB1) generates code to perform the operation Uj-Lj, releases the stack operator -~ and exits to COMP + + :OMP branches to CP66, determined operator pair + and ~Q~~~ + + :P66 stacks the source operator + and exits to SNOT + SNOT scans the dummy source text to the operator QQ, stacks the operand representing the constant 1, and exits to CDMP QQ + + :O~~ branches to CP69, determined operator pair QQ and + Do :P69 generates code to perform the operation (Uj-Lj)+l, releases the stack operator +, and exits to COMP :OMP branches to CP10, determined operator pair Do and ~QE~~ :P10 switches to the Statement Matrix, and exits to COMP context :OMP branches to CP43, determined operator pair QQ and ~Q~~~ by + QQ CP43 :P20 replaces the stack by the by the by the Assiqn the operator Por:= by ~~~iqQ and exits to CP20 (DB1C2'---- (DB1C2) generates code to store the dimension range, Uj-Lj+l, in the Storage Mapping Function entry addressed by the relevant stack operand (see above), releases the stack operator Assign. and returns to CP51 (OERE2) At re-entry to CP51, the source text pointer SOURCE is reloaded with the previously saved address of the source operator ~Q~~~ or ) in the current input buffer. If the source operator is ~~~, indicating that a further bound pair follows, an entry is reserve:j in the Data Storage Area for the object tine value of the lower bound to be processe:j next, an:j control is returned to SNore rhe lower and upper bounds W'ill subse~uently be processed by CP36 and CP51, in the manner described above. If the source operator is the closing bracket 1, indicating the end of the bound pair list, CP51 now generates code to compute the address increment factors for ea=h subscript posit~on in the array, and co store the factors in the appropriate entries of the array's storage Mapping Fun=tion (Figure 62). Thereafter, the stack operator [ is released and code is generate:j to acquire a storage area for the array, and to fill in the data in the first 16 bytes of the Storage Mapping FUnction, in the manner outlined at the beginning of this section. A test is then made to determine if the same bound pair list defines a second array (as" for example,. in 'ARRA~' a,b[1:10,1:101;)' In this case,. code is generated to copy the first array's Storage Mapping Function, from byte 16 onwards,. into the second array's Storage Mapping Function area. Code is then gener~ ated to acquire a storage area for the second array and to complete the remainder of the storage Mapping Function. This procedure is repeated for every array defined by the bound pair list. Lastly, the character following the closing bracket is inspected. Logically" the closing bracket may be followed by a ~Q~~~ (as, for example" in "ARRAY' a.b[1: 10], ell: 100] ;) or by 12el£2. representing the semicolon at the end of the Chapter 8: Compilation Phase 129 decl~r~tion. Any other char~cter following closing bracket would represent a synt~ctical error. If the operator is a Comm~, control is passed to SNore rhe programs subsequently entered from C~MP Nill process the following array(s) and bound p~ir list(s). If any character other th~n a ;Qillill~ is ietectei, control is passed to C~~P, Nhich then branches tp CP54 (if the character is the operator Qel£~), or to some other compiler program. which will record the syntatical error. the £QillQiler Progran No.54 (CP54) Source Jperator: Stack Jperator: Q.~lt~ ~~ [released] The source ani stack operators indicate that the end of an array declaration has been reached. ~ call is nade to the SCHDL subroutine (which updates the semicolon count and generates a call to the Fixed Storage Area routine TRACE, if the TEST option has been specified); the Program context M~trix is addressed, and control is passed to SNore for statement" code is generated to load the reserved register with the precalculated address (expression (g) above) The presence of an optimized subscript is determined, in the first instance" by verifying whether SUTABC (Figure 71) contains any entries (representing one or more arrays in the embracing for statement l containi~g optimized subscripts) " and in the second instance" by comparing the position of the current subscripted variable's opening bracket in the input bufferl with the position noted in SUTABC of each of the arrays listed. Where this comparison shows that SUTABC contains an entry for the subscripted variable, the same entry will contain the address of an operand pointing to the object time register (or the Data storage Area field) which contains the precalculated address. A test is then made of byte 7 of the surABC entry to determine if the first subscript has been optimized. If so" the SMT switch in the HCOMPMOD Control Field is turned on" indicating to the arithmetic compiler programs that no code should be generated for any operators in the subscript~ and to CP38 that the following subscript has been optimized. Ie CASE B Source )perator: Stack 8perator: (See matrices ~ppendixes V-a to V-c) identifier> CASE A: See "Switches". CASE A CASE B Comma or ] Source Operator: ----1 Stack Operator: Stack Operand: Identifier> CASE B: A subscriptei variable in a statement has been encountered. After st~cking an operator to specify a return to the current matrix, the statenent context Matrix is addressed and the source operator stacked. CAS& B: Either source operator is preceded by a subscript expression. The closing bracket" ], marks the end of a subscripted variable. A register is reserved to hold the address of the array element. If the subscripted variable contains no subscripts optimized in an embracing for statement (if any), or if the array is a formal parameter, code is then generated to load the register with the array's z ero- base address. If, however, the subscripted variable contains one or nore subscripts optimized (precalculated) in the embracing Comma: If the HCOMPMOD switch CMT shows that the subscript was not optimized ' DC H '' L ADR, (CDSA) ~ $PRR;:'<81~~~R~2> (CDSA) ~ ST < GPR>. (CDSA) (Phi or Pi)generates code to branch around the code representing the declared procedure, which begins with one Of more constants representing the charocteristic(s) of the formal parameter(s). If a parameter is value specified (os is FI in this example), CP4 generotes code, first, to branch to the code sequence for the actual parameter (via thp. Fixed Storage Area routine CAPI), and second, to call the Fixed Storage Area routine VALUCALl, w\'ich stores the value of the actual parameter in t\'e formal parameter's object time Data Storage Area field. [CP69 (+) calls OPDREC on recognition of the operand F 1 J OPDREC (called by most compiler programs whenever on operand is encountered) generates code, in the case of a formal parameter called by nome, to branch to the code sequence for the octuol porameter (via the Fixed Storage Area routine CAPl). [CP69 generates code, on return from OPDREC, which loads ~:; ~~~~~tle;,al::d~a~~~se~:t~~r v~?u? i~0~t~7;:~ain~2~s EPllOGP activates the Data Storage Area of the logically or dynamicolly enclosing block or procedure; moves the computed value of a ~pe procedure to the Fixed Storoge Area location ......FCTVAlST (addres,ecJ by ADR); releases the Data Storage Area of the called procedure; and posses control to the next instruction following the procedure coil. - END'; Z ~r~l~e~~~:a~:s ~r:l~ fJ~~~~;; ~;e~nf~eV;r the result _ I ,= 'IX, YI; _I- '-- BEPILOG' IFSAI - . '-~' ~:;,~:(~~,~~A:I } - CP64 (Left Parenthesis) generates code to branch over the following code sequences for the actual parameters in the procedure call. ICDSAI CAP2 reactivates the intervening higher level __ X> Dolo Storage Area(s), if any; loads CDSA with - -the a~d~ess of the Data Storoge Area of the block _ LA ADR (CDSA) containing the actual parame.'er call; and relurns~ ~ _ _ B CAP2'(FSA) control to the return addreSs m BRR. MVT PROLPBN, r, ;;:;;~;;:;;:;:--::==I===~ PROLOG acquires moin_ 510roge for the Data Storage Area of the called procedure; 'stores the addresse's of the actual parameter code sequences in the Data Storage Area fields of the formal parameters; and bronches to the first instruction in the procedure. __ L-_ _ _ _~ L ADR, (LAT) BAL BAR, PROLOG (FSA) DC A«Address of X~ code sequence» DC H '< Characteristic of X::>' DC H '< Number of parameters, 2 >' DC A«Address of V's code sequence» DC H -< Characteristic of V>' ~~CH~~I~pm_mZ~4:mche~:;r in CPl6 (End) generates code to branch to the Fixed Storage Area routine EPllOGP, which releases the procedure's Dato Storage Area. CPl6 also stores the displacement (PRPOINT) of the nexl object code instruction in the Label Address Table entry referenced in the branch instruction at the head of the procedure declaration. O(ADR) l CPS7 (Comma or Right Parenthesis) generates all or part of a coae'Sequence for each actual parameter in the procedure call. In the simplest cose, where (as in the illustration) the octuol POrameters are simple variables or constonts, the code sequence loads ADR with the address of the parometer, and branches (vio the Fixed Storoge Area routine CAP2 to the next instruction in the procedure body, following the call for the actual parameter. At the end of the list of actual parameters, CPS7 generates code to load ADR with the address of the procedure and to branch to the Fixed Storage Area routine PROLOG. The call to PROLOG is preceded by on MVI instruction which specifies the fnrooc::~;s~~~P;h;r~;pr~l;r~~t~~~tb;r o~u:h~ li::~t~~eG Program Block Tobie, containing the size of the required Data Storage Area). The call is followed by 0 series of constants, spectfying, among other things, the addresses of the precedtng actuol parameter code sequences At eX11 from CPS7, the Operand Stock contoms an entry representmg the function value of P(X,Y), the address of the value bemg m ADR [CP20 (Semtcolon) generates code to move the compvted value of the type procedure P from the Fixed Storoge Area ~~~~~~oen L~!~~~~To~o~~:$~~i~ae ~JR) Fi;:rure 63. Coje ;:renerated for declared type procedure and procedure call within the ~rocedure body, every formal called by name is represented by a call to the corres~onjing actual ~aramet­ er code sequence (via C~Pl and C~P2). The address of the relevant coje sequence is obt~inej from the formal parameter's Data storage ~rea field, where it is stored by PR)L)G Nhen the particular call for the procedure is executed. In the case of a formal ~araneter called by value in the procedure body~ the actual value or address of the ~araneter is sin~ly fetched from the form~l ~arameter's Data Storage ~rea field, Nhere the value or address will have been storej at entry to tne procedure. ~~r~meter rhe close of the procedure body is by a branch to the Fixed stora;:re ~re~ routine EPIL)3P. EPIL03P releases the Dat~ Stora;:re ~rea of the procedure and passes control to the next instruction followin;:r the procedure call. If the procedure called is a type ~rocedure~ EPIL)GP moves the calculated value of the procedure re~resented 132 to the Data from the appropriate Data Storage Area ent.ry to a standard location in the Fixed Stora;:re ~rea, before releaSing the type procedure's Data Storage ~rea. PROCEDURE CALL rhe procedure call consists essentially of a call to the procedure by way of the Fixed stora;:re Area routine PROLOG. ~mong other thin;:rs, PROLOG acquires a Data Storage Area for the procedure and then branches to the code representing the procedure. The Program Block Number and the address of the procedure are transmitted to PROLOG by instructions immediately preceding the call. The Program Block Number specifies the appropriate entry in the object time Program Block Table (Figure 84) which contains the size of the Data Storage Area to be acquired by PROLOG for the procedure. If the procedure call includes any actual parameters, the c~ll to PRJLJG is pre~eiei by a c3de Se~uence for e~ch actual p~r!meter. fhe code sequence, which is onlv eKecuted when c~lled by the procedure, ~3mputes the value or the address of the actual parameter (where the ~ctual parameter is not a simple variable or a constant), loads ~DR with the address of the actual p!r!meter, and returns control (via the riKed Storage ~rea r3utine CAP2) to the neKt instruction in the procedure. A branch instruction preceding the actual parameter code se;uence(s} ensures that the coie sequences are not executed until called bV the procedure. The address (es) of the actual parameter code sequence(s) and the characteristic(s) of the ~ctual parameter(s) are stored in a series of constants following the c~ll to PROLOG. rhe first parameter entrv contains the number of actual parameters. PROL03 verifies toe compatibility of the formal and actual parameters (by comparing characteristics) and stores each parameter ~oie sequence address and characteristic in the related formal parameter's storage field in the Data St3rage Area ac~uired for the procedure. This enables the appropriate ~ctual parameter code sequence to be accessed and executed whenever the actual parameter is called by the procedure. In the latter case, control passed directly to COMPo is If the declared procedure is not parameterless, a series of constants 1S generated representing the characteristics of the parameters in the formal parameter list. A.t the same time, an entry is made for each parameter in a table named CBVTA.B (Called by Value Table) " which accommodates up to 15 threebyte entries. The contents of the CBVTAB entries" for each type of formal parameter are as follows: Non-label value: parameter o called by 3 l r-------T------------------, I K 80' I I I L _______ L __________________ J Label parameter called by value: o l 3 r-------T------------------, I K'CO' I I L _______ ~ __________________ J Parameter called by name: o 3 r--------------------------, I I L__________________________ J CASE A Source Jperator: SWitch Stack Jperator: Be~~, CASE B ~r~~ Pi, ~hi, CASE C Pi or Phi [stacked] or ~l£h~ See "Switches". C~SE ~: C~SE B: See C~S~ C: rhe source operator indicates the start of a procedure declaration. Code is first generated to branch around the c3de subsequently generated for the declared procedure. rhe branch instruction references a new entry reserved in the Label A.ddress rable, in which the displacement (PRPOINT) of the instruction fol13wing the end of the procedure is subsequently inserted by CP16. A scanning operation is then initiated (by call to 3NOPDOPR) to locate the operator following the procedure identifier. The operator mOlY be the left parentheSiS preceding a f~rmal parameter list, or the operator Q§l~~ marking the en1 of a parameterless procedure heading. "~rrays". The characteristics in the entries., which are constructed in the order in which the parameters occur, are copied from the internal names representing the parameters in the Modification Level 2 source text. When all parameters in the formal parameter list have been processed in the manner indicated, code is generated for every value-called parameter listed 1n CBVTAB, to fetch the actual parameter value or label address and to store the value or address in the formal parameter's Data Storage Area field. The basic elements of the code generated for a non-label value-called parameter are indicated in Figure 63. In the case of a value-called label parameter, the code consists of a call to the corresponding actual parameter code sequence (via the Fixed Storage A.rea routines CAPl and CAP2) followed by instructions Which store the actual address (contained in A.DR) and the base address (contained in GDSA) of the Data Storage Area of the block where the Cha~ter 8: Compilation Phase 133 l~be~ is stora~e declared, in the 8-byte field reserved for the value-called parameter in the procedure's Data Storage Area. Nhen the end ~f the declare1 procedure nea1in~ is reached (indicated by the operator Delta), control is passed to COMPo See "Subroutine P::>::>l". CASE A: The left parenthesis is preceded by an operand representing a procedure identifier and constituting a call for the procedure. An operator is stacked specifying a return to the current decision matrix~ the Statement Context Matrix is addressed and code is generated to branch past the code sequence(s) to be subsequently generated (by CP57) for the following actual paraneter(s). To specify the address of the first parameter, the displacement (PRPOINT) of the next instruction in the object code is saved in an entry in the Operand Stack. Before control is returned to SNOT., the procedure bracket { is stacked. CASE B: The left parenthesis is preceded by a standard procedure designator. See "Standard Procedures". )per~tor: Source St~ck )perator: ~~ilQ~ Beta CASE B ~ASE End !H~gin ~§..g.Q~ ~ASE A and B: See "Blocks Statellents". :ASE ~: ~E§'~!Qn marks the declared procedure. C Pi or Phi [released] and CASE C: The leftparenthesis is preceded by an operator. See "Arithmetic Expressions" and "Boolean Expressions". Compound close of a Code is generated to c~ll the Fixed Storage Area routine EPIL~GP. The jispl~cement (PRPOINT) of the next instruction in the object c01e is stored in the Label Address Table entry referenced by the branch instruction preceding the procedure body, specifying a branch over the procedure (:PQ). The procedure type and the number of parameters in the pr::>cedure (obtained from the stack operand representing the procedure identifier) are noted in the corresponding entry of Program Block Table III (Figure 60) and a call is nade to PBNffDL. Source )perator: Stack Operator: (3ee decision matrices -Appendices V-a, V-b, V-c) Source Operator: Comma or ) Stack Operator: -{---Either source operator is preceded by an actual paraneter in a procedure call. ~P57 generates all or part of a code sequence for each parameter in the actual parameter list" depending on the type of the parameter. If the actual parameter (an expression) contains any arithmetic or relational operators, the first part of the code sequence (to evaluate the expression) will have been generated before entry to CP57. At the end of the list of actual parameters, :p57 generates a call to the procedure, by way of the Fixed Storage Area routine PROLOG (see Figure 63). The instructions generated by CP57 in each actual parameter code sequence (each of which terminates with a branch to the Fixed Storage Area routine CAP2) depend on the nature of the actual parameter, represented by the last stack operand. ( \ ,r-------------------------------------------T-------------------------------------------, I I Code Generated (followed in_every I ry2g_Qf_~g~~~1_~~f~~g~gf S:~~.!LQy a branch to CAP2) I I I ~-------------------------------------------+-------------------------------------------i Formal parameter Call the actual parameter (call generated by OPDREC). Inte~er, Strin~ real or boolean expression Load ADR with the address of the value of the expression. i:lentifier Inte~er, Load real or boolean array identifier ~DR with the address of the string. Load ADR with the address of Mapping Function. the storage Designational expression with the address of the label and with the address of the Data Storage ~rea corresponding to the block in which jthe label is declared. identifier Load ADR with the address of the switch and 3DS~ with the address of the Data storage ~rea corresponding to the block in which the switch is declared. S~itch Load GDSA I IProc::lur: identifier with no parameters Call the JPDREC). I I IProcedure identifier fN'ith parameters I I I I I ISt~n:l~r:l I I I IL _______ ~ ~fter each code se~uence has been ~te:l, the displacement (PRPOINr) generof the next instruction in the object code is store:lin an entry reserved in the Label ~ddress rable (addressed by a stack oper~n:l) to represent the address of the follofN'ing code sequence. rhe addresses thus recorded are stored in the form of ~:i:lress constants in the parameter list follo~ing the call to PROL03 (see Figure 63). ~fter tne last code sequence has been generated, the displacement of the followin~ instruction is stored in the Label ~ddress Table entry referenced by the branch instruction (generated by CP64) preceding the first code sequence. CJDE PRJCEDURES rhe term "code procedure" is applied to a declared procedure with a normal proce:lure h:a:ling, but fN'ith a procedure body consisting solely of the fN'ord 'CJDE'. The procedure (call generated by Load ~DR with the address of the procedure. Move the Program Block Number of the procedure to PROLPBN in the Fixed Storage Area. Save registers PBT and LAT in PROLREG. procedure identifier ___________________________________ ~DR ~ Load ADR with the address of a constant in the actual parameter code sequence, representing the last 4 bytes of the standard procedure designator. Move block number 0 to PROLPBN in the Fixed storage Area. ___________________________________________ J latter signifies that a precompiled routine with the same name as the procedure identifier in the heading, is to be fetched from the user's library of precompiled procedures. The generated code corresponding to the heading of a declared code procedure is identical in form to that generated for the heading of any non-code procedure (see Figure 63 and CP4). When the delimiter 'CODE' representing the procedure body is encountered, CP83 generates a call to the Fixed storage Area routine LOADPP, which loads the precompiled procedure into main storage and records the address of the procedure's entry point in the object time Program Block Table (see Figure 84). The call to LO~DPP is executed at entry to the block in which the procedure is declared. This ensures that the precompiled procedure has been loaded into main storage in advance of any call for it in the object module. Chapter 8: Compilation Phase 135 When the operat~r !Esilon, m~rking the of the declared code procedure, is encountered, CP16 does not generate a call to EPIL03 as in the case of non-code procedures, but simply marks the appropriate entr~ of Program Block T~ble III (Fi~ure 60) to show a code procedure and to note the number of parameters. 'The precompiled procedure is )ELETEd (by EPIL03) at exit from the block in which the code procedure is declared. cl~se The object code implementing a call for a code procedure is identic~l in form with the code for ~ non-code procedure call. It consists of a call to the Fixed storage ~rea routine PR~L~3. PROL03 acquires a Data Stor~ge Area for the code procedure, stores the addresses of the actual parameter code sequences in the Data storage Area fields of the forn~l par~meters, loads ADR with the address of the precompiled procedure (contained in the relevant Program Block Table entry) and branches to the address in ADR. rhe latter action is taken after determinin~ (by inspection of the Program Block rable entry) that the procedure is a code procedure. The object time re~isters PBr, and LAr are also changed by PRJLJG to point to the t~bles contained in the precompiled procedure load module. comEiler Program No.83 (CP831 Source Jperator: ~~ stack Operator: ~!, ~Q!, Compiler Program No.64 (CP64) Source Operator: Stack Operator: (See Decision Matrices -Appendices V-a, V-b, V-c) CASE A: The source operator is preceded by a procedure identifier. See "Procedures". CASE B: rhe source operator is preceded by a st~ndard I/O procedure or mathematical function designator (Appendix III), representing a call for the procedure or function. To indicate that the standard procedure has been called in the source module, the full word reserved for the address of the standard procedure in the Label Address Table (displacement specified in the last byte of a designator) is flagged, by setting the first bit = O. Flagging the entry causes an ESD and ~n RLD record to be generated in the Termination Phase (IEKS1) for the called standard procedure or function, ensuring that the Library procedure will be combined with the object module at execution time. After the procedure has been loaded, its entry point address is stored in the Label Address Table entry. ~gt~ CP64 initiates a count, in a stack of the number of parameters in the standard procedure call. In the same operand the displacement (P) is stored of the next free entry in the current Data Storage Area in which a parameter list will be constructed at object time. The oper~nd is referenced by CP61, which generates the code to construct the parameter list and to call the standard I/O procedure or mathematical function. Before exit to SNOT , the standard procedure bracket is stacked. oper~nd, ~~ffi~~ represents the bod~ of a declared code procedure. It is followed by an B-byte unit containin~ six characters of the code procedure name and two blanks (EBCDIC code). CP83 generates ~ call to the Fixed ~rea routine LO~DPP. The call is followed by two parameters: the name of the precompiled procedure and the displacement of the Program Block Table entry for the code procedure. Stora~e rhe displacement (PRPOINI) of the call in the object module is stored in the Label ~ddress r~ble entry referenced by the branch instruction generated by CP4 (see "Procedures") at the head of the code procedure declar~tion. 136 < CASE C: The source operator is preceded by another operator. See "Arithmetic Expressions" and "Boolean Expressions". standard 110 procedure, or (2) a standard mathematical function. S~urce Jperator: :omma or ) Stack Operator: ~--- 1. Either source operator is preceded by an actual parameter in a call for a standard I/O pro=edure or mathematical function. Ex=ept in the case of the standard functions ~BS, ENrIER, LENGrH, and SIGN, CP61 ~enerates code which constructs a parameter list (c~ntainin3 an entry for ea=h a=tual parameter in the procedure call) in the current Data Storage ~rea, folloNed by c~de t~ l~ad a register with the address of tne parameter list and then to branch t~ the Library pr~cedure concerned, viz. L L (:DS~) (LAr) RErURN, ENrR~ P~R~~, ENrR~, S~LR The sec~nd instructi~n fetches the address ~f the Library procedure from the entry in the Label ~ddress rable whose displa=ement «LN» is specified in the last byte ~f the standard pr~cedure or fun=tion desi~nator (~ppendix III). The Library procedure is c~mbined with the Jbject module at execution time, by virtue of the ESD rec~rd generated in the Termination Phase (IEX51) for the pr~cedure name (see :P6Q above). rhe parameter list entry constructed at time fJr each actual parameter in a standard procedure or' function call consists ~f a full w~rd c~ntaining a code byte and tne address of the actual parameter (in the last three bytes). The pr~cessing of the a=tual parameters by :P61 depends, in ~eneral, In whether the call is for (1) a A call for a standard liD procedure includes two or three actual parameters. The character of these parameters and the parameter list entries constructed at object time are indicated in Chapter 11 under "Input/Output Procedures". The I/O operation involved in the standard procedure is noted in the 1/0 Table (IOT~B -- Figure 64) opposite the data set number (if any) specified by the first parameter in the procedure call. The 1/0 rable is used in the c~nstruction of the Data Set Table (see "Termination Phase" in this chapter) . 2. A call for a standard mathematical function includes but one parameter. Execution of the standard function gives an arithmetic result. For all standard function calls except those of 'ENTLER', 'ABS', 'LENGTH' and 'SI3N', CP61 generates code to construct a parameter entry in the current Data Storage 'Area for the actual parameter, and to call the relevant Library routine. In the case of 'ENTLER', the Fixed Storage Area ENrIER routine is called. In the case ~f 'ASS' " 'LEN3TH' " and 'SIGN", code is generated to perform the function in line. ~bject BefJre exit to SNOTSP, the stack operand representing the standard function designator is replaced by an operand representing the function value and pointing to the register which contains the value. Chapter 8: Compilation Phase 137 Form Y33-8000-0, Page Revised by TNL Y33-8001, 12/15/67 Figure 64. I/O Table (IOTAB) 4. The logical structure of the code generated for a for statement is 10verned by the for statement~s loop classification (Counting Loop, Elementary Loop or Normal Loop) in the For Statement Table. The ~Er Statement Table, vThich is constructed in the Scan III Phase (Chapter 6) and transmitted to the Compilation Phase via the COllL'!IOn ,york Area, contains a classification byte for every for statement in the source module. The classification byte (Figure 65) not only reflects specific logical characteristics of the for statement, but also specifies (by the pattern of bitsettings in binary positions 0-3) the for sta~ement~s loop classification. All subscript expressions contained in the for statement which are functions of the controlled variable are optimized; so also are subscripts consisting of constants or simple variables to which no assig~'!Ient is made in the for statement. All' other subscripts are not optimized. In the case of a step element, the first characteristics imply that the loop count (or number of iterations) can be calculated in advance. The formula used in computing the loop count is blO Loop Count= (Test Value-Initial Value+Step Value) Step Value Since the loon count can be computed in advance, the it~rated statement may be designed as a Branch on Count loop. The principal characteristics Counting Loop are: of the 1. The controlled variable does not occur in the iterated part of the for statement (other than in optimizable subscript expressions); 2. The for list is limited to step elements and/or arithmetic elements, and all operands in the for list are constant whithin the for statement; 3. 138 All operands in the for list are 1ntciger type. of Furthermore, since the controlled variable is not a factor in the iterated statement, no assignment need be made to it in each iteration. If the controlled variable occurs in a subscript expression (",hich must be optimizable), its contribution is pre-calculated in the form of a uniform address increment. Figures 66 and 68 illustrate the logical structure of the code generated for two Counting Loops, the first containing arithmetic elements, the second containing step elements. Form Y33-BOOO-O, Page Revised by TNL Y33-B001, 12/15/67 r-----------------------------------------,I I I BIT 0=1 if: I the for list contains a while I element the real division operator (/) I [ appears in the for list the power operator appears in I the for list I the I a real operand appears in for list I the controlled variable appears I as a right variable in the r iterated part of the for stateI ment (outside optimizable sub- I The main features of the code ed for a Counting Loop are: 1. The code sequence representing each for list element is executed once only, and the sequence terminates with a BALR instruction, \"hich branches to the iterated statement and loads the address of the next for list element. In the case of a step element, the code sequence tests for an endless loop and computes the loon count (in reqister 0), before branching to the iterated statement. 2. The code sequence representing the iterated statement, in the case of a step element, is controlled by a terminal Branch on Count instruction, which returns to the iterated statment, or, if the step element is exhausted, branches to the next for list sequence (or to the exit address). I L_________ :::~~:_::~::::~~~~~ _____________ J BIT 1=1 if: an assignment is made to the controlled variable in the iterated part of th for statement I ~-BIT-2:i-if~------------------------~----1 [ I a label or switch identifier, implying a jump out of the for statement, appears in the iterated part of the for statement I I r-BIT-3;I-If:-----------------------------l an array identifier appears in the for list a procedure identifier or a formal parameter appears in the for statement an assig~~ent is made to any for list identifier in the iterated part of the for statement j. (Anyone of these conditions qualifies the for statement as a Normal Loop. In I this case, all of bits 0,1,2 and 3 are set=l) r r-----------------------------------------~ BIT 4=1 if: the for element list contains a 1Ilhile I I------------------------------------------, BIT 5=1 if: L_________ the for :~:~:~: list contains a ";lhile _________________________ I I r-~i~-7:i-;;~~ifi~;--~h;~-~h~--fu~----ii~~-l I L--_______ :~:_~~~~~~::~~~_:~:::~ __________ J Loop Classification COUNTI1iG LOOP: Bi ts 0-3 all 0 ELEMENTARY LOOP: Bits 0-3 IiiiX:ed 1 and 0 NOmlAL LOOP: Bits 0-3 ail i Figure 65. For statement classification byte in the For Statement Table If the for statement contains subscripted variables (arrays), the addresses of the array elements are derived in each iteration (except the first) by the addition of a uniform incIement to an initial (or base address, calculated in advance of the first iteration (see "Subscript Opti;'1ization" below). Elementary Loops The distinguishing characterisitcs of the Elementary Loop are: 1. An.. assignment may be made to the controlled variable in the iterated statement (the controlled variable may also occur in the iterated stat.ement as a right variable). 2. The for list may contain real operands or expressions containing the real division or power operator. 3. Subscript expressions in the for statement are optimizable, provided no assignment is made to any variabl~ except the controlled variable, in the expression. I I I contains two or more elements. (The bit is turned on only in 3. ~ BIT 6=1 specifies that the for stateI ment contains subscript expressions to be optimized. (The [ bit is turned on only in the Compilation Phase) I 'Jenerat- If an assignment is made to the convariable in the iterated statement, its value after any given number of iterations cannot be predicted without reference to the iterated statement. This implies that, for a step element, the loop count cannot be pre-calculated, and that accordingly, the iterated statement cannot be designed as a Branch on Count Loop. A test for exhaustion of the step element, involving the test value, the step value, and the controlled. variable, must be made in·each iteration. t~olled Chapter B: Compilation Phase 139 rhis requires that the c~ntr~llej variable be incremsntei U~ the amount of the ster value in each iteration. Increme~­ tati~n oE the c~ntr~lLej variable is also required on the gro~n~ that the controlled variable naj Jccur in the iterated statement as a rj~ht variable as well as a factor in non-JP~inizable subscript exrressions. Figures 67, 6~, 73, and 73 illustrate the lo~ical structure oE the code generated f~r an Elementary Loop, the first c~ntaininJ arithnetic elenents, the sec~nd step elements, the third containing step elenents and an ~ptimizable subscript expression, and the fourth containing while elenents. 4. Since an assignment may be made b) any v3.riable in the for list, the step and test values in a step element may vary between iterations. This implies, first, that the loop count cannot be prec3.lculated without reference to the iterated statement; and second, that in eacn iterat.ion, rhe main features of the code generated for an Elenentary Loop are: 1. 2. 3. The code se~uence initiating a step element tests Ear an endless loop and stores the step and test values in t3e current Data Storage ~rea. rhe c~ntrolled variable is incremented once in each cycle of a step element, and a test for exhaustion DE the step element, using the stored ste~ an1 test values and the controlled variable, is made before a branch is taken to the iterated statement. rhe test is performed by a Fixed storaJe ;rea routine (BCR). IE tne for statement contains any optinizable subscri[it eKpressions, the expressions are optimized by deriving a uniform address increment which is added in each cycle to a pre-calculated base address. No subscript expression is optimizaole in the for statement. a. The step and test values must be calculated, b. The controlled variable must incremented, and c. A test for exhaustion of the step element must be made. be Moreover, since the step value may be a Eunction of the controlled variable, the step value must be calculated twice in each iteration, once when the controlled variable is incremented, and once Cl;:jain, immediately aft.erwards, in order to determine the sign of the step value. The latter is required in order to perform the test for exhaustion of the step elenent before branching to the iterated statement, viz: (20ntrolled Variable - Test Value) *(Sign of Step Value»O Figures 67, 72, and 73 illustrate the structure of the code generated for a Normal Loop, the first containing ari.thmetic eienents, the second containing step elements, and the third containing while elements. lo~ical rhe main features of the code generated Eor a Normal Loop are: rhe rrincipal characteristics Loop are: of 1. rhe step and test values are computed in each iteration, the step value being computed twice (once for incrementing the controlled variable, and once for determining the sign of the step value). 2. rhe controlled variable is incremented and a test for exhaustion of the for list element is performed in each iteration. 3. ~rray the ~ormal 1. ~n assignnent may be made in the iterated statement to any variable in the f::>r list. 2. rhe step value nay be a function of the controlled variable. 3. The 140 statement may contain a statement (which may change the values Jf anyone or more DE the for list variables). f~r pr~ceiure element addresses are computed by evaluating the full subscript expression(s) in each cycle (subscript optimization is not possible) • Source Text: 'FOR' V:~ 1, C 'DO' 'BEGIN ' .......... 'END' Object Code Comment Compiler Program CP6 lst Arithmetic Element Base - Constant Pool Controlled Variable (V) ~ CP40 (lmigo) reserves entries in the Label Address Table for the iterated statement address «LN - I » and the exit address «LN - X» and in the current Data Storage Area for the return address field «DISP - R». L GDSA, 0 (PBT) Initial Value (1) MVC (4, CDSA),<:DISP - 1> (GDSA) Branch and link to iterated statement { « LN - I» 2nd Arithmetic Element Controlled Variable 01) ~ Value (C) CP43 (Comma) generates code, for the first arithmetic element, to assign the initial value to the controlled variable and to branch and link to the iterated statement, loading the address of the next arithmetic element. L BRR, (LAT) t BALR BRR, BRR CP43 (122) enters CP47 at DWITERS. -MVC (4, CDSA), (CDSA) CP47 !;Jenerates an instruction for the last for list element, (which loads BRR with the exit address) as well as the first instruction in the iterated statement (which stores the address in BRR in the return address field). L BRR, (LAT) Load exit address. Iterated Statement «LN - I» Store BRR in return address field. [ST BRR, (CDSA) Load retum address a,nd branch (to next arithmetic element or to exit). (EQr) stores the for statementS' classification byte (from FSTAB) and F.S.No. in the Operand Stack. L BRR, (CDSA) { }-CP81 (tig, - operator marking the close of the for statement) generates the terminal instructions in the iterated statement. In the case of an arithmetic element, these instructions cause a branch to the next for list sequence, or to the exit address, depending on the address fetched from the retum address field. rBR BRR] Exit «LN - X» [Next instruction followina.. the end of the for statement.:.l Logical structure of the code generated for a Counting Loop containing arithmetic elements Figure 66. Source Text: 'FOR' V :~ 1, A 'DO' 'BEGIN' .•........ 'END' CP6 1st Arithmetic Element Base - Constant Pool Controlled Variable Campi! er Program Object Code Comment L GDSA, 0 (PST) 0-1) ~ CP40 (Assign) reserves entries in the Label Address Table for the iterated statement address «LN - I» and the exit address «LN - X» and in the current Data Storage Area for the return address field «DISP - R». CP43 (Comma)generates code, for the first arithmetic element, to assign the initial value to the controlled variable, to load the iterated statement address, to compute the address of the next for list sequence and store it in the return address field, and to branch to the iterated statement. MVC (4, CDSA), (GDSA) Value 1. L BRR, (LAT) Load address of iterated statement. BALR STH, 0 Compute address of next step element and store in return address field. { (For) stores the for statement's classification byte (from FSTAB) and F.S.No. in the Operand Stack. LA STH, 10 (STH) ST STH, (CDSA) BR BRR 2nd Arithmetic Element Controlled Variable 0-1) ~ Value of A. IVbve exit address to return address field. MVC (4, CDSA), (CDSA) } - L MVC (4, CDSA), (LAT) [Iterated statement Iterated Statement «LN - I». Load return oddress and branch (to next arithmetic element or to exit) I"'igure 5 7. L BRR, (CDSA) r BR BRR] [Next instruction following the end of the for statement Exit «LN - X» CP43 (12.2) generates code, for the last arithmetic element, to assign the initial value to the controlled variable and to store the exit address iii the return address field. J } - CP81 (Eta - operator marking the close of the for statement) generates the terminal instructions of the iterated statement, which branch to the next for list sequence or to the exit address, depending on the address contained in the return address field. Lo~ic~l structure of the code generated for an Elementary Loop or Normal Loop containing arithmetic elements Chapter 8: Compilation Phase 141 ~: 'FOR' V:=l 'STEP" 'UNTIL' S, 10 'STEP' 2 'UNTIL'12 '~O' A[2*V-I]:=O; Campiler Program CP6 (fw)stores the for statement's classification byte (from FSTAB) and F.S.No. in the Operand Stock. CP~ ~~~~~~.:::~!e~~'_A~:dT::~e.!rit address (J, the itep value ~DISP - ST», and the cyclical array oddress increment. CP40 also locotes the OPTAB entry for the subscript expreS5ion to b. optimized in the for statement. ~::"S~·r!=~ool L GDSA, 0 (PBT) Controlled Variable (V) '" Initiol Value (T). WC (4, CDSA), (GDSA) } - CP43 (~) generates cod., for the fint step element, to assign the initial value to the controlled variabt •• CP45 runtiJ) CP.(J cod., for the second step el.ment, to assign the initial value to the controlled voriobl •• l 3, (GDSA) St~ stacks the operator~. LTR STH, 3 Value = 01 BZ ENDLESL (FSA) ! Store Step Value. ST STH, (CDSA) A STH, (GDSA) loop Count = (Test Value - Initiol Volue + Step Value) • St.p Volue. S STH, (CDSA) SRDA STH, 32 DR STH, 3 LR 0, BRR { Branch to Test and Initiolize Entry. l BRR, < IN - 11 >(lAT) BAlR BRR, BRR "'L GDSA, 0 (FBT) Mle (4, CDSA), (GDSA) l 3, (CD5A) loop Count = (Test Value S STH, < DISP - V> (CDSA) A 5TH, < Ol5P - 12 >(GDSA) [ - Initiol Volue + Step Volue) • Step Value. SRDA STH, 32 LR 0, BRR load exit address. Test CW'td Initialize tore R in return address field. CP47 also generates the first instructions of the Test and Initialiu sequence (which store the retum address and test for exhaustion of the step element), CP47 then calls- l BRR, (lAT) ST BRR, (CDSA) Loop Count'" 01 ~Iuc;rjpt CP47 , + 4 (CDSA) L GDSA, 0 (FBT) Addend A (-I) l BRR, (GDSA) M STH, + 20 (CDSA) F * Pi + 1 lR ADR, BRR F.Pi+,*V M STH, (CDSA) Add A [0] -A*PI+l + F*Pi+,.V (= initiol address of subscripted variable) F. Pi + 1 AR , BRR lR BRR, ADR F.P j + 1 5te!) (= cyclical address inu.ment M 5TH, (COSA) Store cyclical increment ST BRR, (CDSA) Branch around subscript incrementation (first cycle only), Iterated Statement clN - I> u ript incrementohan (+F*P i + I·St~) { : Base = Constant Pool A[2.V-I] =0; L BRR, (lAT) ~ :R ::TR>; CP41 lR ADR, L GDSA, 0 (PBT) we 0 (4, ADR), < DISP - 0> (GDSA) l BRR, (LAT) BCTR 0, BRR Exit ( (CDSA) BR BRR Subscript Inc Routine generates code to add the cyclical address increment to the precalculated subscripted variable address. ': ~9~n:hi~sh 5~a!!!~yan:o~:! ~h:~~~~ =c!~y~ ~:)~ ~~~A!;s~~criPt has been optimized (CDSA) Branch on count to iterated statement, load retum address and branch (to next step element or to exit). Subscript Init Routjne makes an entry for the optimized array in SUTA8C and generates a subscript initialization sequence which computes the 1nltial address of the subscripted variable l add A [0] + 5j' Pi + I and the cyclical address increment. F * Pi + 1 • (Step Value). CPI2 (precalcu- ~) stocks the opet'Otor~. } - CP20 (E.f.g ~ 0 rotor marking the end of the for stotement) gener~ ates cZto assign the value (0) specified in the source module to the subscripted variable. t C.pBI (Eta) genet"Qtes cod. (1) to branch on count to the iterated statement and (2) to bronch to the next step element or to the exit address, depending on the address saved in the retum addreu field. [Next instruction following the end of the for statement,] Logical structure of the code generated for a Counting Loop containing step elements and optimizable subscript expression ~ subscri~t ex~ression of ~n array identifier containej in the iterated part of an enbracing for statement is jefinea to be optimizable in that for statement if the ex~ression is of the form subscript's displacement contribution in the first iteration (where V' is the initial value of the controlled variable), the displacement contribution in the nth iteration is , Sj Pi+ 1 +(n-UAsj Pi+1 =(F*V'+~)Pj+1 + (n-1)(F*Step*P j+ 1 ). ~n ±F*V±A, F(Factor) is an integer variable or V is the controlled vari~ble of the embracing for statement, and ~(~ddend) is an inte~er variable or const~nt. rwo conjitions for optimization of a subscri~t ex~ression of the above type ~re: ~here ~onst~nt, 1. rh~t the embracin~ for statement be a Counting Loop or an Elementary Loop; anj 2. rh~t no assi~nnent be m~de in the iteratej statement to any variable in the subscri~t ex~ression. In the general case, the ~djress of ~iven array element, ~[S1,S2,S3] is ~iven bV ~ny where addA[O,D,O] is the arra~"s zerobase address and Sj Pj+1is the ~roduct of the subscript and the address increment factor for the subscript position. The zero-base address and the address increment factors are obtained from the ~rr~y's stora~e M.appin~ r'ilnctioll (Figure 62 see"Arrays">' rhe~roduct SjPj+1 re~resents the contribution of the particular subscript to the displacement of the ~rr~y elenent from the zero-base equivalent form is (a) {s'Pi+1 +(n-2)Asj Pj+1 }+Asi Pj+1 = { (F*IT' +AJ Pj + 1 + (n-2) (F*step*Pj + 1 )} +F*step*Pj+1 • Equation (a) expresses the subscript optimization formula, which states that, for an optinizable subscript: 1. the change in the subscript's displacement contribution is constant in each iteration, if the change (or step) in the controlled variable is constant, and is given by ASi Pi+ 1 =F*step*Pj + 1 (called the cyclical address increment). 2. the subscript's displacement contribution in each iteration is obtained by adding the cyclical address increment, F*Step*Pi+ 1 , to the subscript's displacemen~ contribution in the preceding iteration, viz: (F*IT'+A)Pj+1 +(n-2) (F*step*Pi+1)' rhe address of the array element A[SL,S2,S3] in the nth iteration, where subscripts 51 and S2 are optimizable and subscri~t S3 is non-optimizable, may be expressed as ~ddress. in nth iteration rhe displacement contribution linear (optinizable) subscri~t form (F*V+~) is of of any the rhe ch~nJe in the displacement contribution associatej with a change (or "step") in the value of the controlled v~ri~ble V is ASj Pj + ,= ={F*(v+ste~)+A}Pj+1 -{F*V+~}Pj+1 =F*Step*Pj+1 • If the controlled variable V changes ~ constant step value in a succession iter~tions, the change in the subscri~t's dis~lacement contribution, F*step*Pi+1 , is constant in each iteration. If Sj'Pj+1 =(F*IT'+~)Pj+1 is the by of rhis states that the address of a subscripted variable containing one or more optimized subscripts is obtained in each iteration of a step element, by addin~ the cyclical address increments of the optimized subscripts, viz. ASj Pi+ 1 =F*Step*Pi+ 1 r together with the displacement contributions of the nonoptimizable subscripts, viz. siPi+1' to a pre-calculated address element, viz. the expression in braces { ••• }. The latter represents the sum of the array's zero-base address, addA[O,O,Ol, plus the displacement contributions of the optimized subscripts in the first iteration, sf Pj+ 1 = (F*V' +A) Pi+ " plus the cumulative total of the cyclical address increments, ASi Pi + 1 =F*Step*Pi+ l ' added in Chapter 8: Compilation Phase 143 the ~recedin~ iterations for all optimized subscripts. In the ~enerated object code, the optimization of subscript expressions ~omprises two phases: Subscript Initialization and Subscript Incrementation. Subscript Initialization (illustrated in Fi~ures 65 and 70) is performed before entry to the iterated statement. It consists in computin~ (in any available general purpose register =addAlO,O,OJ+s:P 3 +s:P 3 ; ani in ieriving and storing (in a field in the current Data Storage Area, in each subsequent iteration, thus Subs~ript adding <~XTR>, Incrementation consists in the cyclical address increment to thus ~ , (CDSA). Nhere the subscripted variable contains a non-optimized subscript (as in the example above). the displacement contribution for the non-optimized subscript is added to after the code to evaluate the proiuct of the full expression and the subscript increment factor. viz. s i Pi + 1 , is executed inside the iterated statement. CASE A CASE B Operator: Goto For Stack Operator: ~~lin;-§~mi£Q1Q~, QQ. Ih~~=~ or ~1~=~ Sour~e C~SE ~: See "30to Statements". CASE A: ~Q~ marks the beginning of a for statement. The operator is stacked and the Statement Context Matrix addressed. Three operand Stack entries are reserved, in the last of which the for statement's classification byte (OPTB~TE-Figure 65) and For Statement Number are stored. Source Operator: Stack Operator: Assig~ Fo~ rhe ~~~iln operator follows the controlled variable,. whose internal name has been entered in the operand Stack. ~P40 stacks the operator For:~ and reserves two entries in the Label Address rable and one or more storage fields in the current Data Storage Area (depending on the for statement's loop classification, indicated by the classification byte stored by CP6 in the stack), and stores the displacements of these entries in the stack operands reserved by CP6. rhe Label Address Table entries. in which the relative address of the iterated statement and the exit address are subsequently inserted, will be referenced by instructions generated subsequently by other compiler programs (see Figures 66-70 and 72, 73). The Data storage Area fields reserved will be used at object time for storing the return address and the conditional entry address. ~P40 also searches the optimization Table to determine if the table contains any entries for optimizable subscript expressions contained in the for statement (an entry is identified by comparing the For Statement Number previously entered in the stack by CP6, with the For Statement Number in the first byte of the optimization Table entry Figure 50). If an entry is found, bit 6 (OPTB) of the classification byte in the stack is turned on, to indicate that code to optimize the subscript expression is to be generated. Source Text: 'FOR'V :"" 1 'STEP' 1 'UNTIL' 5, 10 'STEP' 2 'UNTll' 12 'DO' 'BEGIN' ........... 'END'; Compiler Progrcm In Step E1emlOt Bose - Constant Pool. L GOSA, 0 (PBT) Controlled Variable (V) '" Initial Value (1). MVC (4, COSA), }OISP -1> (GDSA) CP6 (GDSA) Step Value'" O? LTR STH, STH BZ ENOLESl (FSA) BAlR BRR, 0 Compute and store the sign of the step value. CP45 (Until) generates code to test for crt endless loop and to sf'O'rethe step value. { 5LL BRR, 1 5T BRR, (CDSA) Store the ~tep value (l). ST STH, (COSA) Store the test value (5). MVC (4, CDSA), load controlled variable. l DISP - 5> (GOSA) STH, {COSA) BAlR BRR, 0 Compute the address of the step addition sequence and store in retum address field. LA BRR, 12 (ORR) {l CP47 (Comma) generates code to store the test value, to compute ond stare the step addition address, to branch around the i~: ~~i:!~~ :I~:.ce (for the first cycle only), and to ST BRR, (CDSA) Branch around step addition (first cycle). ~ ::H~B:R~,SP ~ Add step value to controlled variable. - ST> (COSA) A 5TH, (CDSA) ST STH, (CDSA) } - CP45 (entered from CP47) generates code to odd the step value to the controlled variable. C 5TH, (CDSA) Branch to iterated statement «LN - I» if step element not exhausted;. otherwise begin next step element (test performed by Fixed Storage Area routine BCR). ( t~e Steto~'s~~netn~ool. Controlled Variable (V) '" Ini'ial Value (10). } - CP47 (reentered from CP45) generates code to compore the controlled variable with the test value and to load the sign of the step value. l BRR, (LAT) }CP49 (entered fram CP47) generates code to load the iterated EX ADR, BCR (FSA) statement address and to invoke the Fixed Storage Area [ routine BCR, which branches to the iterated statement if L GOSA, 0 (PBT) the step element has nat been exhausted. } - CP43 (~) generates code, for the second step element, to assign MVC <[lISP - V>(4, CDSA), (GDSA) the initio I value to the controlled variable. IC ADR, (CDSA) l Step Value'" O? 5TH, (GOSA) LTR STH, STH BZ ENOLESL (FSA) 8AlR BRR, 0 { Compute and store the sign of the step value. ST BRR, (CDSA) Store the step value (2). ST 5TH, (COSA) Store the test value (12). MVC (4, COSA), (GDSA) Load controlled variable. CP45 (Until) generates code to test for an endless loop and to store theStep value. Sll BRR, 1 L 5TH, (CDSA) 8ALR BRR, 0 Compute the address of the step addition sequence and store in retum address field. [ LA BRR, 12 (BRR) CP47 (QQ) generates code to store the test value, to compute and store the step addition address, and to branch around the step addition sequence (for the first cycle only). ST BRR,(CDSA) Branch around step addition (first cycle) ~: :::;:~I:' B 12 (BRR) l STH, (CDSA) 10 cootrolled va,;abl, { A STH, (CDSA) ST STH, (CDSA) Branch to exit if step element exhausted; otherwise execute iterated statement (test performed by Fixed Storage heo routine BCR). I C 5TH, "(CDSA) XI (CDSA), X 'EO' CP47 (reentered from CP45) generates code to compore the controlled varioble with the test value. IC ADR, (COSA) L BRR, (LAT) EX ADR, OCR (FSA) I ~~nit:~::~h: fi~~ ~:~~a:~r:d~~~i~~a~~~~ ~~tchd~;:~~h;: [Iterated statement load retum address ond branch to step addition. Exit ((COSA) OR ORR] } CPBl (E.,tg - operator marking the close of the for statement) generates code to branch to the step addition sequence. [Next instruction following the end of the for statement~ Figure 69, Logical structure of the code generated for an Elementary Loop containing step elements Cha~ter 8: Compilation Phase 145 SourceText:-FOR- V:=oI'STEP'j'UNTlL'5, lO'STEP'2 'UNTlL'12 'DO- A[2*V-l] :"'0; Campi ler Program ~:;:S~~::rT:tn:nitializatian oddress in CP6 MVC (4, CDSA), (lAT) conditional entry field. - Base'" Constant Pool. L GDSA, 0 (PBT) Cantrolled vurioble IV) '" Initial Value (1). MVC (4, CDSA), (GDSA) l Step Value'" O? STH, CP40 ts-TlB):~ tFh~S ~~~~a;~~h:t3;~~~~iS~~~k~ byte (from f~L~~:7D~;;tS;:C:;et~;e~~b:~dAf:;:~~sT ~~~eOa;ft\B entry for the subscript expression to be optimized in the for statement. CP40 also generates code to store the ~~~~~~fte~~~i~d~!:;fi~~re5S (GDSA~ «LN - SI» in the con- CP43 (~) genel'ates code, for Ihe first step element, to assign the initial value to the controlled variable. LTR STH, STH BZ ENDLESL (FSA) BAlR BRR, .0 Compute and stare the sign of the slep value. CN5 (Until) generates code to lest for an endless loop and to store the step value. { SLL BRR, I ST BRR, (CDSA) Store the step value (I). ST STH, (COSA) Stare the test value (5). MVC (4, CDSA}, (GDSA) Load controlled variable. L STH, (CDSA) BALR BRR, 0 Compule the address of the step addition sequence and store in the return oddress field. Branch around step addition (first cycle). [ LA BRR, 12 (BRR) CP47 (Comma) generates code to store the test value, to compute and store the step addition address, and to bronch around the step addition sequence (for the first cycle only). ST BRR, (CDSA) B 12 (BRR) Sleo Addilian Add step value to controlled variable. l STH, (CDSA) A STH, (CDSA) CP45 (entered from CP47) generates code to odd the step volve to the controlled vorioble. ST STH, (CDSA) Branch to conditional entry address «LN 51> or {CDSA) CP47 IC ADR, (CDSA) EX ADR, BCR (FSA) CP49 (entered from CP47) generates code to load the conditional entry address and to invoke the Fixed Storage Area routine BCR, which branches to the subscript initialization sequeflce (for the first cycle) Or to the iteroted statement (for every wbsequent cycle) or to the next for li,t sequence (if the step element is exhausted). CP49 also generates code to store the iterated statement address in the conditional entry field. [MVC (4, CDSA), (LAT) L GDSA, 0 (PBT) MVC (4, CDSA), (GDSA) CP43 (~) generates code, for the second step element, to assign the initial value to the controlled variable. L STH, (GDSA) Step value O? ;:t":;d~~~~c7bl~P:flh gth:e~:~sv~~: ~~d~:r~~~ :~: ~i~~ -of the step value. L BRR, (CDSA) lTR STH, STH BZ ENDLESL (FSA) BALR BRR,O Compule and store Ihe sign of the step value. CP45 (Uu.tillgenerotes code to test for an endle" loop and to store the step value. SLl BRR, I ST BRR, (CDSA) Store the steo value (2). ST STH, (CDSA) Store the test value (12). MVC (4, COSA), (GDSA) Load controlled variable. L STH,(CDSA) Compute the address a - the step addition sequence and store in the return address field. BALR BRR,O LA BRR, 12 (BRR) CP47 (Do) generates code 10 store the test value, to compute and stare the step addition sequence address, and to branch oround the step oddit;on sequence (for the 11«1 cycle only). ST BRR, (CDSA) Branch around step addition (first cycle). Steo Addition Add steo value to controlled variable. ' 12 (BRR) __ L 5TH, (CDSA) [ A STH, (CDSA) ST STH, (CDSA) Branch to conditional entry address «LN SI>ar (CDSA) IC CP47 (reentered from CP45) generates code to compare the controlled variable with the test value and to load the sign of the step value. ADR, (CDSA) L BRR, (CDSA) [EX Load exit address ond branch ADR, BCR (FSA) L BRR, (lAT) CP49 (entered from CP47) gel1erotes code to load Ihe conditional entry address, to invoke the Fixed Storage Area routine BCR (see above), to load the exit address and branch, and to store the iterated statement oddress in the conditional entry field. BR BRR $ubscript Initializgtion ((4, CDSA), (LAT) L , + 4 (CDSA) L GDSA, 0 (PBT) Addend A (- 1). i L BRR, (GDSA) 1 (addend .. address increment Add A [0] -A"P i , 1 M STH, -I- :;:0 (CDSA) SR , BRR racIal" F 1- 2) L BRR, (GDSA) F"P i , I M STH, - 20 (CDSA) F",P i · 1 LR ADR, BRR F ... Pj " l"Y odd A [0] - A .. Pi ' 1 j- F * Pi • 1 .. V (. iniliol address of subscripted variable). ~~:~~~!i~s~r:~~~e;so~~:~~~e~~~ ~ ~~: ~ :i(~;~p).l' M 5TH, (CDSA) M STH, (CDSA) increment.) Store cyclical increment. ST BRR, iCDSA) Branch around subscript incrementotion (first cycle only). L BRR, (LAT) CP47 then geflerates code to branch around the fallowing subscript incrementotion sequence. BR BRR Iterated Statement «LN I» Subscript Incrementalion (-\ F * P * Step) : Bose -~ Constant Pool. A , DISP - IN (CDSA) Subscript Inc. Routine (entered from CP47) generates the subscript incrementotion sequence. LR ADR, l GDSA, 0 (PBT) A[2*V -IJ "0; MVC 0 (4, ADR), (CDSA) 0> (GDSA) BR BRR [Next instruction following the end of the for stotement~ Figure 70. 146 and AR , BRR LR BRR, ADR F"Pil- l ~ *c~icUa*IS~~~ress SubSCript Injt Routine (entered from CP49) makes on entry for the oplimized ,ubscripl in SUTABC and generates on initialization sequence which camp-,utes the initlol address 11 Jl CP41 ([) inspects SUTABC and sets a switch (CMT) to specify to CP69 (which normally processes the operata" "* an.d _) and CP3B ( ]) that the subscript has been optimized. See "Artays" . CP12 P20 ~) stocks the operator~. ~: :;:C~:i~r(~)a:~~h:tLl,~~~;tt:d :~i:~le~,s;gn the CPS I (ftg) generates code to load the return address and bronch to the step addition sequence. L~gical structure of the code generated for an Elementary Loop containing step elements and an optimizable subscript expression Counting Loop: Figure 68 (no code). Elementary Loop: Figures 69 and 70. Normal Loop: Figure 72. Source Jperater: Stack Operater: ~teQ, Nhil~, E2~~= Q~, or £omm~ rhe source operator follows the 1n1tial value (represented by the l~st st~ck oper~n1) to be assi~ned to the controlled variable. In every case. the operator stacked, replacing the stack !:!nti! is operator §.:!:~~. ~P45 DVH3) is also entered (at DVE2 and from CP47. See Figures 69 and 70. Ex~ept in the case of a Counting Loop no subscript expressions (in:li~ate:l by bit 6, OprB, in the for statement's classification byte), code is ~enerated (by branching to CP20) to assi~n the initial value to the controlled variable (Figures 67-70 and 72, 73)' containing Depending on the source operator and the loop classification, code is then generated as illustrated in the figures in:licate:l below. ~omma (end of an arithmetic element) ---Counting Loop: Fi~ure 66. Elementary or Normal Loop: Figure 67. Elementary Loop (with optimization): Figure 70. Do (end of an arithmetic element and of the for list) ~ounting Loop: CP47 is entered at ~WIT~RS. Figure 66. Elementary Loop: Figure 67. st~ Counting or Elementary Loop: Figure 69-70 (no code). ~ormal Loop: Figure 72. ~t!gs Elementary or Normal Loop: Figure 73. rhe stack operand representing the initial value of the controlled variable is released, and, except in the case of the ~omma, the source operator is stacked:--- Source Jperator Stack Jperator ~nti! is preceded by the step value, represented by the last operand in the stack. Depen:lin~ on the for statement's loop classification, code is generated as illustrated in the figures indicated below: Co~iler Program No.47 (CP4Il Source Operator: Comma or Do Stack Operator: Until The source operator is preceded by the test value, represented by the last stack operand. Depending on the for statement's loop classification., code is generated as illustrated in the figures indicated below: Counting Loop: Figure 68. The figure illustrates a Counting Loop containing step elements and an optimized subscript expression. As indicated in the figure" the subscript 1n1tialization and subscript incrementation sequences are generated at the end of the for list (indicated by Q~) by entry to the subscript Initialization Routine (DWG3) and the Subscript Incrementation Routine (OVAl) see below. Where subscript optimization is not required (Bit 6 of the classification byte = 0), these routines are not entered. Elementary Loop: Figures 69 and 70. Both figures illustrate a Counting Loop containing step elements, but Figure 70 shows a counting Loop containing in addition an opt imiz able subscript expression. As indicated in the figures, CP47 enters CP45 (at DVE2 or DVH3, depending on whether the controlled variable is integer or real) and exits to CP49 (at EMG1). The latter calls the subscript Initialization and Incrementation routines, where necessary. Normal Loop: Figure shows that CP47 EMG1) • 72. The figure exits to CP49 (at CP47 is also entered (at DWITERS) from CP43 (Figure 66). Chapter 8: Compilation Phase 147 Source )perator: :omma or Stack )perator: Whil~ (indicated by the source operator QQ). when it is determined (by inspection of bit 6 of the for statement's classification byte 'OPTBYTE" entered in the operand stack by CP6) that the iterated statement contains a subscript expression to be optinized. On recognition of the operator For, CP6 will have located the first of or more entries in the optimization Table (Figure 50) representing the subscript expression(s} to be optimized in the for statement. D~ one rhe source operator is preceded by a expression, representing the condition specified in the ~hile element. rhe for statement must be an Elementary or Normal Loop. Figure 73 illustrates the co:le ~enerated for either of these loop classifications, ~here the source operator is Q2, narking the end of the for list, and ~here the for statement (an Element~ry Loop) contains no optimizable s~bscript eKpressions. rhe code generated in the case of the ~~~~ operator is identi~~l, ex~ept that the address loaded before the conditional branch is that of the iteratej statement. Where an Elementary Loop contains optinizable expressions, the code generated by the suoscript Initialization and Incrementation ro~tines (US~l and UV~l -- see below), on call from CP~9 is similar to that illustrated in Figure 70. boole~n rhe Subscript Initialization Routine constructs an entry in the Subscript rable-C (SUr~BC), Figure 71, for every subscripted variable containing optimizable subscript expressions represented by entries in the Optimization rabIe, provided no previous entry was made for the same subscript in an enclosing for statement or in the current for statement, and generates a subscript initialization sequence (see "Subscript Optimization" above, and Figures 68 and 70). subscript Table-C is referenced by CP41 and CP38 (see "Arrays"), which are entered ~henever the operators [ and Comm~ in a subscripted variable are encountered. Its function is to enable CP41 and :P38 to identify the subscript expressions (if any) in a subscripted variable which have been optimized, and, if ~ny subscripts have been optimize~ to enable CP38 to locate the stack operand which specifies the object time register «NKrR» containing the pre-calculated array element address. :P49 is also entered (at EKIrERS) from CP43 and (at EM31) fron CP47 (see Figures 6 9, 7 0 a nj 7 2) • rhis routine is entered from CP47 and :P49 at the close of a for list o 1 7 4 2 9 r-----~----T-------------T-----------------T--------------1 III I _________________ operand> position key> JI i I ______________ ~ = <~ddress of stack oper~n:1> Figure 71. 148 Entry in above>
(16 bits representing subscript positions 0-15. Bit=l if the subscript has been optimized.) 5~bscript rable-C (SUT~BC) ~: 'FOR" V:= 1 "STEP' 1 "UNTIL" 5,10 "STEP "2 'UNTIL" 12 "DO' 'BEGIN •.•.....••• ·END Complier Program CP6 {4, CDSA), (GDSA) o (PBT) }CP4D the CP4l (~Ii!) generates code, for the first element, to ossign the initial value to the controlled variable and to comPJte and store the: return address. BAlR STH, 0 ComPJte the return address and store in the { retum odd...s field. ~FeJ~:!~:~sn~a::s~n(~N~~t:;:heT::~!d~~~ ~~~ :Id~~sar;i~li~ (~tsprr~~~~ta Storage Are for LA STH, 8 (STH) STH STH, (CDSA) L GDSA, 0 (PBT) L STH, (GDSA) LTR STH, STH BALR BRR, 0 Compute and store the sign of the step value BNZ B(8") SR BRR, BRR BCR BRR, 0 Sll BRR, 1 P45 ST BRR, (CDSA) c:remented. { Add the step value to the conh'olled vori- { Branch to compute the sign of the step value agoin, before testing for exhaustion of the step element .. { Bypou the step addition sequence when the ~ift~r~h~~:i,~u:CI~s,:bl~~=~~Irnable. \ ~;~!I~~e;~t~d~:: t~nt~;t~~tt~i l:rv::i~~ie, :e;a::u:e and to compute the sign of the step value again. l BRR, (LAT) XI (CDSA) ST 5TH, (CDSA) L BRR, (CDSA) CP47 (~) generates code to compare the controlled variable with the test value and to load the sign of the step value. C STH, (GDSA) B,.nch to the ae",ted ,tatement ( -, B,",( if the step element is not exhausted; other- IC ADR, (CDSA) wise begin the next step element. l BRR, (LA T) [ t~. ~G~~:~n~ool. CP49 (entered from CP47) generates cade to load the iterated statement address and to Invoke tne Fixed Storage Area rautlne BCR, which branches to the iteroted statement if tne step element hos not been exhausted. EX ADR, BCR (FSA) L GDSA, 0 (PBT) Cont.:olled variable (V) = Inltiol Value (10) MVC (4, CDSA), (CD5A) Compute and store the retum address. LA STH, 8 (STH) BALR STH, 0 CP4l ~ generates code, for the second step element, to assign the initial value to the controlled variable and to compute CX'Id store the return address. 5T 5TH, (CD5A) L GDSA, 0 (PBT) l 5TH, (CD5A} LTR STH, STH BALR BRR, 0 BNZ 8 (8RR) ComFUte and store the sign of the step value . 5R BRR, BRR BCR BRR,O SlL BRR, 1 5T 8RR, (C~SA) CP45 !~:~!Pu~~e~~t~dd~~: ~e~;a1u~et:tt!t~~tt~il!!r~:~~~ie, and to compute the sign of the step value again. Bypass the step addition sequence when the { SIgn of the step value is computed again after the controlled variable has been incremented. Add the step value to the controlled variable. Branch to comPJt. the sign af the step value again, before resting for exhaustion of the step element. { l BRR, (LAT) XI ~ BCR (CDSA), X 'SO' 4, BRR A STH, (CDSA) ST 5TH, (CD5A) l BRR, (CDSA) -BR BRR L STH, (CDSA) SI (GDSA) XI (CDSA), X 'EO' CP47 (119) generates code to compare the controlled variable with the test value, to invert the sign of the step value CX'Id to load the inverted sign of the step value. IC ADR, - (CD5A) l BRR, (lAT) EX ADR, BCR (FSA) '.terated Statement (): Load return address and branch. [Iterated statement l BRR, (CDSA) BR BRR] Exit ( (4, CDSA), (GDSA) Store the Assign and Test oddress in the return address field. MVC (4, CDSA), (LAT) Test if B is true. TM (CDSA), X '01' Load the exit address. L BRR, (LAT) Branch to exit if B is false. CBCR 8, BRR }- ~ (For) stores the for statement's classification byte (from FSTAB) and·F.S.No. in the Operand Stack. CP40 (Assign) reserves entries in the Label Address Table for the Assien and Test address «LN - AT » and the exit oddress «LN - X» and in the current Data Storage. Area for the return address field «D1SP - R». CP43 CP49 <'Ml.ilJ:) generates code to assign the value specified to the controlled variable and to store the Assign and Test address in the return address field. (~) generates code tO,test t.he condition s.pecified in the if the wnile element and to enter the iterated statement condition is true or to branch to the exit address if the condition is false. [ Iterated statemen t Load the return oddress and branch to Ass ign and Test. Exit «LN - X>l L BRR, (CDSA) } - CPSI BR BRR] (~- operator marking the close of the for statement) generates code to branch ta the Assign and Test sequence. [ Next instruction following the end of the for statement .] -Figure 73. Logical structure of coc.e generated for Ele."TIentary Loop or Normal Loop containing a while element Initially, a search is made to deterif SUTABC contains any entries (indicating one or more optimized subscripts in an enclosing for statement) and, in this event, if there is an entry for the same subscripted variable (determined by comparing the record number and relative address in bytes 11-13 of the OPTAB entry previously located by CP40, with bytes 1-4 of the SUTABC entry). The action taken depends on the result of this test: mine 1. No entry for the subscripted ble is found in SUTASC. varia- A new entry is constructed in SUTABC, the contents of bytes 11-13 of the OPTAB entry bein~ copied into bytes 1-3 of the SUTABC entry, the current For Statement Number into byte O. An object time register «NXTR» is reserved in vlhich the pre-processed arrav element address will be calculated,~and the address of a stack operand representing the pre-processed address is entered in the SUTABC entry. Coc.e is generated to load ~~XTR> the array~ s zero-base address (addA[O,O,OJ), the address of the ,"Ii th 150 Storage Happing Function being obtained from the OPTAB entry. array~s (Figure 62) For every OPTAB entry ,"hich contains the same address data in bytes 11-13 (all such entries representing optimizable subscript expressions of the same subscripted variable), the corresponding bit in bytes 7 and 8 of the SUTABC entry is turned on (to specify the optimized subscript position) and code is qenerated to add the product (Addend) * (Address) Increment Factor), A*Pi+l to and to add the product (Factor) * (Address Increment Factor), F*Pi+l to ADR. Hhen all of the OPTAB entries for the Sfu~e subscripted variable have been processed in this way, code is generated to multiply the contents of ADR by the initial value of the controlled variable and to add the result to NXTR, which now, contains the quantity addA[O~O,O]; A*?i +l+L(F*ll+i)*V' • Code ~s tnen generated tOffiultiply the contents of ADR by the step value and to store the result, (F*P i+l)* Step, representing the =y=lical a11ress increment, in the current Data St~rage Area. If any other oprAB entries are found relating t~ an~ther subscripted variable in the current for statement, a ne~ SUT~B: entry is constructe1 and the pre-processed address and cyclical address incre~ ment are computed in the manner described. 2. An entry the same subscripted is found in SUTABC. rhis indicates that a subscript initialization sequence ~as generated in an en=losin~ for statement for one or more subscripts ~f the same subs=ripted variable. In this case, the sane sur~B: entry is used, the =ontents of byte 0 being overNritten ~ith the current For statement Number, and code is generated to l~ad ~ith the previously calculated array element addreSS, namely ~n assignment statement is implemented essentially by a MOVE instruction or a STORE instruction, whose effect is to transfer the value of the expression to the right ~f the assignment operator to the Data Storage Area field of the operand to the left ~f the assignment operator. The expression on the right may be f~r ~ariable add 7\[0, 0, O]+~A*Pi+'t +~(F*Pi+1 This routine is entered from CP47 and CP49 Nhen address incrementation is required for one or more optimized subscripts (the for statement contains a step element). :~de is generated to add the =yclical address increment, ~(F*Pi+1 )*Step, t~ the pre-processed array element address. See Figures 68 and 70. N~.81 a simple variable or a constant whose ~bject time value is contained in a Data storage Area field, or 2. a complex expression, whose value may be contained in a register or a Data Storage Area field. Compiler Program No.12 (CP12) )*V'. rhe object time location of this pre-processed address is determined ~ith the aid of the operand address in the surABC entry. compiler Proqran 1. Source Operator: Assign Stack Operator: Beg!.!!, Semicolo!!, Elsg::.§, or QQ ~ben-s" The source operator identifies the beginning of an assignment statement. CP12' s function is to test the characteristic ~f the left variable (represented by the stack operand) for assignability, and to stack the Assign operator. If the operand is a formal parameter, in which case assignability can only be determined at object time, CP12 generates code to check for assignability by inspecting the characteristic in the relevant actual parameter code sequence (see nprocedures n ). Thereafter, a call is made to OPDREC ~hich generates code to call the actual parameter. (CP~l) Source )perat~r: Eta Stack Operator: QQ Eta marks the close of the current for statement. CPBl generates the terminal instructions of the iterated statement (see Figures 66-7J and 72, 73) and deletes all entries in SUTABC. All stack operands relating to the current for statement are released and the operator Do is released. Source operator: Assign Stack Operator: Assi9!! rhe operators identify assignment, e.g., a:=b:=c. a multiple Jnless one or both of the last two stack operands are all-purpose operands, control is passed to CP12, in which the last operand is tested for assignability. The operand before last will have been tested previously. Chapter B: Compilation Phase 151 Source O~entor: St~ck O~erator: ~g!!!!£Q!sm, ~J2~!'!Qg, Et~, End or Else ~~si~n ---- rhe combination of source and stack operators indicates the end of an assignment st~tement. The last two stack operands re~resent the operands to the left ~nj ri~ht of the assignment o~erator. 2P20's function is to determine if the operands are conpatible (i.e., real-real, integer-integer, real-integer, or integer-real, or boolean-boolean) and, if one is real and the other integer, to ~ener~te ~ call to the appropriate Fixed Storage Area routine to convert the right operand to the same ty~e as that of the left operand. rhe callI where required, is generated by rRINR& or rRREIN. If both operands are boolean, and if the ri~ht operand is a boolean constant, the assignnent of the value of the right operand to the left variable is implemented by an MVI instruction. In all other cases (i.e., where the operands are a combination Of real and/or integer, or where both operands are boolean, the right operand being a boolean variable), the assi~nment is implemented by entry to the Real-Real or Integer-Integer routine 152 of Compiler Program No.69 (CP69). The latter routines generate code to store (or move) the value of the right operand (de~ending on whether the latter is contained in a register) to the Data Storage Area field of the left variable (the object-time address of which is contained in the stack operand before last). A boolean assignment is handled by the Real-Real routine/, which generates the necessary move instruction (in the object code, boolean operands are at no point loaded into registers). At re-entry to CP20 from CP69, the operator is release~, and unless the preceding stack operator is For, ~I or Assi:Ig" control is passed to --COMP" after the last two stack operands have been released. rhe operator [QE indicates that 2P20 was entered from CP43 for the special case of an assignment to the controlled variable in a for statement (see CP43 under "For Statements"). The operator indicates another special case, in which CP20 is used in the generation of code for an array declaration (see :P51 under "Arrays"). The operator Assiqrr indicates a multiple assignment, e. g., a:=b:=c" where the assignment a:=b remains to be implemented. rhe remaining assignment is generated by branching back to a point (BIE4) within CP20, after moving the last operand downward (replacing b by c) so as to specify the equivalent assignment a:=c. Assi~!! * rue implement~tion of a conditional statement in the code generated by the compiler may be denonstrated by the following example: ••• i 'IF' 'IF' B>::: 'ra:E:N' A.: =B+C 'ELSE' A.: =B-Ci ••• 3tore occupied registers > 'rHE;:iI' E;valuate (B>:::). store True or Fals~ in Data storage-Area field. Branch to E (below) if B>C is ~~!.~g := + :::om[;lute (B+C) 'E:LSE:' 3tore (B+C) ~t A. Branch to F (below) := E: ::ompute (B-C) F: store (B-C) ~t A. [Next instruction] CPS stacKS If-s and switches to EXC CP67 stacks> CP69 releases > CP78 replaces If-~ by rh~~=§ and switches to P:;C CP12 stacKS A.ssign CP22 switches to EXC CP66 stacKS + CP69 releases + CP70 switches to STC CP7i switches to PGC ::P20 releases A.ssiq~ CP17 replaces Th~ by g!~§ CP12 stacks ~ssign CP22 switches to EXC CP66 stacKS - (minus) CP69 releases - (minus) CP70 switches to STC CP70 switches to PGC CP20 releases ~siq~ CPiB releases El~ rhe symbols E:KC, PGC and src represent, respectively, the Expression Context Matrix, the program ::ontext Matrix, and the Statement Context Matrix (Appendix V). The special operators If~~, Iuen-s, and E:lse-§ (see Appendix I-d) identify the delimiters 'IF', 'rHE:N', and 'EL3E' as rel~ting to a conditional statement. ~s opposed to the same lelimiters occurring in boole~n or conditional expressions. Chapter 8: Compilation Phase 153 ~t entry to CP78, the stack operand addresses a Data Storage Area field in which the value of the boolean expression will be s~ored at object time. Source )perator: If Stack Operator: ~~9!ll, §gID!£Q!Qll, Else-s, or Q~ In the context identified by the operator, !! marks the beginning ~onjitional statenent. Before control is returned to SNOT, the stack operator 1!=2 is replaced by Then-s and the Program Context Matrix is addressed. stack of a C~SE B: See "Conditional Expressions". ~fter stacking the operator !f-~ and addressing the Expression context Matrix, a call is made to the CLE~RRG subroutine, whi~h ~enerates code to store all objecttime registers in use. Source Operator: Else Stack Operator: Then=2 EI~g precedes the second alternative a conditional statement. CASE A Source Operator: Stack Operator: C~SE ~: If=~ in CASE B If Then narks the end of an if clause ('IF' (boolean expression) 'rHEN') in a conditional statement. Code is generated to test the value of the preceding boolean expression (which nay be a boolean variable or constant, a boolean function designator, a relation or a more complex boolean expression) and, if the value is False, to branch to the first instructi;n representing the alternative statement following 'ELSE' (or if there is no alternative statement, to the first instruction representing the next sequential statement). rhe branch instruction references an entry in the Label Address rable (reserved by CP78) in which the relative branch address will be stored by CP17. unless the boolean expression preceding 'THEN' is a simple boolean variable or constant, code will have been generated by other compiler prograns, before entry to CP78, to evaluate the expression. CP17 replaces the stack operator rh~=2 by ~!se-2 and generates code to branch around the immediately following sequence representing the second alternative statement. The code references a new entry in the Label ~ddress Table in which the relative branch address will be stored by CP18. CP17 also stores the relative address (PRPOINT) of the second alternative code sequence in the Label Address Table entry (addressed by a stack operand) previously reserved by CP78. Source Operator: Stack Operator: ~!gQlon, Epsilon, Eta, or End Then-s or Else-s rhe source operator marks the end conditional statement. of a CP18 releases the stack operator, stores the displacement (PRPOINT) of the next object code instruction in the Label Adress Table entry reserved by CP17 (or CP78), and exits to COMPo fhe implementati~n Jf a conditional expression in the code generated by may be demonstrated by the following example: ••• ; ~:=B+('IF'B>:'THgN':'gLSE'-C); := + , IF' , fHEN' , EL3E' store occupied registers Evaluate (B>C). Store True or r~l~~ in Data Storage-~rea field Branch to E(below). if (B>:) is False Load C. Branch to F (below) - (minus) ) E: Loa:! -: Transfer -: to same register as C F: :ompute (B+/-:) 1\.: =(8+1-:) Compiler ••• Compiler > the Pro9:E.~!!! CP12 stacks ~ssiqn CP22 switches to EXC CP66 stacks + CP64 stacks ( CP80 stacks .H. :P67 stacks > CP69 releases > CP78 replaces If by Th~ CP87 replaces Theg by Els~ CP66 stacks - (minus) CP69 releases - (minus) CP79 releases El~~ CP68 CP69 CP70 CP71 CP20 releases releases + switches to ST: switches to PGC releases ~sign The abbreviations EX:, ST:, and PGC represent the Expression Context Matrix, the Statement Context Matrix and the Program Context ~atrix, respectively. Chapter 8: Compilation Phase 155 Source CASE A Operat~r: Jperator: St~ck See Source Operator: Stack Operator: C~SE ~: C~SE B: See "Standard Procedures". "Pr~cedures". CASE C: rne source operator precedes a conditional, bo~lean ~r arithmetic expression. rhe source operator is stacked. Source Jperator: If stack D~erator: yrhe c~nbination of operators indicate that 1£ opens a conditional expression enclosed by parentheses. Code is generated, by call to CLEARRG, store all occupied object time registers, ~nd If is stacked. t~ Source Operat~r: St~ck Jperator: opens a conditional expression. If is stacked and the ~xpression context ~atrix is addressed. CASE A Source Jperat~r: If ~r stack Jperator: If-or ~f~§ C~SE 156 !~ CASE A: See "Conditional Statements". CASE B: follows a boolean expression in a conditional expression. rh~u CP78 generates code to test the value of the immediately preceding boolean expression and to branch to the first instruction representing the second alternative expression following 'ELSE', if the value is K~b~. Unless the boolean expression consists solely of a boolean variable or constant, code will have been generated, before entry to CP78, to evaluate the expression and to store the value in a Data Storage ~rea field. The object tine location of the stored value is addressed by the stack operand. rhe generated code references a new entry in he Label Address rabIe, in which the relative address of the alternative statement will be subsequently stored. Before exit to SNOT, the stack operator If is replaced by !heU. If CASE B Not (See Expression context f.latrix -- App. V-c) If opens a conditional expression inside an if clause. If is stacked. B: See "Boolean Expressions". Source Operator: Else Stack Operator: Then ~1~~ follows a designational, arithmetic or boolean expression representing the first alternative in a conditional expression. CP87's function is to ensure (by generating the requisite object code), that: for designational expressions, the address value of the expression is loaded in ~DR. for arithmetic expressions, the value of the expression 1S loaded into a fixed pOint or floating point register, depending On whether the value is integer or real. for boolean expressions, the value (True or False> of the expression is stored in a~IeId in the current Data storage 1\.rea. Nhere the ex~ressi~n is complex, code will h~ve been ~enerated, before entry to :PS7, to evaluate the expression, ~nd in this ~~se, the value or address will already be contained in the appropriate re~ister or Data Storage ~re~ field. If however, the expression is a simple label, an arithlletic c~nstant or variable, or a b~ole~n constant or variable, CPS7 generates a Load ~r M~ve instruction. In all ~~ses, the expression is represented by the stac~ operand pointing to a Label ~ddress r~ble entry, a Data Storage ~rea field, or a register. 2P37 ~lso 3enerates an unconditional the second alternative expression which follows 'ELSE'. The code referen~es a new entry in the Label Address rabIe, in which the relative branch address will subsequently be stored by CP79. In addition, CPS7 stores the displacement (PRP)I~r) of the next object code instruction in the Label ~ddress rable entry ~reviously reserved by CP7S, representing the address of the second alternative expression. Before exit to SNOr, the stack oper~tor ~~~n is replaced by EI~g. br~ncn ~rounj Operator: (See Expression Context Matrix -- ~pp. V-c) Stack )perator: Else Sour~e rhe source operator marks the end of a expression. It is preceded by a designational, arithnetic or boolean expression representing the second alternative expression. ~onjition~l 2P79's function is: 1. to ~enerate the necessary object code such that, if the condition following 'IF' is f~b~g, the address or value of the second alternative will be loaded in the sane register (ADR in the case of ~ desi~national expression), or moved to the same Data Storage Area field as that specified in the coding for the first alternative expression (see CPS7 above); and 2. to generate, if necessary, a call to the Fixed Storage ~rea integer-real conversion r~utine, in the event one of the alternative expressions is real and the other is integer. rhe two alternative expressions are represented by the last two stack operands. ~t exit from CP7~, these operands are replaced by a single operand which address- es the object time register or Data Storage Area field in which the address or value of the particular alternative expression (depending on the condition identified at object time) will be contained after evaluation of the complete conditional expression. Finally, the displacement (PRPOINT) of the next object code instruction is stored in the Label ~ddress Table entry specified by an operand previously stacked by CPS7, representing the address of the unconditional branch following the first alternative expression, and the stack operator Else- is released. Object time boolean operations (specified in the source module by the operators '~ND', 'OR', 'EQUIV', and 'IMPL') are performed in fields reserved for intermediate results in the current Data Storage ~rea (in the listing these fields are referred to as "Object Stack entries") • When code to implement a boolean operator is to be generated, a test is first made to determine if the first operand constitutes: 1. a logical constant or a declared lean variable, or 2. an intermediate boolean value. boo- If the operand is a logical constant ('TRUE' or 'F~LSE') or a declared boolean variable (as in X'AND'Y), a field is reserved in the current Data storage Area (by incrementing pointer P -- see Figure 54) and code is generated to move the operand to the reserved field and to perform the specified boolean operation in that field. If, however, the operand is an intermediate logical value, representing the value, say, of a relation (as in A>B'AND'C>D), the generated code will execute the specified boolean operation in the Data Storage Area field containing the intermediate value. rhe operators 'AND' and 'OR' are implemented directly by the corresponding machine instructions. 'EQUIV' is implemented by the combination Exclusive Or (inversion) and Or. 'IMPL' is implemented by interchanging the operands and by Exclusive Or (inversion) and Exclusive Or. Where the second operand is a logical constant (whose value is known at compile time), the object code utilizes immediate i nstructi ons. Chapter 8: Compilation Phase 157 Comeiler Pro~ram ~o.64 (CP64L Source )perator: Stack )perator: (See decision m~trices -- Appendix V) CP76 generates code to perform the specified operation in a current Data Storage Area field~ and releases the stack operator. At exit to COMP, the stack operand addresses the Data Storage Area field in which the result (True or False) of the operation will be contained at object time. CASE A: See "Procedures". CASE B: See "Standard Procedures". CASE C: rhe source operator precedes an arithnetic, boolean or conditional expression. rhe Expression context Matrix is addressed and the source operator stacked. Source )per~tor: St~ck )perator: CASE A CASE B If Not If-or If~ (See-Expression Context Matrix --Appendix V-c) Source Operator: (See Expression Context Matrix -- App. V-c) stack Operator: ~ rhe source operator is preceded by a boolean operand (a constant, a variable or a complex expression) to be operated on by the stack operator ~Q!. CP77 generates code to invert the logical value of the operand in a current Data storage Area field, and releases the operator ~. CASE A: See "Conditional Expressions". CASE B: The logical operator No! identifies a boolean expression. ~Q! is stacked. Source Operator: Stack Operator: (See decision matrices -- Appendix V) CASE A: See "Procedures". Source St~ck Oper~tor: Operator: (See Expression Context Matrix -- ~pp. V-c) (See Expression Context Matrix -- App. V-c) rhe source operator (which may be an or relational operator or any one of the lO:Jical operators ~!!;'!. Qr, ~g~i~, or Imel) is stacked. ~rithmetic Source Operator: Stack )perator: (See Expression Context Matrix -- App. V-c) AnQ, Q~, ~l~iY, or I~2± rhe source operator indic~tes that the operation specified by the stack operator, between the boolean operands represented by the last two stack operands, may be implementei. 15B CASE B: See "Code Procedures". CASE C: rhe source operator precedes an arithmetic, boolean or conditional expression. The Expression Context Matrix is addressed and the source operator stacked. Source Operator: + or Stack Operator: ,~,= and Real-Integer Power Routine (I1B1) First operand real, second operand integer. Operator: Po~. for A.rithllletic o!?erators: +, -,." /, and +~el:ition:il Integer Power Routine (IUB1) Both operands integer. Operator: Po~er. Real-Real Routine (DHEB2): First operand real, second operand real or integer. Operator: any relational operator. If the second (or last) operand is integer., a call is generated (by the TRINRE subroutine) to the Fixed Storage Area routine CNVIRD for integer-to-real conversion. No.69 (2P69) :P69 handles the leneration of code all of the following: Integer Multiplication Routine (IPB1) Both operands integer. Operator: *. * Real Power Routine (HOB1) Second operand real, first operand real or integer. Operator: Pow~~. If the first operand is integer, a call is generated (by the TRINRE subroutine) to the Fixed Storage Chapter 8: compilation Phase 159 ~rea rJutine 2NVIRD for integerto-real conversion. ~fter code tJ iDpleDent the Jpe~ation has been generated, operator and ope~and in the ~eleased, and (except in the indicated the last Stack are case of an assignment) the stack operand originally representing the ope~and to the left of the sta~k operator is modified to specify the object tine registe~ o~ Data Storage Area field ~ontaining the result of the operatiJn implenented. rhis ~outine generates code, on call from CP69, to inplenent the arithmetic Jpe~ato~s + and , and the relational operatJrs <, ~, >, ~, =, and *, connecting tNO integer ope~ands. It is also entered f~o~1 2P20 for normal assignments (see "~ssignnent statenents") and f~om CP51 (see "~~~ays") • Ex~ept in the case of relational operators, Jbject tine Jperations are performed in ~egisters, and the routine handles the generation of object code to load an operand (where neither operand is contained in a register) by calling the appropriate sub~outine in the Subroutine Pool. In the case of relational operators, a compare instructiJn is generated first and a ~all is then made to the Relational si~broutine (IMB1), which generates code to nove the value rrue or False (X'01' or X'OO'), dependin~--on the--condition code set, to a field in the current Data Storage ~re'i. In the case Jf an assignnent operator, a o~ move instruction is generated. stJ~e rhis routine gene~ates code to implement the ope~ator + connecting two integer operands, on call fron 2P69. Befo~e generating code to implement the division operator, tests are made and appropriate object code generated, to ensure that the first operand is loaded into an even-numbered register and that the next odd-numbered ~egiste~ is free. 160 rhis routine generates code to implement the operator * connecting two integer operands, on call from CP69. Before generating code to implement the multiplication operator, tests are made and appropriate object code gene~ated, to ensure that one of the operands is loaded into an odd-numbered register and that the other operand is loaded into the preceding even-numbered register. rhis routine implements the power operator connecting two integer operands, on call from CP69, by generating a call to the standard Power function (Load Module IHIFII) in the ALGOL Library (Chapter 10). The code generated consists in part of instructions which store the object time add~esses of the two operands (base and exponent) in a parameter list in the current Data Storage Area, in part of a calling sequence, which loads the address of the parameter list and branches to the standard Power function. rhis routine generates code, on call from Cp69, to implement the arithmetic operators +, -, *, and / and the relational opera tors <, s, >, ~" =, and connecting two operands, one (or both) of which is real (before entry, code will have been generated to convert the non-real operand, if any). rhe routine also generates code to implement an aSSignment, on call from CP20 (see "~ssignment statements"). The implementation of operators is similar to that of the Integer-Integer Routine, as regards a~ithmetic as well as relational operators, except that floating point registers are used. * rhis routine implements the power operator connecting a real operand and an integer operand, on call from CP69, by generating a call to the standard Power function (Load Modul e IHIFRI or IHIFDI, depending on whether the precision of the base is short or long) in the ALGOL Library. The code generated is similar to that generated by the Integer Power Routine (see above). rhis r~utiae inplenents the p~~er operator c~nnecting tw~ re~l operands, on call from CP69, by generating a call to the standard Power function (Load Module IHIFRR or IHIFDD, depending ~n whether the precision ~E tne b~se is short or long) in the ~LG)L Library. rhe c~de geaer~ted is simil~r t~ th~t ~ener~ted by the Integer Power R~utine (see ~bove). Source Operator: Semicolon, orEnd--- Stack Operator: ~E§~!2Q" ~:l::~ sem!£Q!2Q rhe source operator ends a statement in a block, a procedure, a for statement or a compound statement. If the source operator is a Semicolon., the SCHDL subroutine is call ed;--otherwis e the Semicolon in the stack is released. Source )perat~r: ) St:l.ck Operator: ( rhe source oper~tor marks the close of :in :irithmetic, boolean or conditional expression enclosed by parentheses. rhe st:l.ck operator is rele~sed. Source Operator: For, Goto, If, [, ( or ASSig-n--- -Stack Operator: Bet~, Pi, Phi The source operator identifies the first statement in a block or a procedure. A ~g~~~Q!QQ is stacked to ensure that, if a declaration is subsequently encountered, an err~r will be recorded by CP28. S~urce St:l.ck Oper~tor: Oper~tor: Qg!~~ ~g~~, E~ or CONrExr SWIrCHING Eh~ represents the semic~lon termin~t­ :l. declaration or a specification. A call is made to the SCHDL subroutine, which upd:l.tes the Semicolon 20unt at SCSC and, if the rEsr ~pti~a is specified, generates a c:l.ll to the FiKed St~raJe ~re~ rRACE routinE. Delt~ in~ Source )perator: Senicolan Stack )perat~r: Beta, Pi, Ehi or ~g~in rhe ~~~i£Q!QQ marks the end of the first stateneat in a black, procedure or compound statement. rhe Senicolon is stacked (to ensure th~t, if--~-further declaration follo~s, an error will be rec~rded by CP28) and the SCHDL subroutine is called (see CP24 :l.bove). If the Semicolon was preceded by an operand (in whi~case- the operand logically represents a call for a parameterless procedure), a call is m~de to the PLPRsr subroutine (~hich generates the appropriate procedure call or records an error) :l.nd the operand is released. Each the three decision matrices specifies the set of compiler programs to be entered for all possible pairs of s~urce-stack operators within a particular context of the source module, ideatified as a program context" a statement conteKt and an expression context. As soon as a change in context occurs (signified by one or more critical source operators), a corresponding change in decision matrix is indicated. The appropriate change in matrix is effected by a partiCUlar compiler program specified in the currently operative matrix. (See n Decision Matrices" in this chapter). After the change has been effected, control is in every case passed to COMP, which branches to the compiler program specified in the new matrix for the original operator pair. (~ppendix of ~ Source Operator: If Stack Operator: Assi~ Cha~ter 8: compilation Phase 161 ~ change fron program to statement context is indicated. The statement context Matrix is addressed. LOGIC~L ERROR RECOGNITION The following compiler p~ograms are entered on detection of operator/operand sequences ~hich are logically or syntactically incorrect. Their function is Source )perator: arithmetic, logical or relational operator) Stack Operator: ~~~!IU 1. to record the error in the Error Pool; 2. to s~itch the Compiler to Syntax Check Mode (see Chapter 9), or, in one case (CP84), to terminate compilation; and 3. to make appropriate adjustments to the operator/Operand Stack, so as to permit syntax checking to proceed. Errors are recorded by a branch to the Error Recording Routine, ~hich also s~itches to Syntax Check Mode. (~ny ~ cnange from program to expression context is indicated. The Expression Context ~atrix is addressed. Source 8perator: (Any arithnetic, logical or relational operator) Stack )perator: (See Statement 20ntext Matrix) ~ change fron statenent to expression context is indicated. The Expression Context Matrix is addressed. Source Operator: Stack )perator: (See Expression Context Matrix -- ~pp. V-c) (See ~xpression 20ntext Matrix -- ~pp. V-c) Source Operator: stack Operator: Arr~~, s~it£h, Theu=~, ~!~~, g! or Rll1 As~igU or Sem!£olQU The source operator identifies a declaration outside the block head, i.e., follo~ing or inside a statement. Error No. 166 is recorded and all stack operators and operands relating to the statement (if any) in ~hich the declaration occurs, are released. The declaration ~ill be processed (syntax checked) by the compiler program subsequently entered. ~ change fron expression to statement context is indicated. The Statement Context ~atrix is addressed. Source Operator: (See decision matrices -- ~ppendix V) Stack Operator: (See decision matrices -- Appendix V) Source Operator: Stack Operator: (See Statement Matrix -- ~pp. (See statement Matrix -- ~pp. Context V-b) Contex:t V-b) ~ change fron statenent to program context is indicated. The Program context Matrix: is add~essed. 162 The stack and source operators represent an improper operator sequence. Error No. 194 or 195 (depending on ~hether the operators are separated by an operand) is recorded, and the Operator/Operand Stack is adjusted, after release of the last stack operator and operand (if any), according to the next stack operator, to permit syntax checking to proceed. Source )~er~tor: St~ck )~erator: elta ptimization Table, and re-sets the pointer to a new record where the end of the current rec~rd has been reached. Called by CP40, CP47, and CP49, when the Optimization Table is being searched for subscript expressions to be optimized in a for statement. Proqram No.3 (CP3) ~perator ~perator: QmEl! marks the end of the source Providing the source module is not a precompiled proced~re (determined by inspection of the HCOMPMOD Control Field!\.ppendix IV), code is generated to branch to the rermination Ro~tine rERMIN in the Fixed Stora~e !\.rea. :ontrol is then passed to :PEND, the normal exit from IEX51. (See ns~bro~tine Pool".) mod~le. Subroutine Pool, contained in IEK50000 w comprises the by nost conpiler programs in common, as well as a short initialization ro~tine and the scanning and decisionmakin~ routines Scan to Next Operator (S~~r) and Conpare (:OMP). The latter two routines are described in an earlier section of this chapter. Contr~l Section s~bro~tines used Initialization ~:!~_~2~~E~~_QE~~!tQ~_lsNQ!t ::::ompare - (C:>MP) 164 Re-sets a pointer (SOURCE-register 6) to address a buffer containing a new record of the Modification Level 2 text and RE!\.Ds a further record from SYSUT2 into the alternate buffer. Called by SNOT" CP4, CPS1, and CP66 on recognition of the record-end character ~~!. op~rator rhe The are described elsewhere Else If or If-s so~rce stack These routines in this Chapter. Stores an error pattern in the Error Pool and sets the Syntax Check Mode switch on in the HCOMPMOD Control Field" on call from most compiler programs and subroutines. rhe error pattern is described in Chapter 9. There are five entry points" depending on the length of source text to be included in the ultimate diagnostic message. 3enerates code to call the Fixed Storage !\.rea routine CNVIRD (Which converts an integer operand to real form in floating point register 0) and modifies the stack operand to represent a real operand contained in ~PRO. Called by CP20, CP47, Cp61, CP69 and CP79. £Q~yg~sion Real-Integer (TRREIN) 3enerates code to call the Fixed Storage !\.rea routine CNVRDI (which cOnverts a real operand to integer form in fixed point register STH). Called by CP20" CP36, CP38, and CPS1. Constructs TKT and RLD records of object by the calloutputs the S~SPU~CH data sets, dependin;J on the options (LOAD and/or DECK) specified. The calling sequence in the callin;J compiler program is of the form ~odule instructions specified in:!' co~piler pro;Jram, and records on the S~SLI~ and/or BAL I~F)R~, <~-byte Formal parameter array called by value Parameterless procedure 3E~TXr4(O,SBR) object instruction> where INFORM (re;Jister 2) loads the address of the object instruction to be generated. rhere are seven entry points (GE~TXT2, GENTXr6, 3ENTXTS, 3ENTXTP2, 3ENTxrp4, and GENRLD), each entry point correspondin:!, to a particular instruction length. 3ENTKTP2 and GENTKTP4 are used for floatin;J point instructions. 3ENTXTS is used for object code sequences of varying length. The call to 3E~TXTS is of the form storage Area field specified in the stack operand). Load ADR with address of array (contained in formal parameter's Data storage Area field specified in the stack operand). Load GDSA with Data storage Area base address. store occupied registers. Call procedure (see Figure 63). No code is generated if the operand is not a formal parameter or a parameterless procedure. 3E~TKT4, LA INFORM, sequence>

Source Exif Data:
File Type                       : PDF
File Type Extension             : pdf
MIME Type                       : application/pdf
PDF Version                     : 1.3
Linearized                      : No
XMP Toolkit                     : Adobe XMP Core 4.2.1-c043 52.372728, 2009/01/18-15:56:37
Create Date                     : 2013:01:21 08:27:48-08:00
Modify Date                     : 2013:01:21 10:29:28-08:00
Metadata Date                   : 2013:01:21 10:29:28-08:00
Producer                        : Adobe Acrobat 9.52 Paper Capture Plug-in
Format                          : application/pdf
Document ID                     : uuid:40407db7-6d13-4fcb-9c48-96f3dc31f3c7
Instance ID                     : uuid:370c9182-03d2-429c-ab06-badde1225dbe
Page Layout                     : SinglePage
Page Mode                       : UseNone
Page Count                      : 326
EXIF Metadata provided by EXIF.tools

Navigation menu