Download presentation
1
STRUCTURE OF PROGRAMMING LANGUAGES
Dr Yasser Fouad STRUCTURE OF PROGRAMMING LANGUAGES
2
Book
3
Quote of the Day “A language that doesn't affect
the way you think about programming, is not worth knowing.” - Alan Perlis
4
Then you decide to get a PhD
You get tired of the PowerPoint and its animations. You embed a domain-specific language (DSL) into Ruby. …
5
Reasons for Studying Concepts of Programming Languages
Increased ability to express ideas Improved background for choosing appropriate languages Increased ability to learn new languages Better understanding of significance of implementation Overall advancement of computing
6
How is this class different?
It’s about: foundations of programming langauges but also how to design your own languages how to implement them and about PL tools, such as analyzers also learn about some classical C.S. algorithms.
7
Why a developer needs PL
New languages will keep coming Understand them, choose the right one. Write code that writes code Be the wizard, not the typist. Develop your own language. Are you kidding? No. Learn about compilers and interpreters. Programmer’s main tools.
8
Overview how many languages does one need?
how many languages did you use? Let’s list them here:
9
Develop your own language
Are you kidding? No. Guess who developed: PHP Ruby JavaScript perl Done by smart hackers like you in a garage not in academic ivory tower Our goal: learn good academic lessons so that your future languages avoid known mistakes
10
Programming Domains Scientific applications Business applications
Large number of floating point computations Fortran Business applications Produce reports, use decimal numbers and characters COBOL Artificial intelligence Symbols rather than numbers manipulated LISP Systems programming Need efficiency because of continuous use C Web Software Eclectic collection of languages: markup (e.g., XHTML), scripting (e.g., PHP), general-purpose (e.g., Java)
12
Figure by Brian Hayes (who credits, in part, Éric Lévénez and Pascal Rigaux): Brian Hayes, “The Semicolon Wars.” American Scientist, July-August 2006, pp Also see figure A.1 in [S], p.820.
13
Genealogy of Common Language
14
Programming Paradigms
A programming language is a problem-solving tool. Imperative style: program = algorithms + data good for decomposition Functional style: program = functions o functions good for reasoning Logic programming style: program = facts + rules good for searching Object-oriented style: program = objects + messages good for modeling(!) Other styles and paradigms: blackboard, pipes and filters, constraints, lists, ... PS — Introduction © O. Nierstrasz
15
Language Categories Imperative Functional Logic Object-oriented Markup
Central features are variables, assignment statements, and iteration Examples: C, Pascal Functional Main means of making computations is by applying functions to given parameters Examples: LISP, Scheme Logic Rule-based (rules are specified in no particular order) Example: Prolog Object-oriented Data abstraction, inheritance, late binding Examples: Java, C++ Markup New; not a programming per se, but used to specify the layout of information in Web documents Examples: XHTML, XML
16
Program A program is a machine-compatible representation of an algorithm If no algorithm exists for performing a task, then the task can not be performed by a machine Programs and algorithms they represent collectively referred to as Software
17
What is a Programming Language?
A formal language for describing computation? A “user interface” to a computer? Syntax + semantics? Compiler, or interpreter, or translator? A tool to support a programming paradigm? A programming language is a notational system for describing computation in a machine-readable and human-readable form. — Louden © O. Nierstrasz PS — Introduction
18
Programming Methodologies Influences
1950s and early 1960s: Simple applications; worry about machine efficiency Late 1960s: People efficiency became important; readability, better control structures structured programming top-down design and step-wise refinement Late 1970s: Process-oriented to data-oriented data abstraction Middle 1980s: Object-oriented programming Data abstraction + inheritance + polymorphism
19
Favorite programming language June 2012
Python (3,054) Ruby (1,723) JavaScript (1,415) C (970) C# (829) PHP (666) Java (551) C++ (529) Haskell (519) Clojure (459) CoffeeScript (362) Objective C (326) Lisp (322) Perl (311) Scala (233) Scheme (190) Other (188) Erlang (162) Lua (145) SQL (101)
22
job listings collected from Dice.com
Python 3,456 (+32.87%) Ruby 2,141 (+39.03%) HTML5 ( %) Flash 1,261 (+95.2%) Silverlight 865 (-11.91%) COBOL 656 (-10.75%) Assembler 209 (-1.42%) PowerBuilder (-18.71%) FORTRAN 45 (-33.82%) Java 17,599 (+8.96%) XML 10,780 (+11.70%) JavaScript (+11.64%) HTML 9,587 (-1.53%) C# 9,293 (+17.04%) C++ 6,439 (+7.55%) AJAX 5,142 (+15.81%) Perl 5,107 (+3.21%) PHP 3,717 (+23%)
24
Languages in Common Use
25
A Brief Chronology Early 1950s “order codes” (primitive assemblers)
1957 FORTRAN the first high-level programming language 1958 ALGOL the first modern, imperative language 1960 LISP, COBOL Interactive programming; business programming 1962 APL, SIMULA the birth of OOP (SIMULA) 1964 BASIC, PL/I 1966 ISWIM first modern functional language (a proposal) 1970 Prolog logic programming is born 1972 C the systems programming language 1975 Pascal, Scheme two teaching languages 1978 CSP Concurrency matures FP Backus’ proposal 1983 Smalltalk-80, Ada OOP is reinvented 1984 Standard ML FP becomes mainstream (?) 1986 C++, Eiffel OOP is reinvented (again) 1988 CLOS, Oberon, Mathematica 1990 Haskell FP is reinvented 1990s Perl, Python, Ruby, JavaScript Scripting languages become mainstream 1995 Java OOP is reinvented for the internet 2000 C# PS — Introduction © O. Nierstrasz
26
ENIAC (1946, University of Philadelphia)
ENIAC program for external ballistic equations: 1946 ENIAC was unveiled in Philadelphia. ENIAC represented still a stepping stone towards the true computer, for differently than Babbage, Eckert and Mauchly, although they knew that the machine was not the ultimate in the state-of-the-art technology, completed the construction. ENIAC was programmed through the rewiring the interconnections between the various components and included the capability of parallel computation. ENIAC was later to be modified into a stored program machine, but not before other machines had claimed the claim to be the first true computer was the year in which the first computer meeting took place, with the University of Pennsylvania organizing the first of a series of "summer meetings" where scientists from around the world learned about ENIAC and their plans for EDVAC. Among the attendees was Maurice Wilkes from the University of Cambridge who would return to England to build the EDSAC. Later that year Eckert and Mauchly, in a patent dispute with the University of Pennsylvania, left the University to establish the first computer company -- Electronic Control Corp. with a plan to build the Universal Automatic Computer (UNIVAC). After many crises they built the BINAC for Northrup Aviation, and were taken over by Remington-Rand before the UNIVAC was completed. At the same time the Electronic Research Associates (ERA) was incorporated in Minneapolis and took their knowledge of computing devices to create a line of computers; later ERA was also assimilated into Remington-Rand.
27
Programming the ENIAC
28
ENIAC (1946, University of Philadelphia)
programming done by rewiring the interconnections to set up desired formulas, etc Problem (what’s the tedious part?) programming = rewiring slow, error-prone solution: store the program in memory! birth of von Neuman paradigm 1946 ENIAC was unveiled in Philadelphia. ENIAC represented still a stepping stone towards the true computer, for differently than Babbage, Eckert and Mauchly, although they knew that the machine was not the ultimate in the state-of-the-art technology, completed the construction. ENIAC was programmed through the rewiring the interconnections between the various components and included the capability of parallel computation. ENIAC was later to be modified into a stored program machine, but not before other machines had claimed the claim to be the first true computer was the year in which the first computer meeting took place, with the University of Pennsylvania organizing the first of a series of "summer meetings" where scientists from around the world learned about ENIAC and their plans for EDVAC. Among the attendees was Maurice Wilkes from the University of Cambridge who would return to England to build the EDSAC. Later that year Eckert and Mauchly, in a patent dispute with the University of Pennsylvania, left the University to establish the first computer company -- Electronic Control Corp. with a plan to build the Universal Automatic Computer (UNIVAC). After many crises they built the BINAC for Northrup Aviation, and were taken over by Remington-Rand before the UNIVAC was completed. At the same time the Electronic Research Associates (ERA) was incorporated in Minneapolis and took their knowledge of computing devices to create a line of computers; later ERA was also assimilated into Remington-Rand.
29
Assembly – the language (UNIVAC 1, 1950)
Idea: mnemonic (assembly) code Then translate it to machine code by hand (no compiler yet) write programs with mnemonic codes (add, sub), with symbolic labels, then assign addresses by hand Example of symbolic assembler clear-and-add a add b store c translate it by hand to something like this (understood by CPU) B100 A200 C300 Drop this slide? With assemblers and compilers not yet developed, for the Univac to access a number in memory required that I first give it a specific address out of the 1,000 available locations. For example, to add two numbers together that were found in locations 100 and 200, the following code would have to be executed: Bring the contents of location 100 into the add register. Add the contents of location 200 to the add register. Store the sum, which was in the add register, into location 300. Thus it took three instructions, or one and a half words, to add two numbers together and save the result. The coding would look like this: B100 A200 C300 If we could use symbolic locations and assign the actual locations later, it would help to organize the memory more efficiently. Also, if we changed some record or code, it would not be so tedious to correct the code. After training, we manually coded symbolically such as clear and add a, add b, store c and supplied the exact addresses at the end of coding.
30
Assembly Language ADDI R4 R2 21 ADDI R4,R2,21 Use symbols instead of binary digits to describe fields of instructions. Every aspect of machine visible in program: One statement per machine instruction. Register allocation, call stack, etc. must be managed explicitly. No structure: everything looks the same.
31
Assembler – the compiler (Manchester, 1952)
a loop example, in MIPS, a modern-day assembly code: loop: addi $t3, $t0, -8 addi $t4, $t0, -4 lw $t1, theArray($t3) # Gets the last lw $t2, theArray($t4) # two elements add $t5, $t1, $t2 # Adds them together... sw $t5, theArray($t0) # ...and stores the result addi $t0, $t0, 4 # Moves to next "element“ # of theArray blt $t0, 160, loop # If not past the end of # theArray, repeat jr $ra
32
High-level Language Provides notation to describe problem solving strategies rather than organize data and instructions at machine-level. Improves programmer productivity by supporting features to abstract/reuse code, and to improve reliability/robustness of programs. Requires a compiler.
33
FORTRAN I (1954-57) Langauge, and the first compiler
Produced code almost as good as hand-written Huge impact on computer science Modern compilers preserve its outlines By 1958, >50% of all software is in FORTRAN
34
FORTRAN I Example: nested loops in FORTRAN
a big improvement over assembler, but annoying artifacts of assembly remain: labels and rather explicit jumps (CONTINUE) lexical columns: the statement must start in column 7 The MIPS loop from previous slide, in FORTRAN: DO 10 I = 2, 40 A[I] = A[I-1] + A[I-2] 10 CONTINUE
35
“Hello World” in FORTRAN
PROGRAM HELLO DO 10, I=1,10 PRINT *,'Hello World' 10 CONTINUE STOP END All examples from the ACM "Hello World" project: www2.latech.edu/~acm/HelloWorld.shtml © O. Nierstrasz PS — Introduction
36
Side note: designing a good language is hard
Good language protects against bugs, but lessons take a while. An example that caused a failure of a NASA planetary probe: buggy line: DO 15 I = 1.100 what was intended (a dot had replaced the comma): DO 15 I = 1,100 because Fortran ignores spaces, compiler read this as: DO15I = 1.100 which is an assignment into a variable DO15I, not a loop. This mistake is harder to make (if at all possible) with the modern lexical rules (white space not ignored) and loop syntax for (i=1; i < 100; i++) { … }
37
“Hello World” in COBOL 000100 IDENTIFICATION DIVISION.
PROGRAM-ID. HELLOWORLD. DATE-WRITTEN. 02/05/ :04. 000400* AUTHOR BRIAN COLLINS ENVIRONMENT DIVISION. CONFIGURATION SECTION. SOURCE-COMPUTER. RM-COBOL. OBJECT-COMPUTER. RM-COBOL. DATA DIVISION. FILE SECTION. PROCEDURE DIVISION. MAIN-LOGIC SECTION. BEGIN. DISPLAY " " LINE 1 POSITION 1 ERASE EOS. DISPLAY "HELLO, WORLD." LINE 15 POSITION 10. STOP RUN. MAIN-LOGIC-EXIT. EXIT. © O. Nierstrasz PS — Introduction
38
ALGOL 60 History Committee of PL experts formed in 1955 to design universal, machine-independent, algorithmic language First version (ALGOL 58) never implemented; criticisms led to ALGOL 60 Innovations BNF (Backus-Naur Form) introduced to define syntax (led to syntax-directed compilers) First block-structured language; variables with local scope Structured control statements Recursive procedures Variable size arrays Successes Highly influenced design of other PLs but never displaced FORTRAN Motivations: fear of IBM; targeting general market Recursive procedures — originally thought “academic” Variable size arrays — bound when block is entered © O. Nierstrasz PS — Introduction
39
“Hello World” in BEALGOL
BEGIN FILE F (KIND=REMOTE); EBCDIC ARRAY E [0:11]; REPLACE E BY "HELLO WORLD!"; WHILE TRUE DO WRITE (F, *, E); END; END. © O. Nierstrasz PS — Introduction
40
“Hello World” in PL/1 HELLO: PROCEDURE OPTIONS (MAIN);
/* A PROGRAM TO OUTPUT HELLO WORLD */ FLAG = 0; LOOP: DO WHILE (FLAG = 0); PUT SKIP DATA('HELLO WORLD!'); END LOOP; END HELLO; © O. Nierstrasz PS — Introduction
41
“Hello World” in Functional Languages
SML Haskell print("hello world!\n"); hello() = print "Hello World" © O. Nierstrasz PS — Introduction
42
Goto considered harmful
L1: statement if expression goto L1 statement Dijkstra says: gotos are harmful use structured programming lose some performance, gain a lot of readability how do you rewrite the above code into structured form?
43
Special-Purpose Languages
SNOBOL First successful string manipulation language Influenced design of text editors more than other PLs String operations: pattern-matching and substitution Arrays and associative arrays (tables) Variable-length strings ... Variable-length strings — uncommon in other languages! OUTPUT = 'Hello World!' END © O. Nierstrasz PS — Introduction
44
Object-Oriented Languages
History Simula was developed by Nygaard and Dahl (early 1960s) in Oslo as a language for simulation programming, by adding classes and inheritance to ALGOL 60 Smalltalk was developed by Xerox PARC (early 1970s) to drive graphic workstations Begin while 1 = 1 do begin outtext ("Hello World!"); outimage; end; End; Transcript show:'Hello World';cr © O. Nierstrasz PS — Introduction
45
4GLs “Problem-oriented” languages PLs for “non-programmers”
Very High Level (VHL) languages for specific problem domains Classes of 4GLs (no clear boundaries) Report Program Generator (RPG) Application generators Query languages Decision-support languages Successes Highly popular, but generally ad hoc PLs for “non-programmers” — i.e., as opposed to COBOL! RPG — first 4GL: 1960s Application generators — routine applications Decision-support languages — integrated DB, stats etc. © O. Nierstrasz PS — Introduction
46
“Hello World” in SQL CREATE TABLE HELLO (HELLO CHAR(12)) UPDATE HELLO
SET HELLO = 'HELLO WORLD!' SELECT * FROM HELLO © O. Nierstrasz PS — Introduction
47
Scripting Languages History
Countless “shell languages” and “command languages” for operating systems and configurable applications Unix shell (ca. 1971) developed as user shell and scripting tool HyperTalk (1987) was developed at Apple to script HyperCard stacks TCL (1990) developed as embedding language and scripting language for X windows applications (via Tk) Perl (~1990) became de facto web scripting language echo "Hello, World!" on OpenStack show message box put "Hello World!" into message box end OpenStack puts "Hello World " print "Hello, World!\n"; © O. Nierstrasz PS — Introduction
48
How do Programming Languages Differ?
Common Constructs: basic data types (numbers, etc.); variables; expressions; statements; keywords; control constructs; procedures; comments; errors ... Uncommon Constructs: type declarations; special types (strings, arrays, matrices, ...); sequential execution; concurrency constructs; packages/modules; objects; general functions; generics; modifiable state; ... © O. Nierstrasz PS — Introduction
49
Improved background for choosing appropriate languages
C vs. Modula-3 vs. C++ for systems programming Fortran vs. APL vs. Ada for numerical computations Ada vs. Modula-2 for embedded systems Common Lisp vs. Scheme vs. Haskell for symbolic data manipulation Java vs. C/CORBA for networked PC programs [Scott]
50
Evolution of Programming Languages
ALGOL - 60 (ALGOrithmic Language) Goals : Communicating Algorithms Features : Block Structure (Top-down design) Recursion (Problem-solving strategy) BNF - Specification LISP (LISt Processing) Goals : Manipulating symbolic information Features : List Primitives Interpreters / Environment
51
Evolution of Programming Languages
Pascal Goal : Structured Programming, Type checking, Compiler writing. Features : Rich set of data types for efficient algorithm design E.g., Records, sets, ... Variety of “readable” single-entry single-exit control structures E.g., for-loop, while-loop,... Efficient Implementation Recursive descent parsing
52
Other Languages Functional Logic Object-oriented Hybrid
LISP, Scheme ML, Haskell Logic Prolog Object-oriented Smalltalk, SIMULA, Modula-3, Oberon C++, Java, C#, Eiffel, Ada-95 Hybrid Python, Ruby, Scala Application specific languages and tools
53
Programming Languages
C Bell labs Dennis Ritchie, 1973 C++ Bjarne Stroustrup, 1980 Hybrid OOP Java Sun Microsystems (formally announced in May 1995) Pure OOP Web programming
54
Current Trend Multiparadigm languages
Functional constructs for programming in the small Focus on conciseness and correctness Object-Oriented constructs for programming in the large Focus on programmer productivity and code evolution Example languages Older: Python, Ruby, Recent: Scala, F#, etc
55
Scheme (dialect of LISP)
Recursive definitions Symbolic computation : List Processing Higher-order functions Dynamic type checking Functional + Imperative features Automatic storage management Provides a uniform executable platform for studying, specifying, and comparing languages. The language we use for programming in CS784.
56
Java vs Scala public String buildEpochKey(String... keys) {
//Java - what we're used to seeing public String buildEpochKey(String... keys) { StringBuilder s = new StringBuilder("elem") for(String key:keys) { if(key != null) { s.append(".") s.append(key) } return s.toString(). toLowerCase()
57
Java vs Scala def buildEpochKey(keys: String*): String = {
("elem" +: keys) filter(_ != null) mkString(".") toLowerCase } +: means add the item before the +: to the item after it filter filters a collection based on the closure after it. Filter will pass each item into the closure. If the closure returns true, the item will be added to the new collection, otherwise it won't. _ in a closure is a shortcut for saying the first parameter passed in mkString is Scala's version of join. mkString also has a variant that takes delimiters. toLowerCase is just that. A call on the string that is the result of mkString
58
Implementation Methods
Compilation Programs are translated into machine language Pure Interpretation Programs are interpreted by another program known as an interpreter Hybrid Implementation Systems A compromise between compilers and pure interpreters
59
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
60
The Compilation Process
61
Additional Compilation Terminologies
Load module (executable image): the user and system code together Linking and loading: the process of collecting system program and linking them to user program
62
Pure Interpretation No translation
Easier implementation of programs (run-time errors can easily and immediately displayed) Slower execution (10 to 100 times slower than compiled programs) Often requires more space Becoming rare on high-level languages Significant comeback with some Web scripting languages (e.g., JavaScript)
63
Hybrid Implementation Systems
A compromise between compilers and pure interpreters A high-level language program is translated to an intermediate language that allows easy interpretation Faster than pure interpretation Examples Perl programs are partially compiled to detect errors before interpretation Initial implementations of Java were hybrid; the intermediate form, byte code, provides portability to any machine that has a byte code interpreter and a run-time system (together, these are called Java Virtual Machine)
64
Just-in-Time Implementation Systems
Initially translate programs to an intermediate language Then compile intermediate language into machine code Machine code version is kept for subsequent calls JIT systems are widely used for Java programs .NET languages are implemented with a JIT system
65
Programming Environments
The collection of tools used in software development UNIX An older operating system and tool collection Nowadays often used through a GUI (e.g., CDE, KDE, or GNOME) that run on top of UNIX Borland JBuilder An integrated development environment for Java Microsoft Visual Studio.NET A large, complex visual environment Used to program in C#, Visual BASIC.NET, Jscript, J#, or C++
66
What Does This C Statement Mean?
modifies *p *p++ = q++ increments p increments q Does this mean… … or … or *p = *q; ++p; ++q; *p = *q; ++q; ++p; tp = p; ++p; tq = q; ++q; *tp = *tq;
67
Languages Simula Smalltalk Algol Cobol F# Prolog Pascal Modula-2 ADA
PL/I CORBA PERL BASIC JAVASCRIPT LISP MIRANDA ML SCHEMA SNOBOL APL DELPHI MAYA
68
Can you answer these questions?
Why are there so many programming languages? Why are FORTRAN and COBOL still important programming languages? Which language should you use to implement a spelling checker? A filter to translate upper-to-lower case? A theorem prover? An address database? An expert system? A game server for initiating chess games on the internet? A user interface for a network chess client? © O. Nierstrasz PS — Introduction
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.