CS 52 / LECTURENOTES on a COURSE in SYSTEMS PROGRAMMING . BY. . AIANC. SHAW DECEMBER 9, 1966 COMPUTER SCIENCE DEPARTMENT School
Total Page:16
File Type:pdf, Size:1020Kb
CS 52 / , / . LECTURENOTES ON A COURSE iN SYSTEMS PROGRAMMING . BY. AIANC. SHAW $F) pq WEET n+KLUWD --. K~~NICALREPORT NO. 52 DECEMBER 9, 1966 These notes are based on the lecturei of Professor Niklaus Wirth which were given during the winter and spring of 1965/66 as CS 236a and part of CS 236b, Computer Science Department, Stanford University. COMPUTER SCIENCE DEPARTMENT School of Humanities and Sciences STANFORD UNIVERSITY . ,’ January 15, 1967 ERRATA in . ALAN c. SHAW, LECTURE NOTES.CN A COURSE IN SYSTEMS PROGRAMMING * . CS TR No. 52, Dec. 9, 1966 P* 17, line 5, read "Si+l'! for "Si+k" . P* 34, line 4, read "operand[O:m];" for "operands[O:m];" . P* 35, line 3, read "real or" for "real of" . P* 39, line -7, read "KDF-9" for "KDK-9" . P* 50, line -8, read "careful" for "cardful" . P* 5% add an arrow from "Data Channel" to "Memory" in the diagram. P* 74, last box on page, read "TSXf, 4" for "TSX 4,r" in all cases. P* 75, diagram, read "SQRT" for "S$RT" . P* 86, line 10, append "~2 := s2 + a[j] X b[jl;" , line -10, read "C[l:&l:n];" for "C[l:.!,l:m];" . F* 91, last paragraph, replace by 11 "Dijkstra has developed a solution to the more general problem where there are n processes, instead of only 2, operating in parallel. See K.nuth13 for a discussion and extension of Dijkstra's solution.". p. 100, left, insert between lines -6 and -7, "TRA EQ" . left, line -2, read "1" for "7" . p. 105, Example, read " A X" for ",AX " l i.2 LDQ kf P* 117, second diagram, read " mx!-] f " for 'i-q--q-qq " . p. 119, line -7, read "u,v (possibly empty)" for "u,w (possibly emtpy)". p. 120, line 1, append to-first sentence 1 "where the elements of 6' - are of the form: U' x(x f u, u&, xdf*) l 0 , .: / CS 52 ERRATA, Alan C!. Shaw p. 131, lines 1 and 2, interchange "it&rative" and "recursive". p. replace-program by 136, . (( So := PO; i := O;k := 1; while Pk /= ‘I' & begin i := j := i+l; Si := Pk; k := k+l; while Si .> Pk do' begin while Sj,-l k Sj do j := j-l; S l - Leftpart(S . S,); i := j j l .- j end end --_ p. 137, replace (b) by I b A ‘ A A 9 9 9 I I 4 <head> <head> -II <head> <head> 1 1 <head> <strin@ 1 <head> 1 <strin@ 1' . line -2, read "of KstringX ." for "of Xstring> ." p. 140, line -3, insert "The word "simple" is henceforth omitted.". p. 147, lines 5 through 9, replace by "directly reducible substrings (a)1 S..e..Sk and (b) Sj....S1 . It follows from the definition of precedence relations that S. Q S J-l j and Sk 4 Sk+l . Nowif i<j, then also k < j, since i<j<k l s If i=j and k<_L, then k=l, since implies S j-l= j' jLk<l implies Sk A sk+l ." . p. 151, line -13, read "conditional" for "condition" . p. 154, line -7, read "<digit>" for "<digit" e ' p. 179, insert between lines -4 and -5 "procedure Q(n); integer r-q" 2 - I Lecture Notes on a Course in SYSTEMS PROGRAMMING -. Decerriber 9, 1966 These notes are based on the lectures of Professor Niklaus Wirth which were given during the winter and spring of 1965/66 as CS 236a and part of CS 236b, Com- puter Science Department, Stanford University. Alan C. Shaw i SYSTEMS PROGRAMMING Page I* Introduction . e o 0 . e o e . 0 1 I-l* Advanced Programming . e . ., . o 0 0 e . 1 I-2. Purpose and Prerequisites of the course D e ., o e . 2 1730 Translators . D + a e . o . D o 0 2 I-4. References . o o . D . , 0 * , . e o . 0 . 4 II. Assemblers--. D e Q o o . ., ., . o Q . 0 . e D D ., 0 o 5 II-l. Basic Concepts . o . a ,, . e ., . o e 0 o 5 11-2. Multi-Pass Systems . a . ., e . o . o 0 ., 0 7 11-3. Organizing and Searching Symbol Tables . D . 0 . e 11 11-3.1 UnorderedTables ..e o e.O o o o O.. 12 II+2 Ordered Tables . 0 . 0 . o a o 12 11-3-3 Sorting . o . o . e . e 0 o . o 14 11-3.3.1 Bubble Sort o a e a a D o o o e ., m 14 11-3.3.2 Ranking By Insertion . o e . Q o D 16 11-3.3.3 Other Common Methods D . 0 ., o 0 o 3-7 II-3.4 Scrambling Methods D . e 0 o . o o o Q o o a 17 11-k. One-Pass Assembly . o e Q q 9 o . D 0 D 0 e D o o . 18 II+ Block Structure in Assemblers e . 0 e 0 ., e . o D o 21 11-6. References a o o 0 o ., d ., o a a . o o . e ., . 0 . 26 11-7. Problems . ., ., ., 0 . e o . o q a ., D o . 26 ii Page III* Interpreters . 30 III-l* Definition and Examples .............. 30 11X-2. Basic Interpreter of Sequential Code ........ 31 111-3. Interpreter for a von Neumann Machine . 33 III-b. Polish String or Stack Organized Machines . 38 111-5. Interpretive Computers ............... 41 111-6. References ..................... 43 111-7. Problems. 43 IV. Input-O'Wut Progr=ing. 48 IV-l. The Input-Output Problem ............. 48 IV-2. Immediate I-O. .................. 49 IV-2*1 No "Busy" Flag. .............. 50 IV-2.2 "~sY~ Flag. 50 IV-3. Indirect I-O . 51 IV-3.1 Channels . , .I. 52 IV-3.2 CPU Interrogates Channel . ,53 IV-3.3 Channei Interrupts CPU . l l . l e l 57 . Iv-4. I-O Processors. , . 66 w-5. .Experimental Comparison of Several Methods of I-O. Organiiation. +. 66 IV-~. I-O and Systems Programming. 68 V. Supervisory Programs (Monitors). , . 69 V-l. Monitor Tasks l '* . l l . 69 v-2. Types of Monitors. l . 71 V-2.1 Batch Processing Monitors . 71 iii Page V-2.2 Real Time Monitors . 71 V-2.3 Time Sharing Monitors . 72 v-3. Storage Allocation Methods . 73 V-3.1 Static Relocation . 74 V-3.2. Dynamic Relocation . , s . l . 76 V-3.2.1 Ferranti ATLAS Method . '78 V-3.2.2 Burroughs B5500 . 80 V-3.2.3 Arden, et al. Scheme . 0 . a 80 V-3.3 Memory Protection . o . e 82 V-3.4 Invariant Procedures o . 0 . e 83 v-4 . --' Loosely Connected Parallel Processes . 85 V-4 .l Programming Conventions for Parallel Processing . 86 V-4.2 The Control Problem for Loosely Connected Processes . l . 87 V-4.3 Solving the Problem . e . o . 88 V-4.4 The Use of Semaphores . o . 92 V-4.4.1 Two Processes Communicating via an Unbounded Buffer . 93 v-4.4.2 Processes Communicating via a Bounded Buffer. 97 v-5. References . e . e . o . 0 . 97 v-6. Problem. -. c . e . e . *. 99 VI. Compilers - An Introduction . Q . 100 VI-l. Tasks of a Compiler . Q . 100 VI-2. Heuristic Techniques for Expression Compilation . 103 iv Page VI-23 Rutishauser (1952) . 103 VI-2.2 FORTRAN Compiler (1954+) ......... l@b VI-23 NELIAC (a dialect-of ALGOL 58) ...... 105 VI-2.4 Samelson and Bauer (1959) ......... 106 VI-2.5 Dijkstra (1960) .............. 106 VI-30 Compilation of Expressions Using a Stack ..... 106 m-4. Phrase Structure Methods . 111 VI-5. References .................... 112 VI-~. Problems. .................... 112 --_ VII. Phrase Structure Programming Languages . 114 VII-l. Introduction . 114 VII-20 Representation of Syntax ............. 115 VII+ Notation and Definitions ............. 119 VII-b. Chomsky's Classification of Languages ....... 122 VII-5. The Parsing Problem ................ 122 VII-~. Irons' Classification of Languages According to . Parsing Difficulty . l l . l . + l l . 126 VII-7. Parsing Methods . .' . 128 VII-?*1 A "Top Down" Method . 128 VII-7.2 Eickel, Paul, Bauer, and Samelson . 131 ~11-8. Precedence Phrase Structure Systems . 133 ~11-8.1 Precedence Relations and the Parsing Algorithm . 133 ~11-8.2 Finding the Precedence Relations . 138 ~11-8.3 Use of Precedence Functions ....... 141 VII-8.4 Ambiguities ............... 145 Page ~11-9. Association of Semantics with Syntax. 147 VII-9.1 Mechanism for Expressing Semantics. 147 VII+2 Handling of Declarations . 150 VII 9.3 Conditional Statements and Expressions. 151 VII-9.4 GO TO and Labelled Statements . 153 VII+5 Constants . o 154 VII-lo. References . 155 VII-11. Problems . 156 VIII- Algal Compilation ..................... 166 VIII-l.--' Problems of Analysisand Synthesis ........ 166 VIII-29 Run Time,Storage Administration. ......... 167 VIII+ Treatment of Procedures ............. 170 VIII-k. Arrays ...................... 176 VIII-50 References .................... 178 ~111-6. Problems. .................... 178 vi --. I. INTRODUCTION I-l. Advanced Programming194 1 In attempting to define "Advanced. Programming", E. W. Dijkstra described the purpose of the subject to be "Advancing Programming"; he stressed "those efforts and considerations which try to improve 'the state of the art' of programming, maybe to such an extent that at some time in the future we may speak of 'the state of the Science of Program- ming."' Until recently, the design of machines almost always preceded any serious thought about programming them; this had the unfortunate result that programming-. languages and translators had to be severely restricted to fit into the constraints imposed by machine designers. Programming beyond these restrictions succeeded only' "by using the ma- chine in all kinds of curious and tricky ways which were completely unintended and not even foreseen by the designers." Programmers "have concocted thousands and thousands of ingenious tricks but they have made this chaotic contribution without a mechanism to appreciate or evaluate these tricks, or to sort them out." a Dijkstra's remarks were made in 1962.