by neng-fa zhou1 evolution of programming languages –machine language –assembly language...
TRANSCRIPT
![Page 1: By Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion (Algol,](https://reader035.vdocuments.us/reader035/viewer/2022062802/56649e9e5503460f94b9f201/html5/thumbnails/1.jpg)
by Neng-Fa Zhou 1
Evolution of programming languages
– Machine language– Assembly language– Sub-routines and loop (Fortran)– Procedures and recursion (Algol, Pascal, C)– Modules (Modula-2, Ada)– Objects (Simula, Smalltalk, C++,Java)– Declarative programming languages (Prolog,
CLP, Lisp, ML, Haskall)
![Page 2: By Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion (Algol,](https://reader035.vdocuments.us/reader035/viewer/2022062802/56649e9e5503460f94b9f201/html5/thumbnails/2.jpg)
by Neng-Fa Zhou 2
Why are there so many languages
Evolution– Procedural structural object-oriented
New paradigms and applications– Logic languages (Prolog, CLP) for complex data and
knowledge processing– Functional languages (Lisp, ML, Haskell) for symbolic
computation– Scripting languages (JavaScript, Pearl, Tcl, Python,
Ruby, XSLT) for Web-based data processing Personal preferences
![Page 3: By Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion (Algol,](https://reader035.vdocuments.us/reader035/viewer/2022062802/56649e9e5503460f94b9f201/html5/thumbnails/3.jpg)
by Neng-Fa Zhou 3
What makes a language successful Expressiveness Availability of implementations Efficiency Productivity Industrial sponsorships
![Page 4: By Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion (Algol,](https://reader035.vdocuments.us/reader035/viewer/2022062802/56649e9e5503460f94b9f201/html5/thumbnails/4.jpg)
by Neng-Fa Zhou 4
Why study programming languages
Understand language features and concepts at a higher level
Improve the ability to choose appropriate languages
Increase the ability to learn new languages Simulate useful features
![Page 5: By Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion (Algol,](https://reader035.vdocuments.us/reader035/viewer/2022062802/56649e9e5503460f94b9f201/html5/thumbnails/5.jpg)
by Neng-Fa Zhou 5
Why study language implementation Understand how languages are specified
and implemented Understand obscure phenomena Write better-style and efficient programs Design and implement domain-specific
languages
![Page 6: By Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion (Algol,](https://reader035.vdocuments.us/reader035/viewer/2022062802/56649e9e5503460f94b9f201/html5/thumbnails/6.jpg)
by Neng-Fa Zhou 6
Programming language spectrum
Declarative– Logic and constraint-based (Prolog, CLP(FD))– Functional (Lisp/Scheme, ML, Haskell)– Dataflow (Id, Val)– Template-based (XSLT)– Database (SQL)
Imperative– von Neumann (C, Ada, Fortran, Pascal,…)– Scripting (Perl, Python, PHP,…)– Object-oriented (Smalltalk, Effel, C++, Java, C#)
![Page 7: By Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion (Algol,](https://reader035.vdocuments.us/reader035/viewer/2022062802/56649e9e5503460f94b9f201/html5/thumbnails/7.jpg)
by Neng-Fa Zhou 7
Imperative
Features– Variables are mnemonics of memory locations– Assignment statements– goto– Iterative constructs
![Page 8: By Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion (Algol,](https://reader035.vdocuments.us/reader035/viewer/2022062802/56649e9e5503460f94b9f201/html5/thumbnails/8.jpg)
by Neng-Fa Zhou 8
Stack in C
typedef struct NodeStruct { int val; struct NodeStruct *next;} Node, *NodePtr, *List;
typedef struct StackStruct { int size; List elms;} Stack, *StackPtr;
![Page 9: By Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion (Algol,](https://reader035.vdocuments.us/reader035/viewer/2022062802/56649e9e5503460f94b9f201/html5/thumbnails/9.jpg)
by Neng-Fa Zhou 9
Stack in C (Cont.)
void stack_push(StackPtr s, int x){ s->size++; lst_add(&s->elms,x);}
int stack_pop(StackPtr s){ if (s->size==0){ error("empty stack"); } else { s->size--; return lst_remove(&s->elms); }}
![Page 10: By Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion (Algol,](https://reader035.vdocuments.us/reader035/viewer/2022062802/56649e9e5503460f94b9f201/html5/thumbnails/10.jpg)
by Neng-Fa Zhou 10
Object-oriented
Features– Abstract data types– Inheritance and overriding– Polymorphism – Dynamic binding
![Page 11: By Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion (Algol,](https://reader035.vdocuments.us/reader035/viewer/2022062802/56649e9e5503460f94b9f201/html5/thumbnails/11.jpg)
by Neng-Fa Zhou 11
Stack in Javaimport java.util.LinkedList;class MyStack { private LinkedList<Integer> elms;
public MyStack() { elms = new LinkedList<Integer>(); } public void push(int x) { elms.addFirst(x); } public int pop() { if (elms.size()==0){ throw new RuntimeException("Empty stack"); } else return elms.removeFirst(); }}
![Page 12: By Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion (Algol,](https://reader035.vdocuments.us/reader035/viewer/2022062802/56649e9e5503460f94b9f201/html5/thumbnails/12.jpg)
Stack in C#
by Neng-Fa Zhou 12
using System;using System.Collections.Generic;
class MyStack { private LinkedList<int> elms;
public MyStack() { elms = new LinkedList<int>(); } public void push(int x) { elms.AddFirst(x); } public int pop() { if (elms.Count==0){
throw new System.Exception("stack underflow"); } else { int tmp = elms.First.Value; elms.RemoveFirst();
return tmp;}
}
![Page 13: By Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion (Algol,](https://reader035.vdocuments.us/reader035/viewer/2022062802/56649e9e5503460f94b9f201/html5/thumbnails/13.jpg)
by Neng-Fa Zhou 13
Stack in C++
class Stack {public: Stack(); void push(int); int pop();private: list<int> elms;};
Stack::Stack(){}
void Stack::push(int x){ elms.push_front(x);}
int Stack::pop(){ assert(!elms.empty()); int x = elms.front(); elms.pop_front(); return x;}
![Page 14: By Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion (Algol,](https://reader035.vdocuments.us/reader035/viewer/2022062802/56649e9e5503460f94b9f201/html5/thumbnails/14.jpg)
by Neng-Fa Zhou 14
Functional
Features– Single assignment variables (no side effects) – Recursion– Rule-based and pattern matching (ML, Haskell)– High-order functions– Lazy evaluation (Haskell)– Meta-programming (Scheme)
![Page 15: By Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion (Algol,](https://reader035.vdocuments.us/reader035/viewer/2022062802/56649e9e5503460f94b9f201/html5/thumbnails/15.jpg)
by Neng-Fa Zhou 15
Stack in Scheme
(define stack_push(lambda (s x) (cons x s)))
(define stack_peek(lambda (s) (if (eq? s ())
(raise "empty stack") (car s))))
(define stack_pop(lambda (s) (if (eq? s ())
(raise "empty stack") (cdr s))))
![Page 16: By Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion (Algol,](https://reader035.vdocuments.us/reader035/viewer/2022062802/56649e9e5503460f94b9f201/html5/thumbnails/16.jpg)
by Neng-Fa Zhou 16
Stack in Haskell
stack_push s x = (x:s)
stack_peek (x:_) = x
stack_pop (_:s) = s
![Page 17: By Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion (Algol,](https://reader035.vdocuments.us/reader035/viewer/2022062802/56649e9e5503460f94b9f201/html5/thumbnails/17.jpg)
by Neng-Fa Zhou 17
Stack in SML/NJ
fun stack_push s x = (x::s)
fun stack_peek (x::s) = x
fun stack_pop (_::s) = s
![Page 18: By Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion (Algol,](https://reader035.vdocuments.us/reader035/viewer/2022062802/56649e9e5503460f94b9f201/html5/thumbnails/18.jpg)
by Neng-Fa Zhou 18
F#
let stack_push s x = x :: s let stack_peek s = match s with | x :: _ -> x let stack_pop s = match s with | _ ::s1 -> s1
![Page 19: By Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion (Algol,](https://reader035.vdocuments.us/reader035/viewer/2022062802/56649e9e5503460f94b9f201/html5/thumbnails/19.jpg)
by Neng-Fa Zhou 19
Logic & constraint-based
Features– Logic variables– Recursion– Unification– Backtracking– Meta-programming
![Page 20: By Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion (Algol,](https://reader035.vdocuments.us/reader035/viewer/2022062802/56649e9e5503460f94b9f201/html5/thumbnails/20.jpg)
by Neng-Fa Zhou 20
Stack in Prolog
stack_push(S,X,[X|S]).
stack_pop([X|S],X,S).
![Page 21: By Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion (Algol,](https://reader035.vdocuments.us/reader035/viewer/2022062802/56649e9e5503460f94b9f201/html5/thumbnails/21.jpg)
by Neng-Fa Zhou 21
Implementation methods Compilation
– Translate high-level program to machine code• Slow translation• Fast execution
Pure interpretation– No translation
• Slow execution• Becoming rare
Hybrid implementation systems– Small translation cost– Medium execution speed
![Page 22: By Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion (Algol,](https://reader035.vdocuments.us/reader035/viewer/2022062802/56649e9e5503460f94b9f201/html5/thumbnails/22.jpg)
by Neng-Fa Zhou 22
Review questions
Why are there so many programming languages? What makes a programming language successful? Why is it important to study programming
languages? Name two languages in each of the following
paradigms: procedural, OOP, logic, and functional. What are the features of OOP languages? What are the features of functional languages? What are the features of logic languages?