Maclennan chap5-pascal


Published on

Published in: Education, Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Maclennan chap5-pascal

  1. 1. CSE 3302 Pascal (Using slides of Tom Rethard)
  2. 2. Algol <ul><li>Successful, so … </li></ul><ul><ul><li>Use the ideas in other languages </li></ul></ul><ul><ul><li>Algol-like languages </li></ul></ul><ul><ul><ul><li>List processing </li></ul></ul></ul><ul><ul><ul><li>String manipulation </li></ul></ul></ul><ul><ul><ul><li>Systems programming </li></ul></ul></ul><ul><ul><ul><li>Artificial Intelligence </li></ul></ul></ul><ul><ul><li>Upgrades to Algol itself </li></ul></ul>
  3. 3. PL/I <ul><li>A block-structured COBOL/FORTRAN union (IBM, 1967) </li></ul><ul><ul><li>Algol block structure </li></ul></ul><ul><ul><li>COBOL file manipulation </li></ul></ul><ul><ul><li>FORTRAN syntactic style </li></ul></ul><ul><li>“ Everything for Everyone” </li></ul><ul><li>“ The Only Programming Language You’ll Ever Need” </li></ul><ul><li>Basically, a Swiss Army knife </li></ul>
  4. 4. PL/I <ul><li>Characterized by Dijkstra as “a fatal disease” and “a programming language for which the defining documentation is of a frightening size and complexity. Using PL/I must be like flying a plane with 7000 buttons, switches, and handles to manipulate in the cockpit” </li></ul>
  5. 5. Extensible Languages <ul><li>Roll-your-own (sort of) </li></ul><ul><ul><li>Just a language kernel </li></ul></ul><ul><ul><li>But capable of adding to it if necessary </li></ul></ul><ul><ul><li>MAD (Michigan Algorithm Decoder) </li></ul></ul><ul><ul><li>McIlroy’s “syntax macros” </li></ul></ul>
  6. 6. Simple Kernel <ul><li>Turned out to be a good idea </li></ul><ul><li>Frequent choice was an Algol subset with more general data structuring abilities </li></ul><ul><li>Allowed generalization to an application area, built on a common foundation. </li></ul>
  7. 7. Types of Extensions <ul><li>Operator Extension </li></ul><ul><ul><li>Define new, application-oriented operators </li></ul></ul><ul><li>Example: symmetric difference (x # y) </li></ul><ul><ul><li>operator 2 x # y; value x, y; real x,y; begin return abs(x-y) end; </li></ul></ul><ul><ul><li>The “2” is the precedence of the operator. </li></ul></ul>
  8. 8. Types of Extensions <ul><li>Syntax macros </li></ul><ul><li>real syntax: sum from I = lb to ub of elem; value lb, ub; integer I, lb, ub; real elem; begin real s; s := 0; for I := lb step 1 until ub do s := s + elem; return s end; </li></ul><ul><li>Total := sum from k = 1 to N of Wages[k]; </li></ul>
  9. 9. Issues with Extensible languages <ul><li>Usually inefficient </li></ul><ul><ul><li>Tough to write a compiler for a language that is always changing! </li></ul></ul><ul><li>Poor Diagnostics </li></ul><ul><ul><li>The compiler really doesn’t understand what’s going on. </li></ul></ul>
  10. 10. Pascal <ul><li>Designed by Niklaus Wirth </li></ul><ul><ul><li>Previously designed </li></ul></ul><ul><ul><ul><li>Algol-W (a proposed extension to ALGOL with C. A. R. Hoare) </li></ul></ul></ul><ul><ul><ul><li>Euler </li></ul></ul></ul><ul><ul><ul><li>PL360 </li></ul></ul></ul>
  11. 11. Pascal Goals <ul><li>The language should be suitable for teaching programming in a systematic way. </li></ul><ul><li>The implementation of the language should be reliable and efficient, at compile-time and run-time, on available computers. </li></ul>
  12. 12. History <ul><li>Development started in 1968 </li></ul><ul><li>First working compiler in 1970 </li></ul><ul><li>Pascal-70 Report was 29 pages (cf. Algol’s 16) </li></ul><ul><li>P-Code based system in 1973 </li></ul><ul><li>Spread quickly on microcomputers in the 70s & 80s </li></ul>
  13. 13. Example <ul><li>Program AbsMean (input, output); const Max = 900; type index = 1 .. Max; var N: 0 .. Max; Data: array [index] of real; sum, avg, val: real; i: index; … </li></ul>
  14. 14. Example (con’t) <ul><li>begin sum := 0; readln (N); for i := 1 to N do begin readln (val); if val < 0 then Data[i] := val else Data[i] := val end; for i := 1 to N do sum = sum + Data[i]; avg := sum/N; writeln (avg); </li></ul><ul><li>end. </li></ul>
  15. 15. Enumerations <ul><li>Old Way </li></ul><ul><li>begin integer today, tomorrow; integer Sun, Mon, Tue, Wed, Thu, Fri, Sat; Sun := 0; Mon := 1; Tue := 2; Wed := 3; Thu := 4; Fri := 5; Sat := 6; … today := Tue; tomorrow := today + 1; … </li></ul>
  16. 16. Enumerations <ul><li>Pascal Way </li></ul><ul><li>Type DayOfWeek = (Sun, Mon, Tue, Wed, Thu, Fri, Sat); Month = (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec); var today, tomorrow: DayOfWeek; begin … today := Tue; tomorrow := today + 1; … today = Jan; /* type error … </li></ul>
  17. 17. The Enumeration ADT <ul><li>Operations </li></ul><ul><ul><li>:= </li></ul></ul><ul><ul><li>succ </li></ul></ul><ul><ul><li>pred </li></ul></ul><ul><ul><li>= </li></ul></ul><ul><ul><li><> </li></ul></ul><ul><ul><li>< </li></ul></ul><ul><ul><li>> </li></ul></ul><ul><ul><li><= </li></ul></ul><ul><ul><li>>= </li></ul></ul><ul><li>What is succ(Sat)? </li></ul><ul><ul><li>Undefined </li></ul></ul><ul><li>What is pred(Nov)? </li></ul><ul><ul><li>Oct </li></ul></ul>
  18. 18. Enumeration Characteristics <ul><li>High Level and Application Oriented </li></ul><ul><li>Efficient </li></ul><ul><ul><li>Storage </li></ul></ul><ul><li>Secure </li></ul><ul><ul><li>Does not allow meaningless operations </li></ul></ul>
  19. 19. Subrange Types <ul><li>var DayOfMonth 1 .. 31; </li></ul><ul><li>Restricts the range of values for DayOfMonth to the integer subrange of 1..31 </li></ul><ul><li>Can also use in enumerations: </li></ul><ul><li>Type WeekDay = Mon .. Fri </li></ul>
  20. 20. Sets <ul><li>Set of <ordinal type> </li></ul><ul><li>(enumeration type(char,Boolean), </li></ul><ul><li>subrange type) </li></ul><ul><li>Var S, T: set of 1..10; </li></ul><ul><li>S := [1, 2, 3, 5, 7]; </li></ul><ul><li>T := [1 ..6]; </li></ul><ul><li>If T = [1, 2, 3, 5] then … </li></ul>
  21. 21. Set Operations <ul><li>= </li></ul><ul><li><> </li></ul><ul><li><= subset or equal </li></ul><ul><li>>= </li></ul><ul><li>But: no < or > ! </li></ul>
  22. 22. Arrays <ul><li>Any upper or lower bound </li></ul><ul><li>Can also use enumeration types as array indices </li></ul><ul><li>Examples (note base type in #2) </li></ul><ul><ul><li>var A: array [1 .. 100] of real; </li></ul></ul><ul><ul><li>var HoursWorked: array [Mon .. Fri] of 0 .. 24; </li></ul></ul>
  23. 23. Arrays <ul><li>Var day: Mon .. Fri; TotalHours: 0..120; begin TotalHours := 0; for day := Mon to Fri do TotalHours := TotalHours + HoursWorked[day]; </li></ul>
  24. 24. Arrays – of Characters <ul><li>Any finite discrete type for index </li></ul><ul><li>var Occur: array [char] of integer; … Occur[ch] := Occur[ch] + 1; … if Occur[‘e’] > Occur[‘t’] then … </li></ul>
  25. 25. More Complex Arrays <ul><li>var M: array [1..20] of array [1 .. 100] of real; or var m: array [1 .. 20, 1 .. 100] of real; </li></ul>
  26. 26. Arrays Issue <ul><li>There are some problems </li></ul><ul><li>Need to be static, not dynamic </li></ul><ul><ul><ul><li>Must know types at compile time </li></ul></ul></ul><ul><ul><ul><li>Dimensions are part of the array type </li></ul></ul></ul><ul><ul><ul><li>Arrays are considered the same type if index types and base types both match </li></ul></ul></ul>
  27. 27. Type problems <ul><li>type vector = array [1 .. 100] of real; var U, V, vector; function sum (x: vector): real; … begin … end {sum}; </li></ul><ul><li>Can write </li></ul><ul><li>var W: array [1 ..75] of real; </li></ul><ul><li>But cannot write: </li></ul><ul><li>Sum(W) </li></ul>
  28. 28. Type Problems <ul><li>Types of W and of x are not the same because the ranges of the indices are different! </li></ul><ul><li>This appears to be a violation of the Abstraction Principle. </li></ul>
  29. 29. Record Types <ul><li>Heterogeneous data </li></ul><ul><li>Multiple components </li></ul><ul><li>Various types </li></ul>
  30. 30. Records <ul><li>type </li></ul><ul><li>person = record name: string; age: 16 .. 100; salary: 10000 .. 100000; sex: (male, female); birthdate: date; hiredate: date; end; string = packed array [1 ..30] of char; date = record mon: month; day: 1 ..31; year: 1900 .. 2100; end; month = (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec); </li></ul>
  31. 31. Using a Record <ul><li>To use a record: var newhire: person; just like any other type </li></ul>
  32. 32. Getting to the Components <ul><li>var newhire: person; today: date; … newhire.age := 25; := female; := today; </li></ul>
  33. 33. More Possibilities <ul><li>if[1] = ‘A’ then … </li></ul><ul><li>type employeeNum = 1000 .. 9999; var employees: array [employeeNum] of person; EN: employeeNum; </li></ul>
  34. 34. Making it Simpler <ul><li>with newhire begin age := 25; sex := female; date := today end; </li></ul>
  35. 35. Storage Groupings <ul><li>Homogeneous </li></ul><ul><ul><li>Arrays </li></ul></ul><ul><ul><li>All elements are the same type </li></ul></ul><ul><ul><li>Computed (dynamic) selector (subscript or index) </li></ul></ul><ul><li>Heterogeneous </li></ul><ul><ul><li>Records </li></ul></ul><ul><ul><li>Elements (components) may be of different types </li></ul></ul><ul><ul><li>Static selector </li></ul></ul>
  36. 36. Variant Records <ul><li>Sometimes records vary from one record type to another. </li></ul><ul><li>Think of this as a primitive form of subclassing </li></ul>
  37. 37. Variant Records <ul><li>type plane = record flight: 0 .. 999; kind: (B727, B737, B747); status (inAir, onGround, atTerminal); altitude: 0 .. 100000; heading: 0 .. 359; arrival: time; destination: airport; location: airport; runway: runwayNumber; parked: airport; gate: 1.. 100; departure: time; end; {plane} </li></ul>
  38. 38. What’s Wrong? <ul><li>Not all data has meaning at the same time. </li></ul><ul><li>Can imply a plane is located at one airport and is parked at another </li></ul><ul><li>Violates security principle. </li></ul>
  39. 39. Variant Records <ul><li>type plane = record flight: 0 .. 999; kind: (B727, B737, B747); case status: (inAir, onGround, atTerminal); inAir:( altitude: 0 .. 100000; heading: 0 .. 359; arrival: time; destination: airport); onGround: ( location: airport; runway: runwayNumber); atTerminal: ( parked: airport; gate: 1.. 100; departure: time); end; {plane} </li></ul>
  40. 40. Implementation flight kind status altitude heading arrival destination location runway parked gate departure
  41. 41. The Dreaded Pointer <ul><li>There is a problem with pointers and strong typing! </li></ul><ul><li>Pascal solves this problem by typing pointers </li></ul>
  42. 42. Typed Pointers (notPascal) <ul><li>var p: pointer; x: real; c: char; begin new(p); p^ := 3.14159; c := p^; end </li></ul>
  43. 43. Typed Pointers (Pascal) <ul><li>var p: ^real; x: real; c: char; begin new(p); p^ := 3.14159; c := p^; {illegal} end </li></ul>
  44. 44. Pointers with Records <ul><li>var p: ^plane; begin … p^.plane.parked[1] … … end; </li></ul>
  45. 45. Type Equivalence <ul><li>Not as clear as it could have been </li></ul><ul><li>Revised Pascal Report </li></ul><ul><ul><li>Specifies assignments are ok if expression and variable have identical type </li></ul></ul><ul><ul><li>Does not define identical type </li></ul></ul>
  46. 46. Interpretations for equivalency <ul><ul><li>Structural equivalence </li></ul></ul><ul><ul><ul><li>Structural descriptions of the types be the same </li></ul></ul></ul><ul><ul><li>Name equivalence </li></ul></ul><ul><ul><ul><li>Names must be same </li></ul></ul></ul>
  47. 47. Structural Equivalence <ul><li>var </li></ul><ul><li>x: record id: integer; weight: real end; </li></ul><ul><li>y: record id: integer; weight: real end; </li></ul><ul><li>The above are the same because their structure is the same </li></ul>
  48. 48. But… Consider this <ul><li>type person = record id: integer; weight: real end; car = record id: integer; weight: real end; </li></ul><ul><li>The above are the same because their structure is the same, so: car := person; according to structural equivalency is legal! </li></ul>
  49. 49. Name Equivalence <ul><li>var x: record id: integer; weight: real end; y: record id: integer; weight: real end; </li></ul><ul><li>Is actually ambiguous, </li></ul><ul><li>Different versions of Name Equivalence Rule differ on this example. </li></ul><ul><ul><li>If reinterpreted as follows, then they are different </li></ul></ul><ul><li>type </li></ul><ul><li>T00029: record id: integer; weight: real end; </li></ul><ul><li>T00030: record id: integer; weight: real end; </li></ul><ul><li>var x: T00029; y: T00030; </li></ul>
  50. 50. Name Equivalence Issues <ul><li>type age = 0 .. 150; </li></ul><ul><li>var n: integer; a: age; </li></ul><ul><li>Is n:= a legal? </li></ul><ul><ul><li>Pure name equivalence says no </li></ul></ul><ul><ul><li>Logic says yes </li></ul></ul><ul><ul><li>Revised Pascal Report says that a subrange of a type is still that type </li></ul></ul>
  51. 51. Comparison <ul><li>Name Equivalence generally safer </li></ul><ul><ul><li>More restrictive </li></ul></ul><ul><li>Name Equivalence is easier to implement </li></ul><ul><ul><li>Simply a string comparison </li></ul></ul><ul><ul><li>Structural equivalence requires a recursive function </li></ul></ul><ul><li>ISO Pascal specifies name Equivalence </li></ul>
  52. 52. Name Structures <ul><li>Pascal provides six types </li></ul><ul><ul><li>Constant bindings </li></ul></ul><ul><ul><li>Type bindings </li></ul></ul><ul><ul><li>Variable bindings </li></ul></ul><ul><ul><li>Procedure and function bindings </li></ul></ul><ul><ul><li>Implicit enumeration bindings </li></ul></ul><ul><ul><li>Label bindings </li></ul></ul>
  53. 53. Constant bindings <ul><li>const MaxData = 100; </li></ul><ul><li>MaxData can be used almost anywhere </li></ul><ul><ul><li>All declarations </li></ul></ul><ul><ul><li>Executable statements (for loops, etc.) </li></ul></ul><ul><ul><li>Expressions </li></ul></ul><ul><ul><li>BUT , not in other const declarations! </li></ul></ul><ul><ul><ul><li>const MaxDataMinus1 = MaxData –1; is not allowed </li></ul></ul></ul>
  54. 54. Constructors <ul><li>Record constructors </li></ul><ul><li>Procedure/Function </li></ul><ul><ul><li>The major scope defining construct </li></ul></ul>
  55. 55. Procedures <ul><li>procedure <name> (<formal arguments>); <declarations> begin <statements> end ; </li></ul>
  56. 56. A Problem <ul><li>procedure P (...); ... begin ... </li></ul><ul><li>Q(...) ... end ; </li></ul><ul><li>procedure Q (...); ... begin ... P(...) ... end ; </li></ul>
  57. 57. A Problem Solved <ul><li>procedure Q(...) forward; </li></ul><ul><li>procedure P (...); ... begin ... </li></ul><ul><li>Q(...) ... end ; </li></ul><ul><li>procedure Q (...); ... begin ... P(...) ... end ; </li></ul>
  58. 58. Procedure Construction <ul><li>procedure <name> (<formal arguments>); <label declarations> <const declarations> <type declarations> <var declarations> <procedure and function declarations> begin <statements> end ; </li></ul>
  59. 59. Pascal eliminates the block <ul><li>Simplifies name structure </li></ul><ul><li>Complicate efficient use of memory </li></ul>
  60. 60. Control structures <ul><li>Reflects structured programming ideas </li></ul>
  61. 61. For Loop <ul><li>for <name> := expression { to | downto } <expression> do <statement> </li></ul><ul><li>Simplified comparing with Algol (overreact to second generation languages) </li></ul><ul><li>Bounds of the loop are computed once, at loop entry => definite iterator </li></ul>
  62. 62. While Loop <ul><li>Also a “Leading Decision Indefinite Iterator” </li></ul><ul><li>while <condition> do <statement> </li></ul><ul><li>Checks at top of loop </li></ul><ul><li>Can use “while true do....” for a loop exiting from the middle (Mid-Decision Iterator) </li></ul>
  63. 63. Repeat Loop <ul><li>Also “Trailing Decision Indefinite Iterator” </li></ul><ul><li>repeat <statement> until <condition> </li></ul><ul><li>Checks at bottom of loop </li></ul>
  64. 64. Unlabeled Case Statement <ul><li>NOT Pascal – modeled according to Fortran computed goto </li></ul><ul><li>case <expression> of <statement>, <statement>, ... <statement> end case; </li></ul>
  65. 65. <ul><li>case I of begin ... S 1 ... end ; begin ... S 23 ... end ; </li></ul><ul><li>begin ... S 23 ... end ; begin ... S 4 ... end ; end case ; </li></ul><ul><li>No labels provided. </li></ul>
  66. 66. Labeled Case Statement <ul><li>Major contribution of Pascal </li></ul><ul><li>case <expression> of <case clause>; <case clause>; ... <case clause> end case; </li></ul><ul><li>Designed by C.A. Hoare: the most important of his many contributions to language design </li></ul>
  67. 67. Labeled Case Statement <ul><li>case I of 1: begin ... S 1 ... end ; 2: 3: begin ... S 23 ... end ; 4: begin ... S 4 ... end ; end case ; </li></ul><ul><li>Some dialects of Pascal add an otherwise case. </li></ul>
  68. 68. The labeling principles <ul><li>… </li></ul>
  69. 69. Parameter Passing <ul><li>Pass by reference </li></ul><ul><ul><li>Replaces Algol pass by name </li></ul></ul><ul><ul><li>Intended to allow side effects (ie, I-O parameter usage) </li></ul></ul><ul><ul><li>Passes only the address </li></ul></ul><ul><li>Pass by value </li></ul><ul><ul><li>Intended for input only parameters </li></ul></ul><ul><ul><li>Side effects not allowed </li></ul></ul><ul><ul><li>Done by copy-in </li></ul></ul>
  70. 70. Pass as Constant <ul><li>Original specification contained this instead of pass by value </li></ul><ul><li>Similar to C const parameter passing </li></ul><ul><li>Allowed compiler to pass either address or value </li></ul><ul><li>Called procedure could not modify it </li></ul><ul><li>Elimination encourages call by reference </li></ul>
  71. 71. <ul><li>Security advantages of value parameters </li></ul><ul><li>Efficiency advantages of reference parameters </li></ul><ul><li>But there are some security problems … </li></ul><ul><li>when aliasing </li></ul>
  72. 72. <ul><li>type vector=array[1..100] of real; </li></ul><ul><li>var A:vector </li></ul><ul><li>… </li></ul><ul><li>procedure P(x:vextor); *pass by constant </li></ul><ul><li>begin </li></ul><ul><li>writeln(x[1]); A[1]:=0; writeln(x[1]) </li></ul><ul><li>end; </li></ul><ul><li>begin </li></ul><ul><li>P(A) </li></ul><ul><li>end; </li></ul>
  73. 73. Pass as Constant <ul><li>Two orthogonal issues involved </li></ul><ul><ul><li>Should copy its value or use its address? </li></ul></ul><ul><ul><li>Should be I or I-O parameter </li></ul></ul><ul><li>Approach violates the Orthogonality Principle </li></ul>
  74. 74. <ul><li>Write a Pascal fragment that does not use the nonlocal variables, to illustrate the security loophole in parameters passed as constants. </li></ul>
  75. 75. Procedural Parameters: Security Loophole <ul><li>Pascal allows passing a procedure or function name as a parameter </li></ul><ul><ul><li>To restore some of the flexibility lost by omitting name parameters </li></ul></ul><ul><li>Makes it difficult to determine if the function parameter is properly constructed. </li></ul>
  76. 76. <ul><li>Procedure difsq (function f:real; x:real):real </li></ul><ul><li>begin </li></ul><ul><li>difsq:= f(x*x) – f(-x*x) </li></ul><ul><li>end </li></ul><ul><li>difsq(sin,theta)=sin(theta^2 ) – sin(-theta^2) </li></ul>
  77. 77. <ul><li>The arguments of a formal procedure parameter shall be specified </li></ul><ul><li>Procedure difsq (function f(y:real):real; x:real):real </li></ul>
  78. 78. Pascal <ul><li>Actually has lived up to its goals </li></ul><ul><ul><li>Teaching language </li></ul></ul><ul><ul><ul><li>Reliability </li></ul></ul></ul><ul><ul><ul><li>Simplicity </li></ul></ul></ul><ul><ul><ul><li>Efficiency </li></ul></ul></ul><ul><ul><li>Wirth: “the principle to include features that were well understood, in particular by implementors, and to leave out those that were still untried and unimplemented, proved to be the most successful single guideline.” </li></ul></ul>
  79. 79. Extensions <ul><li>Basis for most modern language design </li></ul><ul><ul><li>One step past Algol </li></ul></ul><ul><li>Multiple offshoots: </li></ul><ul><ul><li>Concurrent Pascal </li></ul></ul><ul><ul><li>Mesa </li></ul></ul><ul><ul><li>Euclid </li></ul></ul><ul><ul><li>Modula-2 (by Wirth) </li></ul></ul>
  80. 80. Systems Languages <ul><li>Subsets of PL/I </li></ul><ul><li>PL/S </li></ul><ul><li>PL/360 </li></ul><ul><li>PL/M </li></ul><ul><li>XPL </li></ul><ul><li>TI Pascal and MPP </li></ul>
  81. 81. BCPL <ul><li>Basic CPL </li></ul><ul><ul><li>Simplified version of CPL – Cambridge Plus London </li></ul></ul><ul><ul><li>Became popular in the early 70s </li></ul></ul><ul><li>B </li></ul><ul><ul><li>Ken Thompson, 1969-70 </li></ul></ul><ul><ul><li>“ BCPL squeezed into 8K of memory and filtered through Thompson’s brain” </li></ul></ul><ul><ul><li>UNIX on PDP-7 </li></ul></ul><ul><ul><li>Extreme weak typing (only 1 data type!) </li></ul></ul><ul><ul><li>More like Assembly Language </li></ul></ul>
  82. 82. From B We Got <ul><li>C </li></ul><ul><ul><li>PDP-11 arrived </li></ul></ul><ul><ul><li>Problem with B’s addressing scheme discovered </li></ul></ul><ul><ul><li>Dennis M Ritchie started by extending B to contain basic data types (but no type checking) </li></ul></ul><ul><ul><li>Unions and enumerations added later, but still no type checking </li></ul></ul><ul><ul><li>Serious problems in porting UNIX to other platforms, so lint (a separate type checker) used to check types </li></ul></ul>
  83. 83. C <ul><li>Language attempted to maintain compatibility with older B language </li></ul><ul><li>The C Programming Language by K&R 1978 </li></ul><ul><li>ANSI Standard C </li></ul><ul><ul><li>Began 1983 </li></ul></ul><ul><ul><li>Approved 1989 </li></ul></ul><ul><li>Permitted spread within universities and research organizations </li></ul><ul><li>Also used as the output language for many compilers. </li></ul>
  84. 84. C Generational Characteristics <ul><li>1 st Generation </li></ul><ul><ul><li>No nested procedures </li></ul></ul><ul><ul><li>Poor support for modular programming </li></ul></ul><ul><li>2 nd Generation </li></ul><ul><ul><li>Low-level model of arrays and pointers </li></ul></ul><ul><li>3 rd Generation </li></ul><ul><ul><li>Hierarchical data structures </li></ul></ul>
  85. 85. C According to Ritchie <ul><li>“ C is quirky, flawed, and an enormous success” </li></ul><ul><li>Suggests success attributed to </li></ul><ul><ul><li>Simplicity </li></ul></ul><ul><ul><li>Efficiency </li></ul></ul><ul><ul><li>Portability </li></ul></ul><ul><ul><li>Closeness to the machine </li></ul></ul><ul><ul><li>Evolution in an environment in which it was used to write practical programs </li></ul></ul>
  86. 86. 3 rd Generation Language <ul><li>Emphasis on simplicity and efficiency </li></ul><ul><li>Data structures </li></ul><ul><ul><li>Shift emphasis from machine to application </li></ul></ul><ul><ul><li>Application-oriented constructors: sets, subranges, enumerations </li></ul></ul><ul><li>Name structures </li></ul><ul><ul><li>Simplification of Algol’s </li></ul></ul><ul><ul><li>Add new new binding and scope-defining constructs </li></ul></ul><ul><li>Control structures </li></ul><ul><ul><li>Simplified, efficient versions of the 2 nd generation </li></ul></ul><ul><ul><li>Some new structures, such as a real case </li></ul></ul>
  87. 87. Exercises <ul><li>5-1 </li></ul><ul><li>5-4 </li></ul><ul><li>5-8 </li></ul><ul><li>5-14 </li></ul><ul><li>5-15 </li></ul><ul><li>5-17 </li></ul><ul><li>5-20 </li></ul><ul><li>5-25 </li></ul><ul><li>5-26 </li></ul>