Docsity

Programming Language - Lecture Slides | 198 314, Exams of Computer Science

Toggle sidebar
bg1
1
Introduction 1, CS314 Fall02, BGR 1
198:314, Sects 6-11
198:314, Sects 6-11
Principles of Programming
Principles of Programming
Languages
Languages
Fall 2002
Fall 2002
http://
http://remus
remus.
.rutgers
rutgers.
.edu
edu/cs314/
/cs314/
Prof. Barbara G. Ryder
Core 311, 732-445-3699
http://www.cs.rutgers.edu/~ryder
Introduction 1, CS314 Fall02, BGR 2
Introduction
Introduction
•Administrivia
•Why study PLs?
•Paradigms:
–Imperative
–Object-oriented
–Functional
–Logic
•History of Programming Languages
Louden, Chs1-2
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Programming Language - Lecture Slides | 198 314 and more Exams Computer Science in PDF only on Docsity!

Introduction 1, CS314 Fall02, BGR 1

198:314, Sects 6-11 198:314, Sects 6-

Principles of Programming Principles of Programming

Languages Languages

Fall 2002Fall 2002

http:// http://remusremus..rutgersrutgers..eduedu/cs314//cs314/

Prof. Barbara G. Ryder

Core 311, 732-445-

[email protected]

http://www.cs.rutgers.edu/~ryder

Introduction 1, CS314 Fall02, BGR 2

Introduction Introduction

  • Administrivia
  • Why study PLs?
  • Paradigms:
    • Imperative
    • Object-oriented
    • Functional
    • Logic
  • History of Programming Languages

Louden, Chs1-

Introduction 1, CS314 Fall02, BGR 3

198:314 Fall 2002 198:314 Fall 2002

  • Co-ordinated class, all programming projects, book homeworks and tests are same across all lectures
  • Class webpage
    • – http://remus.rutgers.edu/cs314http://remus.rutgers.edu/cs
    • Look at Course Information for rules, grading, exam policy, important dates, etc.
    • Read about Academic Integrity
    • Review posted Syllabus with project due dates
    • Check Programming Projects and Non-programming Homework for assignments
    • Visit Useful Websites for additional info on PLs we study
  • Four programming projects posted and submitted

for grading electronically

  • Midterm and Final Exams

Introduction 1, CS314 Fall02, BGR 4

198:314 Fall 2002 198:314 Fall 2002

• Lecture webpages

  • TTh Aftn http://remus.rutgers.edu/cs314/f2002/ryder/
  • TTh Night http://remus.rutgers.edu/cs314/f2002/ryderNight/
  • Lecture notes available online in PDF
  • Only print out 2-up or 4-up to save paper
  • Recitation attendance and participation counts in your final grade

Introduction 1, CS314 Fall02, BGR 7

What is a programming What is a programming

language? language?

“a language intended for use by a person to express a process by which a computer can solve a problem” --Hope and Jipping

“a set of conventions for communicating an algorithm” --E. Horowitz

“ the art of programming is the art of organizing complexity” --E. Dijkstra, 1972

Introduction 1, CS314 Fall02, BGR 8

Why learn more than one PL? Why learn more than one PL?

  • Each language paradigm encourages thinking about a problem in a particular manner - Finding a natural match between problem and PL
  • Somewhat different functionality supplied by different paradigms
  • Computer professionals must be multi-lingual
    • PLs change over time as computer architecture changes
    • Specific applications sometimes result in specialized PLs
    • Need to understand each PLs functionality and limitations
    • Also need to understand some things about PL implementation

Introduction 1, CS314 Fall02, BGR 9

Imperative ParadigmImperative Paradigm

  • Underlying notion of an abstract machine
    • Von Neumann architecture
      • Store (memory)
      • Accumulator (ALU)
      • Load/store into memory
    • Key operation: assignment

Introduction 1, CS314 Fall02, BGR 10

ImperativeImperative^ PLsPLs

Fortran

C

SUM = 0 DO 11 K=1,N SUM = SUM + 2*K 11 CONTINUE

sum = 0; for (k = 1; k <= n; ++k) sum += 2*k;

sum := 0; for k := 1 to n do sum := sum + 2*k;

Pascal

Sum up twice each number from 1 to N.

Introduction 1, CS314 Fall02, BGR 13

Functional Paradigm Functional Paradigm

  • Process of problem solution expressed as a sequence

of operations on the data

  • (Pure) value binding through parameter passing
  • No store accessible through names
  • No iteration
  • Key operation: function application (with recursion)

Introduction 1, CS314 Fall02, BGR 14

Functional Paradigm Functional Paradigm

(define (sumdble n) (if (= n 0) 0 (+ (* n 2) (sumdble (- n 1))) ) )

(sum 4) evaluates to 20 = 2+4+6+

Scheme

Introduction 1, CS314 Fall02, BGR 15

Logic Paradigm Logic Paradigm

  • Program is a formal description of characteristics

required of a problem solution

  • Programs tell what should be not how to make it so
  • Solutions through a reasoning process called theorem proving
  • Key operation: unification

Introduction 1, CS314 Fall02, BGR 16

Logic Paradigm Logic Paradigm

sum(0,0). sum(N,S) :- NN is N - 1, sum(NN, SS), S is N * 2 + SS. (^) ?- sum(1,2). yes ?- sum (2,4). no ?-sum(20,S). S = 420 ?-sum (X,Y). X = 0 = Y

Prolog

Introduction 1, CS314 Fall02, BGR 19

Compilation Compilation

scanner

parser

intermediate code generator

optimizer

code generator

assembler linker

compiler

Introduction 1, CS314 Fall02, BGR 20

Compilation Compilation

scanner

parser

intermediate code generator

position = initial + rate * 60;

id1 := id2 + id3 * 60

optimizer

code generator

assembler

linker

Introduction 1, CS314 Fall02, BGR 21

Compilation Compilation

scanner

parser

intermediate code generator

symbol table (position, ...) (initial, …) (rate, …)

:= parse tree

id1 +

**id2 ***

id3 int-to-real

tmp1 = inttoreal (60) tmp2 = id3 * tmp tmp3 = id2 + tmp id1 = tmp

Introduction 1, CS314 Fall02, BGR 22

Compilation Compilation

optimizer

code generator

assembler

linker

tmp1 = inttoreal (60) tmp2 = id3 * tmp id1 = id2 + tmp

movf id3, R mulf #60.0, R movf id2, R addf R2, R movf R1, id1 (^) move R1, R-base, R-offset …

movf R1, 45733

Introduction 1, CS314 Fall02, BGR 25

History ofHistory of PLsPLs - 2- 2

  • 1950’s United States, first high-level PLs invented
    • Fortran 1954-57, John Backus (IBM on 704) designed for numerical scientific computation - fixed format for punched cards - implicit typing - only counting loops, if test versus zero - only numerical data - 1957 optimizing Fortran compiler translates into code as efficient as hand-coded

Introduction 1, CS314 Fall02, BGR 26

History ofHistory of^ PLsPLs^ - 3- 3

  • Algol60 1958-60, designed by international committee for numerical scientific computation [Fortran] - block structure with lexical scope - free format, reserved words - while loops, recursion - explicit types - BNF developed for formal syntax definition
  • Cobol 1959-60, designed by committee in US, manufacturers and DoD for business data processing - records - focus on file handling - English-like syntax

Introduction 1, CS314 Fall02, BGR 27

History ofHistory of PLsPLs - 4- 4

  • APL 1956-60 Ken Iverson, (IBM on 360, Harvard) designed for array processing
  • LISP 1956-62, John McCarthy (MIT on IBM704, Stanford) designed for non-numerical computation - uniform notation for program and data - new conditional control structure (COND) - recursion as main control structure
  • Snobol 1962-66, Farber, Griswold, Polansky (Bell Labs) designed for string processing

Introduction 1, CS314 Fall02, BGR 28

Hisory Hisory ofof PLsPLs - 5- 5

  • PL/I 1963-66, IBM designed for general purpose computing [Fortran, Algol60, Cobol] - user controlled exceptions - multi-tasking
  • Simula67 1967, Dahl and Nygaard (Norway) designed as a simulation language [Algol60] - data abstraction - inheritance of properties
  • Algol68 1963-68, designed for general purpose computing [Algol60] - orthogonal language design - interesting user defined types

Introduction 1, CS314 Fall02, BGR 31

History ofHistory of PLsPLs - 8- 8

  • Modula 1977 N. Wirth (ETH), designed language for large software development [Pascal] - to control interfaces between sets of procedures or modules - real-time programming
  • Ada 1979, US DoD committee designed as general purpose PL - explicit parallelism - rendezvous - exception handling and generics ( packages )
  • C++ 1985, Bjorne Stroustrup (Bell Labs) general purpose
    • goal of type-safe object-oriented PL
    • compile-time type checking
    • templates

Introduction 1, CS314 Fall02, BGR 32

History ofHistory of^ PLsPLs^ - 9- 9

  • SML ~ 1990, R. Milner
    • Strict, polymorphic, functional PL with compile-time type inference and checking and modules
    • SML/NJ compiler (Bell Labs, Princeton)
  • Java ~1995, J. Gosling (SUN)
    • Aimed at portability across platform through use of JVM - abstract machine to implement the PL
    • Aimed to fix some problems with previous OOPLs ® multiple inheritance ® static vs dynamic objects
    • Ubiquitous exceptions
    • Thread objects
  • Haskell ~1998, (newest version)
    • Polymorphic, typed, lazy, purely functional