Professional Documents
Culture Documents
Principles of Programming Languages: Course Outline
Principles of Programming Languages: Course Outline
Course Outline
Outline
Principles of Programming Languages
Course Outline
Lecture Note 1 August 25, 2009 History and Classication of Programming Languages
Course Outline
Course Outline
Outline
Course Objectives
Course Outline
Learn fundamental concepts that underlies in most programming languages. Understand the tradeoff between language design and implementation: how are concepts or features in different languages selected? Understand the language implementation: how are programs parsed and translated by a compiler?
Course Outline
Course Outline
Course Outline
Introduction: history, overview and classication Compiler and Interpreters: how programs are translated to machine codes. Syntax and Semantics Names, Scopes, and Bindings: Control Flow: Subroutines and Parameter Passing: Data Abstraction and Object-Oriented Programming: Functional Programming Concurrency
3 2 1
Outline
Course Outline
Course Outline
Course Outline
Assembly Languages
Mnemonic abbreviations of machine instructions Architecture-dependent: one-to-one correspondence between assembly statement and machine instructions Micros: a sequence of machine instructions
# # # # # #
Daniel J. Ellard -- 02/21/94 add.asm-- A program that computes the sum of 1 and 2, leaving the result in register $t0. Registers used: t0 - used to hold the result. t1 - used to hold the constant 1. li $t1, 1 # load 1 into $t1. add $t0, $t1, 2 # $t0 = $t1 + 2. # end of add.asm
Course Outline
Course Outline
FORTRAN
Example: FORTRAN
Developed in mid 50s. FORTRAN=FORmula TRANslator Arguably the rst high-level programming languages Designed for scientic computation
PROGRAM MAIN INTEGER I, I_START, I_END, I_INC REAL A(100) I_START = 1 I_END = 100 I_INC = 1 DO I = I_START, I_END, I_INC A(I) = 0.0E0 END DO END
Course Outline
Course Outline
LISP
Example: LISP
Developed in the late 50s by McCarthy as a realization of Churchs lambda calculus. Powerful in symbolic computation: LISP=LISt Processing Implicit Memory management: garbage collection Inuenced subsequent functional programming languages: ML, Haskell, etc.
;;;;;;;;; ;;; Function: my-append ;;;;;;;;; ;;; append takes two lists as its arguments. It returns a li ;;; containing the elements of both lists in the following o ;;; all the members of the first list, followed by ;;; all the members of the second ;;;;;;;;; (defun my-append (list1 list2) (if (null list1) list2 (cons (car list1) (my-append (cdr list1) list2)) ))
Principles of Programming Languages 11 / 41 12 / 41
Course Outline
Course Outline
ALGOL
Example: Algol
// Compute The Mean begin integer N; Read Int(N); begin real array Data[1:N]; real sum, avg; integer i; sum:=0; for i:=1 step 1 until N do begin real val; Read Real(val); Data[i]:=if val<0 then -val else val end; for i:=1 step 1 until N do sum:=sum + Data[i]; avg:=sum/N; Print Real(avg) end end
Principles of Programming Languages 13 / 41 14 / 41
Developed in the late 50s: ALGOL 58, 60, 68. ALGOL=ALGOrithmic Language The rst block-based language: local variables are declared in a statement block Inuenced subsequent imperative programming languages: PASCAL, C, etc.
Course Outline
Course Outline
COBOL
Example: COBOL
$ SET SOURCEFORMAT"FREE" IDENTIFICATION DIVISION. PROGRAM-ID. Multiplier. AUTHOR. Michael Coughlan. * Example program using ACCEPT, DISPLAY and MULTIPLY to * get two single digit numbers from the user and multiply them together DATA DIVISION. WORKING-STORAGE SECTION. 01 Num1 01 Num2 01 Result
Developed in the late 50s by Department of Defense. Aimed at business processing: COBOL=COmmon Business-Oriented Language One of the oldest language that is still alive today. Still a lot of lines coded in Cobol especially in large nancial and government related companies.
PROCEDURE DIVISION. DISPLAY "Enter first number (1 digit) : " WITH NO ADVANCING. ACCEPT Num1. DISPLAY "Enter second number (1 digit) : " WITH NO ADVANCING. ACCEPT Num2. MULTIPLY Num1 BY Num2 GIVING Result. DISPLAY "Result is = ", Result. STOP RUN.
Principles of Programming Languages 15 / 41 Principles of Programming Languages 16 / 41
Course Outline
Course Outline
BASIC
Example: BASIC
Developed in 1964, by John George Kemeny and Thomas Eugene Kurtz at Dartmouth Aimed at beginners: BASIC-Beginners All-purpose Symbolic Instruction Code Easy to learn, widespread on microcomputers in the late 1970s and home computers in the 1980s The most popular dialect, Microsoft Visual Basic, remains strong
If name$ = "John" Print "Hello John." Print "Nice to meet you again." Else Print "Hello " + name$ Print "I havent met you before." EndIf
Course Outline
Course Outline
PASCAL
Example: PASCAL
Designed in the late 60s by during 1977-1983, by Niklaus Wirth Named after the French mathematician and philosopher Blaise Pascal Intended for teaching structural programming Simple, quickly gained popularity in education domain Strong inuence on subsequent languages such as Ada, Modula.
If name$ = "John" Print "Hello John." Print "Nice to meet you again." Else Print "Hello " + name$ Print "I havent met you before." EndIf
Course Outline
Course Outline
Ada
Example: Ada
with Ada.Text_IO;
Developed during 1977-1983 by Department of Defense Named after Ada Lovelace (1815-1852), who is often credited as the rst computer programmer Ambitious design, very large and complex Do have a lot of good features: packaging, exception handling, generic programming
procedure Hello is package IO renames Ada.Text_IO; begin IO.Put_Line("Hello, world!"); IO.New_Line; IO.Put_Line("I am an Ada program with package rename."); end Hello;
Course Outline
Course Outline
Simula
Example: Simula 67
Begin Class Glyph; Virtual: Procedure print Is Procedure print;; Begin End; Glyph Class Char (c); Character c; Begin Procedure print; OutChar(c); End; Glyph Class Line (elements); Ref (Glyph) Array elements; Begin Procedure print; Begin Integer i; For i:= 1 Step 1 Until UpperBound (elements, 1) Do elements (i).print; OutImage; End; End; Ref (Glyph) rg; Ref (Glyph) Array rgs (1 : 4); ! Main program; rgs (1):- New Char (A); rgs (2):- New Char (b); rgs (3):- New Char (b); rgs (4):- New Char (a); rg:- New Line (rgs); rg.print; End;
Considered the rst object-oriented programming language Introduced objects, classes, subclasses, virtual methods, coroutines, and features garbage collection. Syntactically, a superset of Algol 60 Strongly inuenced C++
Course Outline
Course Outline
Prolog
Example: Prolog
factorial(0,1).
Developed in the early 1970s by Alain Colmerauer and others Based on formal logic: PROLOG = PROgramming in LOGic Declarative programming language: describing the problem to be solved instead of explicitly constructing the soltuion.
Course Outline
Course Outline
Scheme
Example: Scheme
Developed in 1970s by Guy L. Steele and Gerald Jay Sussman A dialect of Lisp, purely functional The rst programming language with the rst-class support of continuations
; continuation (define (add-if-all-numbers lst) (call/cc (lambda (exit) (let loop ((lst lst) (sum 0)) (if (null? lst) sum (if (not (number? (car lst))) (exit #f) (loop (cdr lst) (+ sum (car lst)))))))))
Course Outline
Course Outline
C++
Developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system Designed for system programming: low level memory management, languages constructs close to machine instructions Very efcient implementation Nowadays widely used in different software platform and computer architectures.
Developed by Bjarne Stroustrup in 1979 at Bell Labs, as an enhancement to C Originally named C with Classes, renamed to C++ in 1983 Added features include classes, virtual functions, operator overloading, multiple inheritance, templates, and exception handling etc. Very complicated language, a challenge to compiler implementors Inherited the popularity of C, widely used in different software platforms and computer architectures.
Course Outline
Course Outline
Java
Haskell
Created by James Gosling in 1991 and released by Sun Microsystem in 1995 Borrowed much of its syntax from C and C++ Greatly simplied from C++, only support object-oriented programming Virtual machine: Write Once, Run Anywhere (WORA) No pointer, but reference, garbage collection, strongly typed
Designed in 1990 by a group of researchers, major release in 1998 A purely functional programming language, using lazy evaluation Named for Haskell Brooks Curry, whose work in mathematical logic serves as a foundation for functional languages Claimed to be one of the best functional programming languages, a result of 20 year cutting-edge research Criticized for having subtle syntax and sophisticated type system
Course Outline
Course Outline
Example: Haskell
Python
{- Factorial -} fac :: Integer -> Integer fac 0 = 1 fac n | n > 0 = n * fac (n-1) {- Fibonacci sequence -} fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
Supports multiple programming paradigms (object-oriented, imperative and functional) Has minimalist core syntax and semantics, but large and comprehensive libraries Features dynamic type system and automatic memory management Uses whitespace indentation as statement block delimiters, very unusual among popular programming languages
Course Outline
Course Outline
Example: Python
More...
# List Comprehension >>> S = [x**2 for x in range(10)] >>> V = [2**i for i in range(13)] >>> M = [x for x in S if x % 2 == 0] >>> >>> print S; print V; print M [0, 1, 4, 9, 16, 25, 36, 49, 64, 81] [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096] [0, 4, 16, 36, 64]
Scripting languages: Perl, Ruby, Javascript, PHP Functional languages: Scheme, ML, OCaml Object-oriented languages: Smalltalk, OCaml, C#
Course Outline
Course Outline
Evolution weve learned better ways of doing things over time socio-economic factors: proprietary interests, commercial advantage Orientation toward special purpose. Orientation toward special hardware. Diverse ideas about what is the most suitable.
Expressive Power Ease of Use and Learn Ease of Implementation Excellent Compilers and Supporting Tools Economics, Patronage, and Inertia
Course Outline
Course Outline
Outline
Course Outline
Course Outline
Comparison
long i n t fac ( i n t n ) { i f ( n < =1) r e t u r n ( 1 ) ; e l s e n=n f a c t o r i a l ( n 1 ) ; return (n ) ;
}
fac ( 0 , 1 ) . f a c ( n , f ) : n > 0 , n1 i s n 1 , f a c ( n1 , f 1 ) , f i s n f 1 . ( define f a c t o r i a l ( lambda ( n ) ( i f (= n 0 ) 1 ( n ( f a c t o r i a l ( n 1 ) ) ) ) ) )