CS558 Programming Languages

Similar documents
CS558 Programming Languages. Winter 2013 Lecture 1

COMP 201: Principles of Programming

Programmazione Avanzata

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

Overview. Overview. Programming problems are easier to solve in high-level languages

Concepts in Programming Languages

Compiler Construction D7011E

What is a Compiler? Compiler Construction SMD163. Why Translation is Needed: Know your Target: Lecture 8: Introduction to code generation

Programming Languages, Summary CSC419; Odelia Schwartz

Lecture #16: Introduction to Runtime Organization. Last modified: Fri Mar 19 00:17: CS164: Lecture #16 1

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

CIT Week13 Lecture

CS321 Languages and Compiler Design I. Winter 2012 Lecture 1

Com S 541. Programming Languages I

Second Part of the Course

Y86 Processor State. Instruction Example. Encoding Registers. Lecture 7A. Computer Architecture I Instruction Set Architecture Assembly Language View

CS 33: Week 3 Discussion. x86 Assembly (v1.0) Section 1G

Machine-Level Programming II: Control and Arithmetic

Instruction Set Architecture

CISC 360 Instruction Set Architecture

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

CS 31: Intro to Systems Functions and the Stack. Martin Gagne Swarthmore College February 23, 2016

administrivia today start assembly probably won t finish all these slides Assignment 4 due tomorrow any questions?

CS , Fall 2004 Exam 1

Introduction. A. Bellaachia Page: 1

Instruction Set Architecture

Instruction Set Architecture

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

CS241 Computer Organization Spring Addresses & Pointers

Instruction Set Architecture

CSCI 3136 Principles of Programming Languages

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

LECTURE 18. Control Flow

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

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

CS , Fall 2001 Exam 1

Introduction to Computer Science I

CS2303 C14 Systems Programming Concepts. Bob Kinicki

Process Layout and Function Calls

CS 3304 Comparative Languages. Lecture 1: Introduction

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

Credits to Randy Bryant & Dave O Hallaron

CS213. Machine-Level Programming III: Procedures

CS558 Programming Languages


Lecture 1: Introduction

Concepts of Programming Languages

AS08-C++ and Assembly Calling and Returning. CS220 Logic Design AS08-C++ and Assembly. AS08-C++ and Assembly Calling Conventions

Process Layout, Function Calls, and the Heap

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

CAS CS Computer Systems Spring 2015 Solutions to Problem Set #2 (Intel Instructions) Due: Friday, March 20, 1:00 pm

Lecture 1. Introduction to course, Welcome to Engineering, What is Programming and Why is this the first thing being covered in Engineering?

Assembly III: Procedures. Jo, Heeseung

ASSEMBLY III: PROCEDURES. Jo, Heeseung

IA010: Principles of Programming Languages

Machine-Level Programming II: Arithmetic & Control. Complete Memory Addressing Modes

CS 314 Principles of Programming Languages

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College February 9, 2016

THEORY OF COMPILATION

ASSEMBLY II: CONTROL FLOW. Jo, Heeseung

INTRODUCTION PRINCIPLES OF PROGRAMMING LANGUAGES. Norbert Zeh Winter Dalhousie University 1/10

Assembly III: Procedures. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

CS241 Computer Organization Spring Loops & Arrays

CSc 372 Comparative Programming Languages

Self-assessment Exercise

Sungkyunkwan University

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

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

Chapter 3 Machine-Level Programming II Control Flow

Programming (Econometrics)

Machine-Level Programming II: Arithmetic & Control /18-243: Introduction to Computer Systems 6th Lecture, 5 June 2012

System Programming and Computer Architecture (Fall 2009)

Assembly II: Control Flow. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

More Lambda Calculus and Intro to Type Systems

1 /* file cpuid2.s */ 4.asciz "The processor Vendor ID is %s \n" 5.section.bss. 6.lcomm buffer, section.text. 8.globl _start.

Welcome to CS 135 (Winter 2018)

Computer Science Final Examination Wednesday December 13 th 2006

CS558 Programming Languages

CS 31: Intro to Systems ISAs and Assembly. Kevin Webb Swarthmore College September 25, 2018

Code Generation. Lecture 30

CS 201 Winter 2014 (Karavanic) Final Exam

Machine Programming 1: Introduction

Lecture 1: Course Introduction

CS558 Programming Languages Winter 2018 Lecture 4a. Andrew Tolmach Portland State University

Assembly Language: Function Calls

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

Chapter 5 Names, Binding, Type Checking and Scopes

CS 3110 Lecture 1 Course Overview

CS558 Programming Languages

CS61 Section Solutions 3

Handout #2: Machine-Level Programs

CSC 2400: Computing Systems. X86 Assembly: Function Calls

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

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007

CSc 372. Comparative Programming Languages. 1 : Introduction. Department of Computer Science University of Arizona

Assembly Language: Function Calls" Goals of this Lecture"

Machine Level Programming II: Arithmetic &Control

Chapter 5. Names, Bindings, and Scopes

Lab 10: Introduction to x86 Assembly

Chapter 6 Control Flow. June 9, 2015

Transcription:

CS558 Programming Languages Winter 2017 Lecture 1a Andrew Tolmach Portland State University 1994-2017 1

What programming languages do you know? Some historically interesting and/or currently visible languages: FORTRAN, COBOL, (Visual) BASIC, ALGOL-60, ALGOL-68, PL/I, C, C++, RPG, Pascal, Modula, Lisp, Scheme, ML, Haskell, F#, Ada, Prolog, Curry, Snobol, ICON, Java, C#, JavaScript, Go, Dart, Swift, Rust, perl, tcl, Python,... Don t forget things like: - HTML, PHP, other web page description languages - SQL, other database query languages - EXCEL formula language 2

What languages? Source: spectrum.ieee.org/static/interactive-the-top-programming-languages-2016 3

What languages? 4

What languages? 5

What languages? History of Programming Languages 1954 1960 1965 1970 1975 1980 1985 1990 1995 2000 2001 2002 2003 2004 1986 1990 1990 1991 1991 1993 1994 1995 1996 1996 1997 1997 2000 2001 2001 2003 2003 2004 www.oreilly.com For more than half of the fifty years computer programmers have been writing code, O Reilly has provided developers with comprehensive, in-depth technical information. We ve kept pace with rapidly changing technologies as new languages have emerged, developed, and matured. Whether you want to learn something new or need answers to tough technical questions, you ll find what you need in O Reilly books and on the O Reilly Network. This timeline includes fifty of the more than 2500 documented programming languages. It is based on an original diagram created by Éric Lévénez (www.levenez.com), augmented with suggestions from O Reilly authors, friends, and conference attendees. For information and discussion on this poster, go to www.oreilly.com/go/languageposter. 2004 O Reilly Media, Inc. O Reilly logo is a registered trademark of O Reilly Media, Inc. All other trademarks are property of their respective owners. part#30417 6

Why are coders angry? Programmers carve out a sliver of cognitive territory for themselves and go to conferences, and yet they know their position is vulnerable. They get defensive when they hear someone suggest that Python is better than Ruby, because [insert 500-comment message thread here]. Is the next great wave swelling somewhere, and will it wash away Java when it comes? Will Go conquer Python? Do I need to learn JavaScript to remain profitable? Programmers are often angry because they re often scared. We are, most of us, stumbling around with only a few candles to guide the way. We can t always see the whole system, so we need to puzzle it out, bit by bit, in the dark. - Paul Ford, What is Code?, Bloomberg Businessweek, 6/11/15 7

Course Goals Learn fundamental structure of programming languages Understand key issues in language design and implementation Become aware of range of available languages and their uses Learn how to learn a new language Get a small taste of programming language theory 8

Course Method Conventional survey textbook, with broad coverage of languages Organized around key anatomical features of PLs Expressions, control flow, functional abstraction, state, types, objects, modules, Lab exercises mostly involving implementing interpreters for toy languages Exercises will use Scala, a modern language that blends the object-oriented (OO) and functional (FP) paradigms 9

X Course Non-Goals X X Teaching you how to program Teaching you how to program in Scala X although you will learn something about this! X X Surveying the details of lots of languages Covering all important programming paradigms X e.g. we ll skip logic programming and concurrency X Learning how real compilers & interpreters work 10

High-level Programming Languages Consider a simple algorithm for testing primality. In Scala, using imperative programming style: // return true if n has no divisor in the interval [2,n) def isprime(n:int) : Boolean = { for (d <- 2 until n) if (n%d == 0) return false; true } 11

High-level Programming Languages In Scala, using a local recursive function: // return true if n has no divisor in the interval [2,n) def isprime(n:int) : Boolean = { // return true if n has no divisor in the interval [d,n) def nodivfrom (d:int) : Boolean = (d >= n) ((n % d!= 0) && nodivfrom (d+1)) nodivfrom(2) } 12

In Intel X86 (32bit) assembler.globl isprime isprime: pushl %ebp ; set up procedure entry movl %esp,%ebp pushl %esi pushl %ebx movl 8(%ebp),%ebx ; fetch arg n from stack movl $2,%esi ; set divisor d := 2 cmpl %ebx,%esi ; compare n,d jge true ; jump if d >= n loop: movl %ebx,%eax ; set n into... cltd ;... dividend register idivl %esi ; divide by d testl %edx,%edx ; remainder 0? jne next ; jump if remainder non-0 xorl %eax,%eax ; set ret value := false(0) jmp done next: incl %esi ; increment d cmpl %ebx,%esi ; compare n,d jl loop ; jump if d < n true: movl $1,%eax ; set ret value := true(1) done: leal -8(%ebp),%esp ; clean up and exit popl %ebx popl %esi leave ret 13

What make a language high-level? Complex expressions (arithmetic, logical,...) Structured control (loops, conditionals, cases,...) Composite types (arrays, records,...) Type declarations and type checking Multiple data storage classes (global/local/heap/ GC?) Procedures/functions, with private scope (first class?) Non-local control (exceptions, threads,...) Data abstraction (ADTs, modules, objects...) 14

What does hardware give us? Low-level machine instructions Control flow based on labels and conditional branches Explicit locations (e.g. registers) for values and intermediate results of computations Flat memory model Explicit memory management (e.g., stacks for procedure local data) 15

How do we bridge the gap? Two classic approaches: A compiler translates high-level language programs into a lower-level language (e.g. machine code) High-level source program Compiler Input Low-level target program Output 16

How do we bridge the gap? Two classic approaches: An interpreter is a fixed program that reads in (the representation of) an arbitrary high-level program and executes it High-level source program Input Interpreter Output 17

How do we bridge the gap? Two classic approaches: A compiler translates high-level language programs into a lower-level language (e.g. machine code) An interpreter is a fixed program that reads in (the representation of) an arbitrary high-level program and executes it Compilers can generate code that runs much faster than interpreted code Interpreters are quicker and easier to write, maintain and understand 18

Combined approaches High-level source program Compiler1 Intermediate language program Compiler2 In Interpreter Out In Low-level target program Out 19

Stack machines: an intermediate language A stack machine is a simple architecture based on a stack of operand values Each machine instruction pops its operands from the stack and pushes its result back on So instructions are very simple, because there s no need to specify operand locations Often used in abstract machines, such as the Java Virtual Machine (which Scala also uses) Often compile from high-level language to stack machine byte code which is then interpreted (or perhaps further compiled to machine code) 20

Stack machine instructions Instruction set for a very simple stack machine Instruction Stack before Stack after Side effects CONST i s1... sn i s1... sn - LOAD x s1... sn Vars[x] s1... sn - STORE x s1... sn s2... sn Vars[x] := s1 PLUS s1 s2 s3... sn (s2+s1) s3... sn - MINUS s1 s2 s3... sn (s2-s1) s3... sn - Here Vars[] is an auxiliary array mapping variables to values. 21

Stack machine example Here s a stack machine program corresponding to the simple statement c=3-a+(b-7) Code Stack Vars[] CONST 3 LOAD a MINUS LOAD b CONST 7 MINUS PLUS STORE c a=100, b=200 3 a=100, b=200 100 3 a=100, b=200-97 a=100, b=200 200-97 a=100, b=200 7 200-97 a=100, b=200 193-97 a=100, b=200 96 a=100, b=200 a=100, b=200,c=96 22

Stack machine example Here s a stack machine program corresponding to the simple statement c=3-a+(b-7) CONST 3 LOAD a Is this code sequence unique? MINUS LOAD b CONST 7 MINUS PLUS Observe that high-level expressions are more flexible than machine code STORE c 23

Other themes in the study of programming languages Paradigms Imperative Object-oriented Functional Logic Concurrent/Parallel Scripting Language Design Criteria Expressiveness Efficiency Correctness Scale Programming in the Small - what s important for 10 2 lines? Programming in the Large - what s important for10 6 lines? 24

Course Structure Weekly reading assignments Short in-class quiz each week covering reading due that week Weekly lab assignments (Mostly) working with interpreters for toy languages that illustrate important language features Implementation in Scala You are encouraged to work collaboratively on these assignments (but everyone must submit separately) 25

Books First edition is available free on line, and is good enough for us. 26

Grading 5% Weekly Quizzes 15% Weekly Labs 35% Midterm (Thursday Feb. 9) 45% Final exam (Tuesday Mar. 21 at 5:30pm) The labs don t count for much directly, but you are unlikely to pass the exams unless you do them Again, collaboration on the labs is encouraged, but you must submit individually to get credit (and to learn) 27

WebLab Web-based system for assignments Assignments are issued You develop solutions in the embedded editor (or in your preferred stand-alone environment) You test your solutions against your own tests and against (secret) tests we provide We can help you debug problems via discussions You submit your solutions Your scores are automatically recorded We (usually) publish correct solutions 28

WebLab 4pm Tuesday 1am Wednesday 29