Programming Languages (CS )

Similar documents
Preliminaries. 1. Preliminaries 1.1 Administration. 1.2 Motivation 1.3 Hello, World!

Programming Languages (CS )

Concepts in Programming Languages

CSCI 3136 Principles of Programming Languages

Programming Languages, Summary CSC419; Odelia Schwartz

Topic I. Introduction and motivation References: Chapter 1 of Concepts in programming languages by J. C. Mitchell. CUP, 2003.

Programming Languages 1. Introduction. Oscar Nierstrasz

Introduction. A. Bellaachia Page: 1

Concepts of Programming Languages

Programming Languages 2nd edition Tucker and Noonan"

Com S 541. Programming Languages I

Seminar in Programming Languages

8/27/17. CS-3304 Introduction. What will you learn? Semester Outline. Websites INTRODUCTION TO PROGRAMMING LANGUAGES

Programming Language Concepts 1982, 1987, Outline. Period

Organization of Programming Languages (CSE452) Why are there so many programming languages? What makes a language successful?

CSC 326H1F, Fall Programming Languages. What languages do you know? Instructor: Ali Juma. A survey of counted loops: FORTRAN

Language Translation, History. CS152. Chris Pollett. Sep. 3, 2008.

General Concepts. Abstraction Computational Paradigms Implementation Application Domains Influence on Success Influences on Design

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

Chapter 2. 5 * B => A V 6 7 (subscripts) S 1.n 1.n (data types)

2. Evolution of the Major Programming languages

! Broaden your language horizons! Different programming languages! Different language features and tradeoffs. ! Study how languages are implemented

What Is Computer Science? The Scientific Study of Computation. Expressing or Describing

Programmiersprachen (Programming Languages)

CS 242. Fundamentals. Reading: See last slide

Programming Paradigms

Compiler Construction

Functional Programming. Big Picture. Design of Programming Languages

Logic Programming II & Revision

Programming Languages Third Edition

Chapter 5 Names, Binding, Type Checking and Scopes

Topic IV. Parameters. Chapter 5 of Programming languages: Concepts & constructs by R. Sethi (2ND EDITION). Addison-Wesley, 1996.

CSc 520. Course Outline (Subject to change) Course Outline (Subject to change)... Principles of Programming Languages. Christian Collberg

! Broaden your language horizons. ! Study how languages are implemented. ! Study how languages are described / specified

Topic IV. Block-structured procedural languages Algol and Pascal. References:

What is a programming language?

Principles in Programming: Orientation & Lecture 1. SWE2004: Principles in Programming Spring 2014 Euiseong Seo

Lecture 09. Ada to Software Engineering. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

COSC 2P90 Programming Languages & Object-Orientation

Chapter 2. Pseudocodes: Speedcoding. 2.2 Minimal Hardware Programming: Pseudocodes. Evolution of the Major Programming Languages

CSc 372. Comparative Programming Languages. 2 : Functional Programming. Department of Computer Science University of Arizona

Why are there so many programming languages? Why do we have programming languages? What is a language for? What makes a language successful?

CSc 372 Comparative Programming Languages

Comp 333: Concepts of Programming Languages Fall 2016

Chapter 2 Preview. Preview. History of Programming Languages. History of Programming Languages. History of Programming Languages

CS 565: Programming Languages. Spring 2008 Tu, Th: 16:30-17:45 Room LWSN 1106

MIDTERM EXAMINATION - CS130 - Spring 2005

Informatica 3 Syntax and Semantics

Chapter 2. Chapter 2

CS508-Modern Programming Solved MCQ(S) From Midterm Papers (1 TO 22 Lectures) BY Arslan

Thanks! Review. Course Goals. General Themes in this Course. There are many programming languages. Teaching Assistants. John Mitchell.

Principles in Programming: Orientation & Lecture 1. SWE2004: Principles in Programming Spring 2015 Euiseong Seo

Early computers (1940s) cost millions of dollars and were programmed in machine language. less error-prone method needed

Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

Introduction to Computer Science I

COMPILER DESIGN LECTURE NOTES

CS 415 Midterm Exam Spring 2002

Lecture 1: Course Introduction

CS A331 Programming Language Concepts

CS383 PROGRAMMING LANGUAGES. Kenny Q. Zhu Dept. of Computer Science Shanghai Jiao Tong University

Chapter 1. Preliminaries

CIS24 Project #3. Student Name: Chun Chung Cheung Course Section: SA Date: 4/28/2003 Professor: Kopec. Subject: Functional Programming Language (ML)

Imperative Programming

Continuations provide a novel way to suspend and reexecute

Chapter 1. Preliminaries

1/14/2014. Introduction to CSE 1325 Object Oriented Programming (Using Java) Introduction (Cont.) Introduction

G Programming Languages - Fall 2012

1DL321: Kompilatorteknik I (Compiler Design 1) Introduction to Programming Language Design and to Compilation

Outline. Programming Languages 1/16/18 PROGRAMMING LANGUAGE FOUNDATIONS AND HISTORY. Current

Functional Programming

Programming Languages (CSCI 4430/6430) History, Syntax, Semantics, Essentials, Paradigms

Programming Language Pragmatics

Chapter 3. Describing Syntax and Semantics

Chapter 7. - FORTRAN I control statements were based directly on IBM 704 hardware

1DL321: Kompilatorteknik I (Compiler Design 1) Introduction to Programming Language Design and to Compilation

Why are there so many programming languages?

Evolution of PL s. EECS 476, Prog. Lang. Design/ page 1

CSC 533: Organization of Programming Languages. Spring 2005

LECTURE 18. Control Flow

Chapter 3. Describing Syntax and Semantics ISBN

Languages october 22, 2017 Éric Lévénez < FORTRAN III end-1958 FORTRAN II FORTRAN I october 1956

Defining Program Syntax. Chapter Two Modern Programming Languages, 2nd ed. 1

Lecture 1: Course Introduction

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

COP4020 Programming Languages. Functional Programming Prof. Robert van Engelen

1DL321: Kompilatorteknik I (Compiler Design 1)

Foundations. Yu Zhang. Acknowledgement: modified from Stanford CS242

Chapter 3. Describing Syntax and Semantics

CSE 307: Principles of Programming Languages

Compilers. Prerequisites

Introduction. COMP 524: Programming Language Concepts Björn B. Brandenburg. The University of North Carolina at Chapel Hill

Chapter 5. Names, Bindings, and Scopes

Chapter 1 Preliminaries

PLAGIARISM. Administrivia. Course home page: Introduction to Programming Languages and Compilers

Introduction to Programming Languages and Compilers. CS164 11:00-12:00 MWF 306 Soda

Multi-Paradigm Approach for Teaching Programming

Closures. Mooly Sagiv. Michael Clarkson, Cornell CS 3110 Data Structures and Functional Programming

CS Compiler Construction West Virginia fall semester 2014 August 18, 2014 syllabus 1.0

LECTURE 1. Overview and History

Programming Languages Third Edition. Chapter 7 Basic Semantics

Transcription:

Programming Languages (CS 234319) Prof. Ron Pinter Dept. of CS, Technion Spring 2007 Why Not Study Programming Languages? The expressive power of all programming languages and computational devices is basically the same [the Church- Turing Hypothesis]: The DOS batch language and Java are equivalent The TRS-80 and the latest Giga Hz processors are equivalent No C++ or Java taught No theorems, proofs, lemmas, or integration by parts No easy grades It s s at 8:30am Introduction-2

Why Study Programming Languages? Evaluation of a language s features and usefulness Over 2,000 different languages out there Common concepts and shared paradigms Framework for comparative studies Because it s fun ML is neat Prolog is elegant There is more to it than Pascal, C, C++ Theoretical part will give you a new way of seeing things you thought you knew Will prove useful for other courses: OOP Compilation Software Engineering Semantics of Programming Languages Introduction-3 What is a Paradigm? par a digm (Merriam-Webster Collegiate Dictionary) a philosophical and theoretical framework of a scientific school or discipline within which theories, laws, and generalizations and the experiments performed in support of them are formulated Model, pattern Thomas Kuhn (1922-1996) A set of universally recognized scientific achievements that for a time provide a model for a community practitioners. The Whorfian hypothesis: The language spoken influences the way reality is perceived. In programming languages: a family of languages with similar basic constructs and mental model of execution Introduction-4

Who Needs Programming Languages? Computers' native tongue is machine language Programmers need higher level languages, because They can't read machine language fluently They can't write machine language correctly They can't express their ideas in machine language efficiently A formal language is not only a man-machine interface but also a person-to-person language! Conclusion: Programming languages are a compromise between the needs of humans and the needs of machines Introduction-5 What is a Programming Language? A linguistic tool with formal syntax and semantics A consciously designed artifact that can be implemented on computers A conceptual universe for thinking about programming (Alan Perlis, 1969) Introduction-6

Programming Linguistics Similar to natural linguistics Syntax = Form Semantics = Meaning Natural languages span much greater range are more expressive are more subtle Discipline Natural languages: what s in existing languages Programming languages: better ways to design languages Introduction-7 Syntax and Semantics Every programming language has: Syntax: The form of programs. How expressions, commands, declarations are put together to form a program: Regular expressions Context-free grammars: BNF form, syntax charts Formal Languages course Semantics: The meaning of programs How do they behave when executed on a computer? our main concern Can have the same semantic concept in this written course with different syntax in different languages, or semantically different concepts that use the same syntax! (consider =) Introduction-8

Requirements from a Programming Language Universal: every problem must have a solution Express recursive functions Natural: application domain specific Try writing a compiler in Cobol or a GUI in FORTRAN Implementable: Neither mathematical notation Nor natural language Efficient: open to debate C and FORTRAN vs. SETL Introduction-9 Desiderata for a Programming Language Expressiveness Turing-completeness But also a practical kind of expressiveness: how easy is it to program simple concepts? Efficiency Recursion in functional languages is expressive but sometimes inefficient Is there an efficient way to implement the language (in machine code)? Introduction-10

Desiderata for Programming Languages (cont d) Simplicity - as few basic concepts as possible Sometimes a trade-off with convenience (three kinds of loops in Pascal) Uniformity and consistency of concepts Why does for in Pascal require a single statement while repeat allows any number of statements? Abstraction - language should allow to factor out recurring patterns Clarity to humans the distinction = vs. == in C is a bit confusing Information hiding and modularity Safety - possibility to detect errors at compile time Awk, REXX and SNOBOL type conversions are error prone Introduction-11 Less is More Two program fragments to find the n th Fibonacci number in Algol 68 x,y := 1; to n do (if x<y then x else y) := x+y; x := max(x,y); x,y := 1; to n do begin x,y := y,x; x := x+y end; Introduction-12

Why Ranger 3 Missed the Moon? An application program written in FORTRAN: DO 10 I=1.3 10 Bad lexical definition spaces are immaterial No declaration of variables (x2) Implicit typing (x2) Bad scoping rules Poor control structure specification Lack of diagnostics Introduction-13 What Characterizes a Programming Language 0. Formal Syntax and Semantics 1. Concepts How it handles values How it checks types Its entities for storing values Its means for storing values How it manages control How it attaches names to values How it allows generalization => values, types and expressions => typing systems => storage => commands => sequencers => binding => abstraction Introduction-14

What Characterizes a Programming Language (cont d) 2. Paradigms Imperative programming: Fortran, Cobol, Algol, PL/I, C, Pascal, Ada, C++, Icon, Modula-2, Modula-3, Oberon, Basic. Concurrent programming: Ada, Occam, Par-C. Object-oriented programming: Small-talk, Self, C++, Objective-C, Object Pascal, Beta, CLOS, Eiffel Functional programming: Lisp, Scheme, Miranda, ML. Logic programming: Prolog, Prolog-dialects, Turbo-Prolog, Icon. Constraint programming: CLP, DLP Introduction-15 The Imperative Paradigm Fortran, Algol, C, Pascal, Ada The program has a state reflected by storage and location It comprises commands (assignments, sequencers, etc.) that update the state of the program They can be grouped into procedures and functions There are also expressions and other functional features Most familiar, but a large variety of possibilities must be mastered and understood Models real-world processes, hence still dominant Lends itself to efficient processing (optimizing compilers etc.) Will see Pascal, mainly in examples Introduction-16

The Functional Paradigm Lisp, Scheme, ML, Haskell Everything is a function that takes arguments and returns results Moreover, the functions are just another kind of value that can be computed (created), passed as a parameter, etc. Don t really need assignment operation or sequencers can do everything as returning a result value of computing a function E.g., use recursive activation of functions instead of iteration Elegant, extensible, few basic concepts Used for list manipulation, artificial intelligence, Requires a truly different perception using an imperative programming style in ML is even worse than a word-forword translation among natural languages Will see ML, mainly in the recitations Introduction-17 The Logic Programming Paradigm Prolog, constraint languages, database query languages Predicates as the basis of execution Facts and rules are listed naturally A computation is implicit it shows what follows from the given facts and rules Emphasizes what is needed, rather than how to compute it Used for expert systems Will see the basics of Prolog later in the course Introduction-18

The Object-Oriented Paradigm C++, Smalltalk, Eiffel, Java The world has objects that contain both fields with values and operations (called methods) that manipulate the values Objects communicate by sending messages that ask the object to perform some method on its data Types of objects are declared using classes that can inherit the fields and methods of other classes Has become the primary paradigm because it seems to treat large systems better than other approaches Treated mainly in the follow-up course Object-Oriented Programming (236703) Introduction-19 Extended Backus-Naur Form (EBNF) A meta-notation for describing the grammar of a language Terminals = actual legal strings, written as is, or inside + Nonterminals = concepts of the language, written program or program or program in different variants Rules = expanding a non-terminal to a series of NTs and Ts One nonterminal is designated as the start of any derivation A sequence of terminals not derivable from start symbol by rules of the grammar is illegal is choice among several possibilities [ ] enclose optional constructs { } encloses zero or more repetitions Example: if-stmt = if expression then statement [ else statement ] Introduction-20

Example of EBNF expression = term { add-op term } term = factor { mult-op factor } factor = variable-name number add-op = + - mult-op = / Is a + 2/ b - c 7 a legal expression? Yes, because there is a sequence of rule applications from expression that yields this string (these can be drawn as a syntax tree ) Introduction-21 Observations on Syntax If there are several possible syntax trees for the same sequence of terminal symbols, the sequence is syntactically ambiguous, and that often leads to semantic ambiguity (several possible ways to understand the meaning) Good programming language design avoids ambiguity There are some syntactic rules that cannot be expressed just using EBNF (which gives context-free grammars) Every variable used is previously declared The number of arguments in a procedure call equals the number of arguments in the declaration of the procedure Much more on grammars and identifying legal programs you will learn in the courses Automata and Formal Languages and Compilation Introduction-22

Relations to Other Fields in Computer Science Databases and Information Retrieval: Query languages - languages for manipulating databases. Human-Computer Interaction: Programming Languages are designed to be written and read by humans Operating Systems: Input-Output support. Storage management. Shells are in fact Programming Languages. Computer Architecture: Programming Language design is influenced by architecture and vice versa. Instructions sets are Programming Languages. Hardware design languages. Introduction-23 Closely Related Topics Automata and Formal Languages, Computability: Provide the foundation for much of the underlying theory. Compilation: The technology of processing programming languages. Software engineering: The process of building software systems. Introduction-24

A system for processing a language: Compiler Language Processors Interpreter Syntax directed editor Program checker Program verifier Studied in other courses: Compilation Program verification Software engineering To know the semantics of a language (the function a program encodes) one can ignore its implementation Introduction-25 Programming Languages as Software Tools In general programming languages are software tools - an interface between human clients and lower-level facilities Other software tools: Interactive editors Data transformers (compilers, assemblers, macro processors) Operating systems Tools for program maintenance (script files, debuggers) Properties of programming languages as software tools: Definition of the interface = syntax and semantics Implementation of the interface to the low level facility = compiler Usefulness for the human client = evaluation of programming languages Introduction-26

At the end of the course you ll know What distinguishes different programming languages from one another A variety of mechanisms in familiar and less familiar programming languages Programming in the functional language ML Some basic concepts from Pascal, Prolog and others The main skill: how to learn a new language easily Introduction-27 Possible approaches Define and compare paradigms of programming languages Present formal approaches to syntax and semantics Present ways of implementing and analyzing programs in various programming languages Show the concepts that must be dealt with by any programming language, and the possible variety in treatment Introduction-28

Syllabus Concepts values, types and expressions typing systems storage commands sequencers binding abstraction Paradigms encapsulation functional programming (ML) logic programming (Prolog) A bit of formal semantics (as time permits) Introduction-29 1 Introduction Course Topics *) 2 Values 3 Storage 4 Bindings 5 Abstractio n 6 Encapsulation 7 Type Systems 8 Sequencers 9 Concurrency 10 Imparative Paradigm 12 Object Paradigm 13 Functional Paradigm 11 Concurrent Paradigm 14 Logic Paradigm C Pascal ML Prolog *) according to Watt's book chapters Introduction-30

Text Books Programming Language Concepts and Paradigms, by David A. Watt. Prentice Hall, 1990. ISBN 0-13-7228874-3. Chapters 1-8,10,13-14. Advanced Programming Language Design, by Raphael Finkel. MIT Press, 1996. ISBN 0-8053-1191-2. Selected material. Programming Languages: Concepts and Constructs (2nd Ed), by Ravi Sethi. Addison-Wesley, 1996. ISBN 0-201- 59065-4 Concepts in Programming Languages, by John C. Mitchell. Cambridge University Press, 2002. ISBN 0-5217-8098-5. Introduction-31 Bibliography for Recitations Introduction to Pascal, by Jim Welsh and John Elder. Prentice Hall, 1979. ISBN 0-1349-1522-4. ML for the Working Programmer, by Lawrence. C. Paulson. Cambridge University Press, 1991. ISBN 0-521-39022-2. Prolog Programming for Artificial Intelligence, by Ivan Bratko. Addison-Wesley. ISBN 0-201-14224-4. Programming in Prolog, by W. F. Clocksin and C. S. Mellish. Springer-Verlag, 1984. ISBN 0-387-11046-1. Slides Introduction-32

Administration This is not an internet course! Most material is provided in class and tutorials. Some material available on the web - http://webcourse.cs.technion.ac.il/234319 Official policy will be published at the above site Prerequisites and tzmudim are strictly enforced Running announcements will be sent through the course mailing list; please subscribe from the course s webpage Requests and questions:lilas@cs.technion.ac.il Course staff Prof. Ron Pinter, Taub 705, x4955, pinter@cs Office hours: Tuesday, 10-12. Lila Shnaiderman (head TA), Taub 218, x5651,lilas@cs Alexey Tsitkin, Taub 316, x4341, lexa@cs Introduction-33 Assignments: Assignments and Grading Every 1-2 weeks Weight is up to 20% (TAKEF) teams of 2 (strict!) - matching services provided by teaching assistants Final exam: Date(s) set by the authorities Weight is 80% or more Final Grade: If exam grade > 50: 80% exam, 20% assignments Otherwise: 100% exam Introduction-34

Language Inception and Evolution Initial definition by a single person: Lisp (McCarthy), APL (Iverson), Pascal (Wirth), REXX (Cowlishaw), C++ (Stroustrup), Java (Gosling) small team: C (Kernighan and Ritchie), ML (Milner et al.), Prolog (Clocksin and Mellish), Icon (Griswold and Griswold) committee: FORTRAN, Algol, PL/1, Ada Some survived, many more perished usability compilation feasibility dependence on platform politics and sociology Most successful languages were taken over by a standards committees (ANSI, IEEE, ISO, ) http://www.oreilly.com/news/graphics/prog_lang_poster.pdf Introduction-35 1950 Language Genealogy (till 1990) 1960 Algol-60 Fortran Cobol Lisp 1970 Simula Smalltalk Pascal Algol-68 PL/I C Prolog ML 1980 Ada Miranda 1990 OO lang. C++ Imperative and Concurrent lang. Haskell Functional lang. Introduction-36

Historical Background Until early 1950s: no real programming languages, but rather Automatic Programming, a mixture of assembly languages and other aids for machine code programming. Mnemonic operation codes and symbolic addresses Subroutine libraries where addresses of operands were changed manually Interpretive systems for floating point and indexing Early 1950s: the Laning and Zierler System (MIT): a simple algebraic language, a library of useful functions. 1954: Definition of FORTRAN (FORmula TRANslator). Originally for numerical computing. Symbolic expressions, subprograms with parameters, arrays, for loops, if statements, no blocks, weak control structures 1957: first working compiler Introduction-37 Historical Background (cont d) Early 1960s: Cobol: Data processing. Means for data description. Algol 60: Blocks, modern control structures One of the most influential imperative languages Gave rise to the Algol-like languages for two decades (Pascal, PL/1, C, Algol 68; Simula, Ada) Lisp (list processing language): symbolic expressions (rather than numerical), computation by list manipulation, garbage collection; the first functional language Mid 1960s: PL/1: an attempt to combine concepts from numerical computation languages (FORTRAN, Algol 60) and data processing languages (Cobol). Simula: object oriented, abstract data types Introduction-38

1970-1990: Historical Background Several OO languages: Smalltalk, C++, Eiffel Logic Programming: Prolog Functional Programming: ML, Miranda, Haskell Ada: Another attempt, more successful than PL/I, for a general purpose language, including concurrency. Specific usages: SNOBOL, Icon, Awk, REXX, Perl: String manipulation and scripting SQL: Query language for relational databases Mathematica, Matlab, Python: Mathematical applications... Introduction-39 1990-present: Historical Background Object oriented + WWW: Java, Visual Basic, C# Components and middleware between operating system and application levels Reuse and design patterns become useful and popular Multiple-language systems with standard interface- XML Flexibility in choice of language and moving among languages Introduction-40

How Many Ways to Say "Hello, World"? In the following slides are examples of the most popular computer program "Hello, World" in various programming languages See how many you can recognize? Examples are taken (with alterations) from the Web site: http://www.latech.edu/~acm/helloworld.shtml More examples at http://99-bottles-of-beer.ls-la.net/ (thanks to Michael Bar-Sinai!) Introduction-41 Assembly 8086:.model small.stack 100h Hello, World.data.hello_message db 'Hello, World',0dh,0ah,'$'.code main proc mov ax,@data mov ds,ax mov ah,9 mov dx,ofsett hello_message int 21h mov ax,4c00h int 21h main endp end main Introduction-42

Hello, World FORTRAN: c c Hello, world. c PROGRAM HELLO WRITE(*,10) 10 FORMAT('Hello, world') END Introduction-43 Hello, World PL/I: HELLO: PROCEDURE OPTIONS (MAIN); /* A PROGRAM TO OUTPUT HELLO WORLD */ PUT SKIP DATA('HELLO, WORLD'); END HELLO; Introduction-44

ADA: Hello, World with i_o; use i_o; procedure hello is begin put ("Hello, World"); end hello; Introduction-45 Hello, World Prolog: hello :- printstring("hello, World"). printstring([]). printstring([h T]) :- put(h), printstring(t). Introduction-46

Hello, World SNOBOL4: OUTPUT = 'Hello, World END Introduction-47 Hello, World RPG II: H FSCREEN O F 80 80 CRT C EXCPT OSCREEN E 1 O 12 'HELLO, WORLD' Introduction-48

Hello, World Lisp: (DEFUN HELLO-WORLD () (PRINT (LIST 'HELLO 'WORLD))) SmallTalk: Transcript show:'hello, World';cr Introduction-49 Postscript: Hello, World %!PS 1.00000 0.99083 scale /Courier findfont 12 scalefont setfont 0 0 translate /row 769 def 85 {/col 18 def 6 {col row moveto (Hello, World)show /col col 90 add def} repeat /row row 9 sub def} repeat showpage save restore Introduction-50