II. Notes on Data Structuring * - Cornell University
II. Notes on Data Structuring * - Cornell University II. Notes on Data Structuring * - Cornell University
102 c.A.R. HOARE new value can be input to buffer from the input tape by the procedure "read next character". In a certain representation of ALGOL 60, basic words are not singled out by underlining, and therefore look like identifiers. Consequently, if they are followed or preceded by an identifier or a number, they must be separated from it by one or more spaces or newline symbols. In the first pass of an ALGOL translator it is desired to read in the individual characters, and assemble them into meaningful symbols of the language; thus, an identifier, a basic symbol, a number, and the ":=" becomes sign, each count as a single symbol, as do all the other punctuation marks. Space and newline, having performed their function of separating symbols, must be ignored. We assume that each meaningful symbol will be scanned by a routine designed for the purpose, and that each such routine will leave in the buffer the first input character which is not part of the symbol. As an example of the analysis of the symbols of a program, input of the text !: beta1" = beta x 12; should be analysed into the following symbols" ! betal beta × 12 The general structure of the program is a case discrimination on the first character of the symbol, which determines to which class the symbol belongs. read first character; repeat case buffer of (alphabet'scan identifier, digit: point" subten" scan number, space" newline" read next character, colon" begin read next character; if buffer = equals then begin deal with "becomes"; read next character end
NOTES ON DATA STRUCTURING 103 else deal with single character end else begin deal with single character; read next character ) end until end of tape 4. THE CARTESIAN PRODUCT Defined enumerations and subranges, like primitive data types, are in principle unstructured. Of course, any particular representation of these types will be structured, for example, as a collection of consecutive binary digits; but from the abstract point of view, this structuring is essentially irrelevant. No operators are provided for accessing the individual bits, or for building up a value from them. In fact, it is essential to the successful use of an abstraction that such a possibility should be ignored; since it is only thus that detailed decisions can be postponed, and data representations can be decided in the light of the characteristics of the computer, as well as the manner in which the data is to be manipulated. We now turn to deal with data types for which the structure is meaningful to the programmer, at least at some stage in the development of his program. The basis of our approach is that, as in the case of enumerations, the pro- grammer should be able by declaration to introduce new data types; but for structured data, the definition of a new type will refer to other primitive or previously defined types, namely the types of the components of the structure. Thus the declaration of a new type will be somewhat similar to the declara- tion of a new function in a language such as ALGOL and FORTRAN. A function declaration defines the new function in terms of existing or pre- viously declared functions and operations. Just as a declared function can be invoked on many occasions from within statements of the program or other function declarations, so the new type can be "invoked" many times from within other declarations of the program; these may be either declarations of variables specified to range over the newly declared type, or they may be declarations of yet another new type. We will deal first with elementary data structures, Cartesian products and unions. These elementary structures are almost as simple and familiar to mathematicians and logicians as the natural numbers. Furthermore, from
- Page 1 and 2: II. Notes<
- Page 3 and 4: NOTES ON DATA STRUCTURING 85 Now we
- Page 5 and 6: NOTES ON DATA STRUCTURING 87 capabl
- Page 7 and 8: NOTES ON DATA STRUCTURING 89 easy f
- Page 9 and 10: NOTES ON DATA STRUCTURING 91 possib
- Page 11 and 12: NOTES ON DATA STRUCTURING 93 this s
- Page 13 and 14: NOTES ON DATA STRUCTURING 95 In the
- Page 15 and 16: NOTES ON DATA STRUCTURING 97 values
- Page 17 and 18: NOTES ON DATA STRUCTURING 99 where
- Page 19: NOTES ON DATA STRUCTURING 101 subra
- Page 23 and 24: NOTES ON DATA STRUCTURING 105 are r
- Page 25 and 26: NOTES ON DATA STRUCTURING 107 In in
- Page 27 and 28: NOTES ON DATA STRUCTURING 109 The m
- Page 29 and 30: NOTES ON DATA STRUCTURING 111 Every
- Page 31 and 32: NOTES ON DATA STRUCTURING 113 ways
- Page 33 and 34: NOTES ON DATA STRUCTURING 115 6. TI
- Page 35 and 36: 6.1. MANIPULATION NOTES ON DATA STR
- Page 37 and 38: NOTES ON DATA STRUCTURING 119 shift
- Page 39 and 40: NOTES ON DATA STRUCTURING 121 The c
- Page 41 and 42: NOTES ON DATA STRUCTURING 123 floor
- Page 43 and 44: NOTES ON DATA STRUCTURING 125 (11)
- Page 45 and 46: NOTES ON DATA STRUCTURING 127 each
- Page 47 and 48: end NOTES ON DATA STRUCTURING 129 n
- Page 49 and 50: NOTES ON DATA STRUCTURING 131 littl
- Page 51 and 52: NOTES ON DATA STRUCTURING 133 can b
- Page 53 and 54: NOTES ON DATA STRUCTURING 135 In so
- Page 55 and 56: NOTES ON DATA STRUCTURING 137 whole
- Page 57 and 58: NOTES ON DATA STRUCTURING 139 in th
- Page 59 and 60: NOTES ON DATA STRUCTURING 141 indic
- Page 61 and 62: NOTES ON DATA STRUCTURING 143 to th
- Page 63 and 64: NOTES ON DATA STRUCTURING 145 The f
- Page 65 and 66: 9.2. EXAMPLE NOTES ON DATA STRUCTUR
- Page 67 and 68: NOTES ON DATA STRUCTURING 149 The r
- Page 69 and 70: NOTES ON DATA STRUCTURING 151 A sim
102 c.A.R. HOARE<br />
new value can be input to buffer from the input tape by the procedure "read<br />
next character".<br />
In a certain representati<strong>on</strong> of ALGOL 60, basic words are not singled out<br />
by underlining, and therefore look like identifiers. C<strong>on</strong>sequently, if they are<br />
followed or preceded by an identifier or a number, they must be separated<br />
from it by <strong>on</strong>e or more spaces or newline symbols.<br />
In the first pass of an ALGOL translator it is desired to read in the<br />
individual characters, and assemble them into meaningful symbols of the<br />
language; thus, an identifier, a basic symbol, a number, and the ":="<br />
becomes sign, each count as a single symbol, as do all the other punctuati<strong>on</strong><br />
marks. Space and newline, having performed their functi<strong>on</strong> of separating<br />
symbols, must be ignored. We assume that each meaningful symbol will be<br />
scanned by a routine designed for the purpose, and that each such routine<br />
will leave in the buffer the first input character which is not part of the<br />
symbol.<br />
As an example of the analysis of the symbols of a program, input of the<br />
text<br />
!: beta1" = beta x 12;<br />
should be analysed into the following symbols"<br />
!<br />
betal<br />
beta<br />
×<br />
12<br />
The general structure of the program is a case discriminati<strong>on</strong> <strong>on</strong> the first<br />
character of the symbol, which determines to which class the symbol bel<strong>on</strong>gs.<br />
read first character;<br />
repeat case buffer of<br />
(alphabet'scan identifier,<br />
digit: point" subten" scan number,<br />
space" newline" read next character,<br />
col<strong>on</strong>" begin read next character;<br />
if buffer = equals then<br />
begin deal with "becomes"; read next character end