1 / 12

Programming Languages 2nd edition Tucker and Noonan

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). Contents. 12.1 What Makes a Language Imperative?

Download Presentation

Programming Languages 2nd edition Tucker and Noonan

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming Languages2nd editionTucker 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. 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. 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. 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. General Characteristics • influencs: Algol, Pascal • large language; case insensitive • unlike C, array indexing errors trapped • type safe • generics • exception handling -- strictly control

  6. 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. 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. 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. 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. 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. 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. 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; • end loop; • return C; • end "*";

More Related