Lecture #6 Programming Languages MISHRA 95

G22.2210

Programming Languages: PL

B. Mishra
New York University.


Lecture # 6

---Slide 1---
Scope Issues

---Slide 2---
Scope

---Slide 3---
Extent

---Slide 4---
Range

---Slide 5---
Dynamic and Static Ranges

---Slide 6---
Example 1

    var i, k: integer;

    procedure P(var j: integer);
      var i: integer;
      begin i := 1; Q; j := i end;

    procedure Q;
      begin i := i+1 end;

    begin
      i := 3; P(k); write(k)
    end.

---Slide 7---
Example 2

  var i: integer;

  function GLOP(function Q: integer,
              lower, upper: integer): integer;
    var i,S: integer;
    begin
      S := 0;
      for i := lower to upper do S := S + Q;
      GLOP := S
    end;

  function A;
    begin A := i*i end;

  begin
    i := 0; write(GLOP(A,1,3))
  end.

---Slide 8---
Procedures and Functions

---Slide 9---
Parameter Passing Methods

---Slide 10---
Calling Mechanisms

---Slide 11---
Variations

           procedure USE(X: in INTEGER) is ...
           procedure GENERATE(X: out INTEGER) is ...
           procedure MODIFY(X: in out INTEGER) is ...

---Slide 12---
Example

    var i: integer;
    A: array[1..3] of integer;

    procedure testbind( <binding> f, g: integer);
    begin
       g := g + 1;
       f := 5 * i;       (* i= nonlocal)
    end;

    begin
      for i := 1 to 3 do A[i] := i;
      i := 2;
      testbind(A[i], i);
      print(i, A[1], A[2], A[3]);
    end;

---Slide 13---
Example (contd)

---Slide 14---
Macros: Text Substitution

---Slide 15---
Macros (contd)

---Slide 16---
Subprograms in Ada

---Slide 17---
Example

---Slide 18---
Procedure Calls in Ada

  COMPUTE_RISE(X_VEL, Y_VEL, TARGET_DIST, ELEVATION);
  COMPUTE_RISE(50.0, 60.0, (POSN + 10.0), R(1));
    --R = array of FLOAT

---Slide 19---
Usage of Default Values

---Slide 20---
Separation of Subprogram Bodies

---Last Slide---
Overloading

[End of Lecture #6]