330 likes | 591 Vues
COMP313A Programming Languages. More Overview. Language Implementation. Language definition syntax, semantics Language translation. Programming Language Design Issues. Programming Language Generations. First Generation: Assembly language
E N D
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
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”
Computational Paradigms • Imperative/procedural • Object-oriented • Functional • Logic
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
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?
Learnability Design goals for making languages easier to learn and remember: • 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.
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?
Writability Language design goals for writability include: • 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
Readability/Understandability Most of the learnability design goals help readabilty: • 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
Maintainability In addition to the readability and writability design goals, design goals that improve readability include: • 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
Jacquard Loom (Early 1800’s) • Machines for weaving cloth • Weaving pattern was programmed by cards / paper tape
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)
1940’s: Languages without Machines War Computers/Calculators: Colossus, ENIAC • 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)
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!!
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)
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’
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
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)
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!)
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
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
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.
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
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
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
Call-by-name void inc(int x) {x++} inc(a[5]); inc(a[i]);
Call-by-name int i; int a[10]; void inc(int x) { i++; x++; } main() { i = 1; a[1] = 1 a[2] = 2; p(a[i]); return(0); }
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
Reverse a list (Defun reverse (x) (cond ((null x) NIL) (T (append (reverse (rest start)) (list (first start))))))