Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 12 Imperative Programming I really hate this.

Similar presentations


Presentation on theme: "Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 12 Imperative Programming I really hate this."— Presentation transcript:

1 Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 12 Imperative Programming I really hate this darn machine; I wish they would sell it; It won’t do what I want it to, but only what I tell it. Programmer’s lament (anonymous)

2 Copyright © 2006 The McGraw-Hill Companies, Inc. Contents 12.1 What Makes a Language Imperative? 12.2 Procedural Abstraction 12.3 Expressions and Assignment 12.4 Library Support for Data Structures 12.5 C 12.6 Ada 12.7 Perl

3 Copyright © 2006 The McGraw-Hill Companies, Inc. 12.6 Ada developed in late 1970’s by DoD DoD spending billions of dollars on software over 450 languages in use solution: standardize on one language Higher Order Language Working Group

4 Copyright © 2006 The McGraw-Hill Companies, Inc. Ada 83 –problem: size of language/compiler –no subsets rule hard times during 1990s –use of COTS renewed interest –COTS proved problematic –development of Spark Ada –NYU GNAT (Ada) compiler

5 Copyright © 2006 The McGraw-Hill Companies, Inc. General Characteristics influencs: Algol, Pascal large language; case insensitive unlike C, array indexing errors trapped type safe generics exception handling -- strictly control

6 Copyright © 2006 The McGraw-Hill Companies, Inc. type union = record case b : boolean of true : (i : integer); false : (r : real); end; var tagged : union; begin tagged := (b => false, r => 3.375); put(tagged.i); -- error

7 Copyright © 2006 The McGraw-Hill Companies, Inc. generic type element is private; type list is array(natural range <>) of element; with function ">"(a, b : element) return boolean; package sort_pck is procedure sort (in out a : list); end sort_pck;

8 Copyright © 2006 The McGraw-Hill Companies, Inc. package sort_pck is procedure sort (in out a : list) is begin for i in a'first.. a'last - 1 loop for j in i+1.. a'last loop if a(i) > a(j) then declare t : element; begin t := a(i); a(i) := a(j); a(j) := t; end; end if;

9 Copyright © 2006 The McGraw-Hill Companies, Inc. Ex: Average comparable to C infinite loop; exit on end of file via exception inner loop to catch errors caused by non-numeric data wordy than C

10 Copyright © 2006 The McGraw-Hill Companies, Inc. Ex: Matrix Multiplication overloaded * raises exception if the number of columns of A not equal to the number of rows of B a’first(2), a’last(2), a’range(2) compiler can verify at compile time that an indexing error cannot occur

11 Copyright © 2006 The McGraw-Hill Companies, Inc. type Matrix is array (Positive range <> of Float, Positive range <> of Float); function "*" (A, B: Matrix) return Matrix is C: Matrix (A'Range(1), B'Range(2)); Sum: Float; begin if A'First(2) /= B'First(1) or A'Last(2) /= B'Last(1) then raise Bounds_Error; end if;

12 Copyright © 2006 The McGraw-Hill Companies, Inc. for i in C'Range(1) loop for j in C'Range(2) loop Sum := 0.0; for k in A'Range(2) loop Sum := Sum + A(i,k) * B(k,j); end loop; Result(i,j) := Sum; end loop; return C; end "*";


Download ppt "Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 12 Imperative Programming I really hate this."

Similar presentations


Ads by Google