programming languages. 2 outline definition of software definition of programming language ...

Download Programming Languages. 2 Outline  Definition of Software  Definition of Programming Language  History of Programming Languages  Programming Language

If you can't read please download the document

Upload: darren-melton

Post on 18-Jan-2018

247 views

Category:

Documents


1 download

DESCRIPTION

3 What is Software (Application)?  Hardware  physical and tangible  provides necessary resources for computation and storage  Operating System  manages computer hardware and software resources  provides common services for sofware applications  functions as a mediator between the HW and SW running within the operating system  Software Application (Computer Program)  Aims to solve a specific problem  A set of instructions/statements..

TRANSCRIPT

Programming Languages 2 Outline Definition of Software Definition of Programming Language History of Programming Languages Programming Language Concepts 3 What is Software (Application)? Hardware physical and tangible provides necessary resources for computation and storage Operating System manages computer hardware and software resources provides common services for sofware applications functions as a mediator between the HW and SW running within the operating system Software Application (Computer Program) Aims to solve a specific problem A set of instructions/statements.. 4 Machine Instructions (Code) 5 Executed by Central Processing Unit (CPU) / Processor Performs a specific task Computational Instructions Add, subtract, increment, invert bits, etc. Data Transfer Instructions Load, store, move, etc. Flow Control Instructions Branch, jump, etc. Input/output Instructions In, Out Lowest level representation of Software Application/Program 2/16/ The von Neumann Architecture 2/16/ The von Neumann Architecture Fetch-execute-cycle (on a von Neumann architecture computer) initialize the program counter repeat forever fetch the instruction pointed by the counter increment the counter decode the instruction execute the instruction end repeat 8 Assembly Language low-level programming language for a programmable device represent various instructions in symbolic code and a more understandable form. very strong (generally one-to-one) correspondence between the language and the machine code instructions. specific to a particular computer architecture 9 High Level Programming Languages Go to the Bank Withdraw Money Go to the Market Buy some Vegetables High Level Language Machine Instructions 10 High Level Programming Languages Java Code Byte Code 11 High Level Programming Languages 2/16/ Compilation Translate high-level program (source language) into machine code (machine language) Slow translation, fast execution Compilation process has several phases: lexical analysis: converts characters in the source program into lexical units syntax analysis: transforms lexical units into parse trees which represent the syntactic structure of program Semantics analysis: generate intermediate code code generation: machine code is generated 2/16/ The Compilation Process 14 Programming Languages A programming language is a notation for instructing a computer to perform specific taks A vocabulary Set of grammatical rules Programming languages have evolved over time First programming languages were developed in the 1950s Since then thousands of languages have been developed Different programming languages provide programmers with different capabilities and styles 2/16/2016 Early programming languages 15 Classic C Simula Pascal Algol68 BCPL Fortran Lisp COBOL Algol60 PL/I 1950s:1960s:1970s: Red==major commercial use Yellow==will produce important offspring Stroustrup/Programming 2/16/2016 Modern programming languages 16 Object Pascal C++ Java95 C#Ada98 C++98 Java04 C++11 Python Lisp Smalltalk Fortran77 Ada Eiffel Simula67 COBOL89 PHP C89 Pascal PERL Visual Basic COBOL04 Javascript Stroustrup/Programming 2/16/2016 Why do we design and evolve languages? There are many diverse applications areas No one language can be the best for everything Programmers have diverse backgrounds and skills No one language can be best for everybody Problems change Over the years, computers are applied in new areas and to new problems Computers change Over the decades, hardware characteristics and tradeoffs change Progress happens Over the decades, we learn better ways to design and implement languages 17Stroustrup/Programming 2/16/2016 slide 18 Assembly Languages Invented by machine designers the early 1950s Mnemonics instead of binary opcodes push ebp mov ebp, esp sub esp, 4 push edi Reusable macros and subroutines 2/16/2016 slide 19 FORTRAN Procedural, imperative language Still used in scientific computation Developed at IBM in the 1950s by John Backus ( ) On FORTRAN: We did not know what we wanted and how to do it. It just sort of grew. The first struggle was over what the language would look like. Then how to parse expressions it was a big problem 2/16/2016 slide 20 From FORTRAN to LISP Anyone could learn Lisp in one day, except that if they already knew FORTRAN, it would take three days - Marvin Minsky 2/16/2016 slide 21 LISP Invented by John McCarthy (b. 1927, Turing award: 1971) Formal notation for lambda-calculus Pioneered many PL concepts Automated memory management (garbage collection) Dynamic typing 2/16/2016 slide 22 LISP Quotes The greatest single programming language ever designed --Alan Kay LISP being the most powerful and cleanest of languages, that's the language that the GNU project always prefer -- Richard Stallman Programming in Lisp is like playing with the primordial forces of the universe. It feels like lightning between your fingertips. -- Glenn Ehrlich Lisp has all the visual appeal of oatmeal with fingernail clippings mixed in -- Larry Wall LISP programmers know the value of everything and the cost of nothing -- Alan Perlis 2/16/2016 slide 23 Algol 60 Designed in Great influence on modern languages Formally specified syntax (BNF) Peter Naur: 2005 Turing award Lexical scoping: begin end or {} Modular procedures, recursive procedures, variable type declarations, stack storage allocation Birth of computer science -- Dijkstra A language so far ahead of its time that it was not only an improvement on its predecessors, but also on nearly all its successors -- Hoare 2/16/2016 slide 24 Algol 60 Sample real procedure average(A,n); real array A; integer n; begin real sum; sum := 0; for i = 1 step 1 until n do sum := sum + A[i]; average := sum/n end; set procedure return value by assignment 2/16/2016 slide 25 Algol 60 Legacy Another line of development stemming from Algol 60 has led to languages such as Pascal and its descendants, e.g., Euclid, Mesa, and Ada, which are significantly lowerlevel than Algol. Each of these languages seriously restricts the block or procedure mechanism of Algol by eliminating features such as call by name, dynamic arrays, or procedure parameters. - John C. Reynolds 2/16/2016 slide 26 Algol 68 Very elaborate type system Complicated type conversions Idiosyncratic terminology Types were called modes Arrays were called multiple values vW grammars instead of BNF Context-sensitive grammar invented by A. van Wijngaarden Eliminated pass-by-name Considered difficult to understand 2/16/2016 slide 27 Pascal Designed by Niklaus Wirth 1984 Turing Award Revised type system of Algol Good data structure concepts Records, variants, subranges More restrictive than Algol 60/68 Procedure parameters cannot have procedure parameters Popular teaching language Simple one-pass compiler 2/16/2016 slide 28 SIMULA 67 Ole-Johan Dahl ( ) Kristen Nygaard ( ) Joint 2001 Turing Award First object-oriented language Objects and classes Subclasses and inheritance Virtual procedures 2/16/2016 slide 29 BCPL / B / C Family Born of frustration with big OSes and big languages (Multics, PL/I, Algol 68) Keep lexical scope and recursion Low-level machine access Manual memory management Explicit pointer manipulation Weak typing (introduced in C) Systems programming for small-memory machines PDP-7, PDP-11, later VAX, Unix workstations and PCs C has been called a portable assembly language 2/16/2016 slide 30 C Bell Labs 1972 (Dennis Ritchie) Development closely related to UNIX 1983 Turing Award to Thompson and Ritchie Added weak typing to B int, char, their pointer types Typed arrays = typed pointers int a[10]; x = a[i]; means x = *(&a[0]+i*sizeof(int)) Compiles to native code 2/16/2016 slide 31 Evolution of C : new features; compiler ported unsigned, long, union, enums 1978: K&R C book published 1989: ANSI C standardization Function prototypes as in C++ 1999: ISO 9899:1999 also known as C99 Inline functions, C++-like decls, bools, variable arrays Concurrent C, Objective C, C*, C++, C# Portable assembly language Early C++, Modula-3, Eiffel source-translated to C 2/16/2016 slide 32 C++ Bell Labs 1979 (Bjarne Stroustrup) C with Classes (C++ since 1983) Influenced by Simula Originally translated into C using Cfront, then native compilers GNU g++ Several PL concepts Multiple inheritance Templates / generics Exception handling 2/16/2016 slide 33 Java Sun (James Gosling) Originally called Oak, intended for set top boxes Mixture of C and Modula-3 Unlike C++ No templates (generics), no multiple inheritance, no operator overloading Like Modula-3 (developed at DEC SRC) Explicit interfaces, single inheritance, exception handling, built-in threading model, references & automatic garbage collection (no explicit pointers!) Generics added later 2/16/2016 slide 34 Other Important Languages Algol-like Modula, Oberon, Ada Functional ISWIM, FP, SASL, Miranda, Haskell, LCF, ML, Caml, Ocaml, Scheme, Common LISP Object-oriented Smalltalk, Objective-C, Eiffel, Modula-3, Self, C#, CLOS Logic programming Prolog, Gdel, LDL, ACL2, Isabelle, HOL 2/16/2016 slide 35 And More Data processing and databases Cobol, SQL, 4GLs, XQuery Systems programming PL/I, PL/M, BLISS Specialized applications APL, Forth, Icon, Logo, SNOBOL4, GPSS, Visual Basic Concurrent, parallel, distributed Concurrent Pascal, Concurrent C, C*, SR, Occam, Erlang, Obliq 2/16/2016 slide 36 Brave New World Programming tool mini-languages awk, make, lex, yacc, autoconf Command shells, scripting and web languages sh, csh, tcsh, ksh, zsh, bash Perl, JavaScript, PHP, Python, Rexx, Ruby, Tcl, AppleScript, VBScript Web application frameworks and technologies ASP.NET, AJAX, Flash, Silverlight Note: HTML/XML are markup languages, not programming languages, but they often embed executable scripts like Active Server Pages (ASPs) & Java Server Pages (JSPs) 2/16/2016 slide 37 Why So Many Languages? There will always be things we wish to say in our programs that in all languages can only be said poorly. - Alan Perlis 2/16/2016 slide 38 What Do They Have in Common? Lexical structure and analysis Tokens: keywords, operators, symbols, variables Regular expressions and finite automata Syntactic structure and analysis Parsing, context-free grammars Pragmatic issues Scoping, block structure, local variables Procedures, parameter passing, iteration, recursion Type checking, data structures Semantics What do programs mean and are they correct 2/16/2016 Syntax and Semantics The syntax of a programming language is the rules of the language. Each programming language has its own syntax. The syntax of each programming language must be precise, or the computer will not understand the instruction and will give you a syntax error. 2/16/2016 Syntax and Semantics The semantics of a particular instruction is what it does. SyntaxSemantics PRINT Hello World!These examples all display printf (Hello World!);the text Hello World put Hello World! into field displayMessage displayMessage.Text = Hello World 2/16/2016 Syntax and Semantics Examples of the same syntax, but different semantics: SyntaxSemantics number = 10In Visual Basic, gives the value 10 to the variable called number number = 10In COMAL, this is part of a condition e.g. IF number = 10 THEN N.B. Syntax is the way in which you give instructions to the computer using a software development environment. Semantics is the meaning or effect of these instructions. 2/16/2016 Modularity Modularity means that when a program is designed and written, it is divided up into smaller sections called subprograms or sub-routines. Subprograms may be called in any order in a program and they may be reused many times over. Each sub program performs a particular task within the program. Subprograms may be written at the same time as the rest of the program or they may by pre-written as a library module. 2/16/2016 Modularity There are two types of modules or subprograms. Procedures Before a procedure may be used in program, it must be defined. Defining a procedure gives it a name and also allows the programmer to state which data the procedure requires to have sent to it from the program. Data is sent to a procedure using parameters. 2/16/2016 Modularity When a procedure receives data, it carries out an operation using the data and makes results available to the program. These results may simply be displayed on screen from within the procedure or they may be passed back out of the procedure to another procedure again using parameters. A procedure is said to produce an effect. 2/16/2016 Modularity Functions A function is similar to a procedure but returns a single value to a program. Like a procedure, a function must be defined and given a name before it can be used in a program. The name of the function is used to represent a variable containing the value to be returned. A user-defined function is a function which is created within a program rather than being already present or pre-defined as part of the normal syntax of a programming language. 2/16/2016 Objects and operations An operation is a process which is carried out on an item of data. An object is the item of data which is involved in the process. 2/16/2016 Objects and operations Arithmetic Operations Arithmetic operations are calculated involving numeric data (objects). The set of arithmetic operations includes add, subtract, multiply and divide. These operators are represented in many programming languages by using the symbols +, -, * and /. 2/16/2016 Objects and Operations Example of arithmetical operations: Put v_num1 + v_num2 into v_total the objects are v_Num1 and v_Num2, the operation is add. 2/16/2016 Objects and Operations String operations Can process string data. String operations include joining strings, known as concatenation, and selecting parts of strings, known as substrings. 2/16/2016 Objects and Operations Example of string operations - concatenation: Put v_firstinitial & v_surInitial into v_initials From the initials program. This is concatenation. Example of string operations - substring: Put char 1 of v_firstname into v_firstInitial From the initials program. This is concatenation. 2/16/2016 Objects and Operations Relational operations use relational operators to compare data and produce a Boolean answer of true of false. The set of relational operators include: =equals >greater than =greater than or equal to = 1) AND (Month = 1 AND Month = 1 AND Month