CS 222: Programming Languages
Heather M. Guarnera
print(“Welcome!”) printf(“Welcome!\n”); System.out.println(“Welcome!”); main = putStrLn “Welcome!”
CS 222: Programming Languages Heather M. Guarnera print(Welcome!) - - PowerPoint PPT Presentation
CS 222: Programming Languages Heather M. Guarnera print(Welcome!) printf(Welcome!\n); System.out.println(Welcome!); main = putStrLn Welcome! 4 (or 5) generations of programming languages 1GL 1GL : machine code
Heather M. Guarnera
print(“Welcome!”) printf(“Welcome!\n”); System.out.println(“Welcome!”); main = putStrLn “Welcome!”
1GL: machine code
2GL: symbolic assemblers
3GL: (machine-independent) imperative languages
4GL: domain specific application generators
5GL: AI languages … Each generation is at a higher level of abstraction
2
Assembly Fortran C Prolog Ada C++ Java Python
3
Low-level High-level Low-level language:
High-level language:
4
Common constructs basic data types (numbers, etc.); variables; expressions; statements; keywords; control constructs; procedures; comments; errors ... Uncommon constructs type declarations; special types (strings, arrays, matrices, ...); concurrency constructs; packages/modules; objects; general functions; generics; ...
5
6
Imperative style program = algorithms + data Good for decomposition Functional style program = functions ⚬ functions Good for reasoning Logic programming style program = facts + rules Good for searching Object-oriented style program = objects + messages Good for modeling
7
8
SUM = 0 DO 11 K=1,N SUM = SUM + 2*K 11 CONTINUE
Fo Fortran
sum = 0; for (k = 1; k <= n; ++k) sum += 2*k;
C
sum := 0; for k := 1 to n do sum := sum + 2*k;
Pa Pascal
9
10
(define (sum n) (if (= n 0) (+ (* n 2) (sum (- n 1))) ) ) (sum 4) evaluates to 20
Sc Scheme
not how to find it
theorem-proving
11
12
sum(0,0). sum(N,S) :- N>0, NN is N – 1, sum(NN, SS), S is N * 2 + SS. ?- sum(1,2). yes ?- sum(2,4). no ?- sum(4,S). S = 20 ?- sum(X,Y). X = 0 = Y
Pr Prolog
13
14
public class IntSet { ... public Integer sum() { Integer s = 0; ListIterator<Integer> it = intVals.listIterator() while (it.hasNext()) { s = s + 2 * it.next(); } return s; } }
Ja Java
IntSet mySet = new IntSet(3); mySet.sum();
and practically
development skills
15