comp313a programming languages more overview. language implementation language definition –syntax,...

33
COMP313A Programming Languages More Overview

Upload: sibyl-farmer

Post on 29-Dec-2015

230 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

COMP313A Programming Languages

More Overview

Page 2: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

Language Implementation

• Language definition– syntax, semantics

• Language translation

Page 3: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

Programming Language Design

Issues

Page 4: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

Programming Language Generations

• First Generation: Assembly language• Second Generation: Unstructured high-level

Languages e.g. Fortran• Third Generation: Structured high-level

languages e.g. Pascal, C, C++, Ada• Fourth Generation: Application-specific

languages for building database-oriented systems

• Fifth Generation: Very high-level languages, especially logic programming languages and other declarative languages. e.g. Prolog

Page 5: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

Imperative versus Declarative Languages

• Imperative programming– Comprises a sequence of commands

imperatives

• Declarative programming– Declare what results we want and leave the

programming language to figure out how to produce them

• Declarative = “What”• Imperative = “How”

Page 6: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

Computational Paradigms

• Imperative/procedural

• Object-oriented

• Functional

• Logic

Page 7: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

What Makes a Good language?

• Page 57 Louden• Human criteria

– Learnability: Is language easy to learn and remember

– Writable: Easy to write correct programs– Readable: Easy to understand programs– Maintainable: Easy to change programs

Page 8: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

What Makes a Good Language…

• Computer Criteria– Implementable: Can language be

implemented– Efficient: Are programs translated and

executed fast enough– Portable: Is language available on most

computers?

Page 9: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

Learnability

• Simplicity.– Simple syntax and semantics.

• Familiarity.– Should use standard notations whenever

possible.

• Uniformity.– Language constructs that are similar

should look and behave similarly.– Constructs that are different should look

different.

Design goals for making languages easier to learn and remember:

Page 10: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

Learnability…• Orthogonality

– Language constructs can be combined in any meaningful way and should not interact in unexpected ways.

• Generality– Have one general construct rather than

several specific ones. Avoid restricting the ways constructs can be used.

• Preciseness– Is the language precisely defined?– ANSI/ISO.– Does it have a formal semantics? Validation

suites?

Page 11: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

Writability

• Expressiveness– Allows programs to be written in the most

natural way. E.g. Build up high-level abstractions

• Error prevention– Language makes some kinds of errors

impossible

• Error Detection– Language allows errors to be found and

reported. E.g. array bounds checking, arithmetic overflow

Language design goals for writability include:

Page 12: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

Readability/Understandability

• Expressiveness – Can also improve readability if the

programmer has used it wisely

• Document support– Essential for understanding large programs

• Language Environment– e.g. browsers, cross-reference tools, pretty

printers, debuggers

Most of the learnability design goals help readabilty:

Page 13: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

Maintainability

• Machine Independence– Ban or isolate machine-specific features

• Modularity – Good modularity constructs allow one part

of a program to be changed without impacting other parts

In addition to the readability and writability design goals, design goals that improve readability include:

Page 14: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

History of Programming

Languages

Page 15: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

Jacquard Loom (Early 1800’s)

• Machines for weaving cloth• Weaving pattern was programmed

by cards / paper tape

Page 16: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

Babbage’s Analytical Engine

• Mechanical digital computer (cogs, levers…)

• Programmed by a sequence of data and operation cards

• Never fully built, but some programs were written by Ada Lovelace (first programmer)

Page 17: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

1940’s: Languages without Machines

• Lambda Calculus by Alonzo Church (1941)– The basis for functional programming languages

• Konrad Zuse, a German engineer working alone while hiding out in the Bavarian Alps, develops Plankalkul (1945)

War Computers/Calculators: Colossus, ENIAC

Page 18: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

1950’s: first Implemented HLLs

• Early 1950’s: First few stored program computers working.– Mark 1, EDSAC, ACE, EDVAC, UNIVAC 1

• Small memory machines• Programmed in machine code• The good old days!!

Page 19: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

Grace Mary Hopper

• Programmer on Mark I, Mark II, and Mark III computers and UNIVAC I, the first large-scale electronic digital computer

• 1949 began work on first compiler A-0– Translated symbolic mathematical code into machine

code

• Then came B-0, later called FLOW-MATIC.– automatic billing and payroll calculation

• Technical advisor to CODASYL responsible for COBOL (1959)

Page 20: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

Grace Hopper…

• It's easier to ask forgiveness than it is to get permission

• A ship in port is safe, but that is not what ships are for. Sail out to sea and do new things

• the most damaging phrase in the language is ‘We've always done it this way’

Page 21: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

FORTRAN (1954-1957)

• IBM “FORmula TRANslating system” for IBM 704 computer

• Major emphasis on compiler producing efficient code

• Became the major scientific/engineering programming language

• Much evolution: FORTRAN II, FORTRAN IV, FORTRAN 66, FORTRAN77, FORTRAN90

Page 22: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

Overview of FORTRAN IV

• Column 1 used to indicate comment lines

• Column 2-5 used for line numbers (optional)

• Data: integer, real, arrays (no chars, records or pointers!)

• Variable declararions are optional (variables starting with I..N are integer, others are real)

Page 23: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

Overview of FORTRAN IV…

• Has a three-way if test, goto statements and computed gotos, but no recursion

• EQUIVALENCE declaration causes variables to be aliased (dangerous!)

Page 24: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

COBOL (1959-1960)

• Common Business-Oriented Language• Developed in 1959 by a group of computer

professionals called the Conference on Data Systems Languages (CODASYL).

• COBOL was the first programming language whose use was mandated by the US Department of Defense

Page 25: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

COBOL…

• English – like verbose syntax (Goal: Human readability)

• Largely ignored by the academic community

• And if you thought COBOL was dead…

Think again.. Object-oriented COBOL is a subset of COBOL 97,

which is the fourth edition in the continuing evolution of ANSI/ISO standard COBOL

Page 26: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

000100 IDENTIFICATION DIVISION. 000200 PROGRAM-ID. HELLOWORLD. 000300 000400* 000500 ENVIRONMENT DIVISION. 000600 CONFIGURATION SECTION. 000700 SOURCE-COMPUTER. RM-COBOL. 000800 OBJECT-COMPUTER. RM-COBOL. 000900 001000 DATA DIVISION. 001100 FILE SECTION. 001200 100000 PROCEDURE DIVISION. 100100 100200 MAIN-LOGIC SECTION. 100300 BEGIN. 100400 DISPLAY " " LINE 1 POSITION 1 ERASE EOS. 100500 DISPLAY "Hello world!" LINE 15 POSITION 10. 100600 STOP RUN. 100700 MAIN-LOGIC-EXIT. 100800 EXIT.

Page 27: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

ALGOL 60 (1958-1960)

• ALGOrithmic Language: general expressive language for describing algorithms

• Used widely in Europe and academia in USA• Modern syntax: defined using BNF, free

format, structure statements, with begin/end pairs

• Type declarations required for all variables

Page 28: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

ALGOL60…

• Introduced recursion, call-by-name and call-by-value

• Required stack-based runtime environment

• Huge influence on later languages: Pascal, C, Module-2, Ada etc

Page 29: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

Call-by-name

• Page 321 Louden• The argument is not evaluated until its

actual use (as a parameter) in the called procedure

• The name of the argument replaces the name of the parameter it corresponds to

Page 30: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

Call-by-name

void inc(int x){x++}

inc(a[5]); inc(a[i]);

Page 31: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

Call-by-nameint i;int a[10];

void inc(int x){ i++; x++; }

main(){ i = 1; a[1] = 1 a[2] = 2;

p(a[i]); return(0); }

Page 32: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

LISP (1956-1962)

• The first functional language• The first language to include garbage collection• Intended for list processing and symbolic

manipulation• Syntax was radically different – lots of parentheses• Efficiency not a huge concern. Ideas more important• Still heavily used today for AI research and

applications• IDE

Page 33: COMP313A Programming Languages More Overview. Language Implementation Language definition –syntax, semantics Language translation

Reverse a list

(Defun reverse (x)(cond ((null x) NIL)

(T (append (reverse (rest start)) (list (first start))))))