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

Similar documents
Programming Languages 2nd edition Tucker and Noonan"

Concepts of Programming Languages

EI326 ENGINEERING PRACTICE & TECHNICAL INNOVATION (III-G) Kenny Q. Zhu Dept. of Computer Science Shanghai Jiao Tong University

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

Com S 541. Programming Languages I

Programming Languages, Summary CSC419; Odelia Schwartz

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

IA010: Principles of Programming Languages

Chapter 1. Preliminaries

Principles of Programming Languages. Lecture Outline

What is a programming language?

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

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

Seminar in Programming Languages

COSE212: Programming Languages. Lecture 0 Course Overview

What is programming? Elements of Programming Languages. From machine code to programming languages. What is a programming language?

NOTE: Answer ANY FOUR of the following 6 sections:

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

CS 242. Fundamentals. Reading: See last slide

Simply-Typed Lambda Calculus

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

Introduction. A. Bellaachia Page: 1

22c:111 Programming Language Concepts. Fall Types I

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

Chapter 1. Preliminaries

CSCI 3136 Principles of Programming Languages

CS558 Programming Languages

G Programming Languages - Fall 2012

Concepts in Programming Languages

INSTITUTE OF AERONAUTICAL ENGINEERING

CS 415 Midterm Exam Spring 2002

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

HANDLING NONLOCAL REFERENCES

Programmiersprachen (Programming Languages)

9/7/17. Outline. Name, Scope and Binding. Names. Introduction. Names (continued) Names (continued) In Text: Chapter 5

Chapter 5. Names, Bindings, and Scopes

St. MARTIN S ENGINEERING COLLEGE Dhulapally, Secunderabad

Chapter 1 Preliminaries

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

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

Why study Programming Language Concepts? Chapter One. Language Evaluation Criteria. Programming Domains. Readability Writability Reliability Cost

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

CSE 307: Principles of Programming Languages

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

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

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

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

Functional Programming

CS 3360 Design and Implementation of Programming Languages. Exam 1

CSc 372 Comparative Programming Languages

The role of semantic analysis in a compiler

CS101 Introduction to Programming Languages and Compilers

Course Syllabus. Programming Language Paradigms. Spring - DIS Copenhagen. Semester & Location: Elective Course - 3 credits.

Comp 333: Concepts of Programming Languages Fall 2016

LECTURE 1. Overview and History

Hi! My name is Sorin. Programming Languages. Why study PL? (discussion) Why study PL? Course Goals. CSE : Fall 2017

Type Systems. Today. 1. Organizational Matters. 1. Organizational Matters. Lecture 1 Oct. 20th, 2004 Sebastian Maneth. 1. Organizational Matters

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

Type Inference Systems. Type Judgments. Deriving a Type Judgment. Deriving a Judgment. Hypothetical Type Judgments CS412/CS413

Programming Languages

Introduction P L COS 301. Fall School of Computing and Information Science University of Maine. Introduction COS 301.

Program Abstractions, Language Paradigms. CS152. Chris Pollett. Aug. 27, 2008.

CMSC 330: Organization of Programming Languages. Administrivia

G Programming Languages - Fall 2012

Foundations. Yu Zhang. Acknowledgement: modified from Stanford CS242

CS 3360 Design and Implementation of Programming Languages. Exam 1

G Programming Languages Spring 2010 Lecture 6. Robert Grimm, New York University

MIDTERM EXAMINATION - CS130 - Spring 2005


CS 314 Principles of Programming Languages

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

PROGRAMMING LANGUAGE PARADIGMS & THE MAIN PRINCIPLES OF OBJECT-ORIENTED PROGRAMMING

CSCI.4430/6969 Programming Languages Lecture Notes

TYPES, VALUES AND DECLARATIONS

CS 241 Data Organization. August 21, 2018

CS 241 Data Organization using C

Programming (Econometrics)

Data Types. Every program uses data, either explicitly or implicitly to arrive at a result.

COSC 2P90 Programming Languages & Object-Orientation

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

SOFTWARE ARCHITECTURE 6. LISP

Chapter 1. Preview. Reason for Studying OPL. Language Evaluation Criteria. Programming Domains

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

11. a b c d e. 12. a b c d e. 13. a b c d e. 14. a b c d e. 15. a b c d e

Functional Programming. Big Picture. Design of Programming Languages

SKILL AREA 304: Review Programming Language Concept. Computer Programming (YPG)

Hi! My name is Sorin. Programming Languages. Why study PL? (discussion) Why study PL? Course Goals. CSE 130 : Fall 2013

Hi! My name is Sorin. Programming Languages. Why study PL? (discussion) Why study PL? Course Goals. CSE 130 : Fall 2014

Programming Languages

INFS 214: Introduction to Computing

Compiler Construction

11/6/17. Outline. FP Foundations, Scheme. Imperative Languages. Functional Programming. Mathematical Foundations. Mathematical Foundations

Lecture 1: Course Introduction

CPS 506 Comparative Programming Languages. Programming Language Paradigm

CS 330 Lecture 18. Symbol table. C scope rules. Declarations. Chapter 5 Louden Outline

CMSC 330: Organization of Programming Languages

Programming Paradigms

CSC 533: Organization of Programming Languages. Spring 2005

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

Transcription:

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

KENNY Q. ZHU Research Interests: Programming Languages Probabilistic Programming Data Processing Concurrency Data & Knowledge Engineering Information extraction Knowledge discovery Natural language understanding Recent Publications: AAAI2018, IJCAI2017, AAAI 2016, KR 2016, AAAI 2015, EMNLP 2015, TACL 2014, ICDE2013, SIGMOD 12, KDD 12 Degrees: Postdoc: Experiences: National University of Singapore (NUS) Princeton University Microsoft Redmond, USA Microsoft Research Asia Faculty at SJTU since 2009 Director of ADAPT Lab 2

ADMINISTRATIVE INFO (I) All-English Course: everything in English! Lecturer: Kenny Zhu, SEIEE #03-541, kzhu@cs.sjtu.edu.cn Office hours: by appointment or after class Teaching Assistant: Yuding Liang, SEIEE #03-341, liangyuding@sjtu.edu.cn Office hours: Thursday 16:00-17:00 Course Web Page (definitive source!): http://www.cs.sjtu.edu.cn/~kzhu/cs383/ 3

ADMINISTRATIVE INFO (II) Format: Lectures on Mon (2 periods) & Thursday (2 periods) Tutorials after every two lectures Led by TA; Your participation is REQUIRED! Reference Texts: Programming Languages Principles and Paradigms, 2 nd Edition, by Tucker & Noonan, McGraw Hill / Tsinghua University Press Practical Foundations for Programming Languages by Robert Harper, Cambridge University Press Types and Programming Languages by Benjamin C. Pierce, The MIT Press. Lecture materials on course web page 4

ADMINISTRATIVE INFO (III) 3-credit course Modes of Assessment: In-class quizzes: 10% Tutorial participation: 5% Assignments: 30% Programming Project: 25% Final Exam: 30% Quizzes Given out at random times 10 on-screen multiple choice questions Bring piece of paper and a pen every time! Tutorials Typically after every two lectures Discuss assignment questions and also issues in project You will be asked to present your answers Volunteer to win extra scores! 5

ADMINISTRATIVE INFO (IV) Assignments Released (usually) every (two) week(s) Due on the following week Submit hard copies to me during Monday s class or to Frank s office Submit code/data to Yuding s email Late submission: -30% of full score for each additional day Assignment solutions to be discussed at the tutorial on Friday following the submission Programming Project Individual project Implement an interpreter for a simple language called simpl Be able to run test programs and produce correct evaluation results Produce a report + code + results: due end of semester 6

7 INTRODUCTION

WHY DO WE LEARN PROGRAMMING LANGUAGES? 8

TWO MYTHS ABOUT THIS COURSE This course about programming. This is another compiler course. 9

WHAT THIS COURSE IS ABOUT Theoretical aspects of the design and implementation of programming languages. The commonalities and differences between various paradigms and languages. So you can: Pick the right language for a project; Design your own language (features); Do programming language research. 10

OUTLINE OF TODAY S LECTURE Principles Paradigms Special Topics A Brief History On Language Design Compilers and Virtual Machines Roadmap of This Course 11

THE FACTORIAL PROGRAM n! = 1 * 2 * * n Or n Õ i=1 n! = i 12

THE FACTORIAL PROGRAM C: int factorial(int n) { int x = 1; while (n>1) { x = x * n; n = n -1; } return x; } Java: class Factorial { public static int fact(int n) { int c, fact = 1; if ( n < 0 ) System.out.println( Wrong Input!"); else { for ( c = 1 ; c <= n ; c++ ) fact = fact*c; return fact; } } } 13

THE FACTORIAL PROGRAM Scheme: Prolog: (define (factorial n) (if (< n 1) 1 (* n (factorial (- n 1))) )) factorial(0, 1). factorial(n, Result) :- N > 0, M is N - 1, factorial(m, SubRes), Result is N * SubRes. 14

PRINCIPLES Programming languages have four properties: Syntax Names Types Semantics For any language: Its designers must define these properties Its programmers must master these properties 15

SYNTAX The syntax of a programming language is a precise description of all its grammatically correct programs. When studying syntax, we ask questions like: What is the basic vocabulary? What is the grammar for the language? How are syntax errors detected? 16

SYNTAX class Factorial { public static int fact(int n) { int c, fact = 1; if ( n < 0 ) System.out.println( Wrong Input!"); else { for ( c = 1 ; c <= n ; c++ ) fact = fact*c; return fact; } } Tokens: Keywords Literals Constants Punctuations } 17

NAMES Various kinds of entities in a program have names: variables, types, functions, parameters, classes, objects, Named entities are bound in a running program to: Scope (static) Visibility Type Lifetime (dynamic and runtime) 18

NAMES class Factorial { public static int fact(int n) { int c, fact = 1; if ( n < 0 ) System.out.println( Wrong Input!"); else { for ( c = 1 ; c <= n ; c++ ) fact = fact*c; return fact; } } } 19

TYPES A type is a collection of values and a collection of operations on those values. Simple types numbers, characters, booleans, Structured types Strings, lists, trees, hash tables, Function types Simple operations like +, -, *, / More complex/general function: (arrow) type Generic types (polymorphism) A language s type system can help: Determine legal operations Detect type errors 20

TYPES class Factorial { public static int fact(int n) { int c, fact = 1; if ( n < 0 ) System.out.println( Wrong Input!"); else { for ( c = 1 ; c <= n ; c++ ) fact = fact*c; return fact; } } } 21

SEMANTICS The meaning of a program is called its semantics. In studying semantics, we ask questions like: When a program is running, what happens to the values of the variables? (operational semantics) What does each expression/statement mean? (static semantics) What underlying model governs run-time behavior, such as function call? (dynamic semantics) How are objects allocated to memory at run-time? 22

SEMANTICS class Factorial { public static int fact(int n) { int c, fact = 1; if ( n < 0 ) System.out.println( Wrong Input!"); else { for ( c = 1 ; c <= n ; c++ ) fact = fact*c; return fact; value } } 23 reference

PARADIGMS A programming paradigm is a pattern of problemsolving thought that underlies a particular genre of programs and languages. There are four main programming paradigms: Imperative Object-oriented Functional Logic (declarative) 24

IMPERATIVE PARADIGM Follows the classic von Neumann-Eckert model: Program and data are indistinguishable in memory Program = a sequence of commands State = values of all variables when program runs Large programs use procedural abstraction Example imperative languages: Cobol, Fortran, C, Ada, Perl, 25

THE VON NEUMANN-ECKERT MODEL 26

OBJECT-ORIENTED (OO) PARADIGM An OO Program is a collection of objects that interact by passing messages that transform the state. When studying OO, we learn about: Sending Messages objects are active Inheritance Polymorphism Example OO languages: Smalltalk, Java, C++, C#, and Python 27

FUNCTIONAL PARADIGM Functional programming models a computation as a collection of mathematical functions. Set of all inputs = domain Set of all outputs = range Functional languages are characterized by: Functional composition Recursion No state changes: no variable assignments x := x + 1 (wrong!) Example functional languages: Lisp, Scheme, ML, Haskell, 28

LOGIC PARADIGM Logic programming declares what outcome the program should accomplish, rather than how it should be accomplished. parent(x, Y) :- father(x, Y). parent(x, Y) :- mother(x, Y). grandparent(x, Y) :- parent(x, Z), parent(z, Y).?- grandparent(x, jim). Declarative! When studying logic programming we see: Programs as sets of constraints on a problem Programs that achieve all possible solutions Programs that are nondeterministic Example logic programming languages: Prolog, CLP 29

MODERN LANGUAGES ARE MULTI-PARADIGM Haskell (F + I) Scala (F + I + O) OCaml (F + I + O) F Sharp (F + I + O) 30

SPECIAL TOPICS Concurrency E.g., Client-server programs Event handling E.g., GUIs, home security systems Correctness How can we prove that a program does what it is supposed to do under all circumstances? Why is this important??? 31

A BRIEF HISTORY How and when did programming languages evolve? What communities have developed and used them? Artificial Intelligence Prolog, CLP, (Python) Computer Science Education Pascal, Logo Science and Engineering Fortran, Ada, ML, Haskell Information Systems Cobol, SQL Systems and Networks C, C++, Perl, Python World Wide Web HTML, Java, Javascript, PHP 32

33

ON LANGUAGE DESIGN Design Constraints Computer architecture Technical setting Standards Legacy systems Design Outcomes and Goals 34

35

WHAT MAKES A SUCCESSFUL LANGUAGE? Key characteristics: Simplicity and readability Clarity about binding Reliability Support Abstraction Orthogonality Efficient implementation 36

SIMPLICITY AND READABILITY Small instruction set E.g., Java vs. Scheme Simple syntax E.g., C/C++/Java vs. Python Benefits: Ease of learning Ease of programming 37

CLARITY ABOUT BINDING A language element is bound to a property at the time that property is defined for it. So a binding is the association between an object and a property of that object Examples: a variable and its type a variable and its value Early binding takes place at compile-time Late binding takes place at run time 38

RELIABILITY A language is reliable if: Program behaviour is the same on different platforms E.g., early versions of Fortran Type errors are detected E.g., C vs. Haskell Semantic errors are properly trapped E.g., C vs. C++ Memory leaks are prevented E.g., C vs. Java 39

LANGUAGE SUPPORT Accessible (public domain) compilers/interpreters Java (open) vs. C# (closed) Good texts and tutorials Wide community of users Integrated with development environments (IDEs) Eclipse vs. vim Visual Studio vs. Emacs 40

ABSTRACTION IN PROGRAMMING Data Programmer-defined types/classes Class libraries Procedural Programmer-defined functions Standard function libraries 41

ORTHOGONALITY A language is orthogonal if its features are built upon a small, mutually independent set of primitive operations. while loop vs. for loop in C Fewer exceptional rules = conceptual simplicity E.g. our tutorials are usually on Friday except the last week of each month or when Yuding is busy with his research on coding mining E.g., restricting types of arguments to a function Tradeoffs with efficiency 42

EFFICIENT IMPLEMENTATION Embedded systems Real-time responsiveness (e.g., navigation) Failures of early Ada implementations Web applications Responsiveness to users (e.g., Google search) Corporate database applications Efficient search and updating AI applications Modeling human behaviors 43

COMPILERS AND INTERPRETERS Compiler produces machine code Interpreter executes instructions on a virtual machine Example compiled languages: Fortran, Cobol, C, C++ Example interpreted languages: Scheme, Haskell, Python, Perl Hybrid compilation/interpretation The Java Virtual Machine (JVM).java.class.class executes on JVM 44

THE COMPILING PROCESS 45

THE INTERPRETING PROCESS 46

COURSE ROADMAP Mathematic foundation inductive definition and inductive proofs Untyped Lambda Calculus Simply-typed Lambda Calculus Extensions to Simply-typed Lambda Calculus Going Imperative Memory Management Subtyping Type Inference Case Study: Imperative Programming Case Study: Object-Oriented Programming Case Study: Functional Programming Case Study: Logic Programming Special Topic: Concurrency 47