Lecture 1: Course Introduction

Similar documents
Lecture 1: Course Introduction

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

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

1DL321: Kompilatorteknik I (Compiler Design 1)

PLAGIARISM. Administrivia. Compilers. CS143 11:00-12:15TT B03 Gates. Text. Staff. Instructor. TAs. Office hours, contact info on 143 web site

Administrivia. Compilers. CS143 10:30-11:50TT Gates B01. Text. Staff. Instructor. TAs. The Purple Dragon Book. Alex Aiken. Aho, Lam, Sethi & Ullman

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

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

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

Compiler Design 1. Introduction to Programming Language Design and to Compilation

Introduction to Programming Languages and Compilers. CS164 11:00-12:30 TT 10 Evans. UPRM ICOM 4029 (Adapted from: Prof. Necula UCB CS 164)

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

Concepts in Programming Languages

Programming Language Design and Implementation. Cunning Plan. Your Host For The Semester. Wes Weimer TR 9:30-10:45 MEC 214. Who Are We?

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

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

Principles of Programming Languages. Lecture Outline

Compilers. Prerequisites

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

Concepts of Programming Languages

CS2303 C14 Systems Programming Concepts. Bob Kinicki

CS 415 Midterm Exam Spring 2002

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

COP 3402 Systems Software. Lecture 4: Compilers. Interpreters

Seminar in Programming Languages

A Tour of Language Implementation

Comp 333: Concepts of Programming Languages Fall 2016

COSC 2P90 Programming Languages & Object-Orientation

Programmiersprachen (Programming Languages)

Introduction. A. Bellaachia Page: 1

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

LECTURE 18. Control Flow

CS 3304 Comparative Languages. Lecture 1: Introduction

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

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

Programming Language Concepts 1982, 1987, Outline. Period

Continuations provide a novel way to suspend and reexecute

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

Low-Level Languages. Computer Programs and Programming Languages

LECTURE 1. Overview and History

15-411/ Compiler Design

Programming Languages, Summary CSC419; Odelia Schwartz

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

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

COSE212: Programming Languages. Lecture 0 Course Overview

Informal Semantics of Data. semantic specification names (identifiers) attributes binding declarations scope rules visibility

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

Introduction to Scientific Computing Languages

Logic Programming II & Revision

COMPILER DESIGN LECTURE NOTES

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

Informatica 3 Syntax and Semantics

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

Compiler Construction D7011E

CSc 372 Comparative Programming Languages

Programming (ERIM) Lecture 1: Introduction to programming paradigms and typing systems. Tommi Tervonen

Outline. Introduction to Programming (in C++) Introduction. First program in C++ Programming examples

CST-402(T): Language Processors

22c:111 Programming Language Concepts. Fall Types I

Introduction to Scientific Computing Languages

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

Introduction. Compilers and Interpreters

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

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

Lecture 16: Static Semantics Overview 1

Design & Implementation Overview

Com S 541. Programming Languages I

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

The role of semantic analysis in a compiler

CSCI 3136 Principles of Programming Languages

Compiler Design. Dr. Chengwei Lei CEECS California State University, Bakersfield

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

Working of the Compilers

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

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

CS 113: Introduction to

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

Compilation 2012 The What and Why of Compilers

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

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

HANDLING NONLOCAL REFERENCES

CS321 Languages and Compiler Design I. Winter 2012 Lecture 1

Formal Languages and Compilers Lecture I: Introduction to Compilers

Data Types. (with Examples In Haskell) COMP 524: Programming Languages Srinivas Krishnan March 22, 2011

Chapter 5 Names, Binding, Type Checking and Scopes

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

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

What is a programming language?

CS 6371: Advanced Programming Languages


Programming Languages Third Edition. Chapter 7 Basic Semantics

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

Static Semantics. Lecture 15. (Notes by P. N. Hilfinger and R. Bodik) 2/29/08 Prof. Hilfinger, CS164 Lecture 15 1

Compiler Construction

COS 140: Foundations of Computer Science

Chapter 1. Preliminaries

Semantic Analysis. Lecture 9. February 7, 2018

Compilation I. Hwansoo Han

Why are there so many programming languages?

Transcription:

Lecture 1: Course Introduction CS164: Programming Languages and Compilers P. N. Hilfinger, 787 Soda Fall 2013 Acknowledgement. Portions taken from CS164 notes by G. Necula. Last modified: Thu Aug 29 16:03:34 2013 CS164: Lecture #1 1

Administrivia Public service announcement: Blueprint is a nonprofit student club aimed at developing technologies for local nonprofit organizations that are making social change. Info sessions Thursday, Sept 5 at 7pm in HP Auditorium and Monday, September 9 at 7pm in 220 Wheeler. Web page: www.calblueprint.org All course information, readings, and documentation is online from the course web page (constantly under construction). Pick up class accounts in lecture today or Wednesday. Go to the class web page and register (Under account/teams/grades). Projects require partnerships of 2 or 3. Start looking. The web page allows you to register teams. For Tuesday, please read Chapter 2 of the online Course Notes. Last modified: Thu Aug 29 16:03:34 2013 CS164: Lecture #1 2

Course Structure Lectures, discussions intended to discuss and illustrate material that you have previously read. Regular homework does theory, practical finger exercises. Done individually. Projects are long programming assignments, done in teams. All submissions electronic. Target language for projects: Python (version 2.5, not latest). Implementation language: C++. You ll find on-line materials on web site. Last modified: Thu Aug 29 16:03:34 2013 CS164: Lecture #1 3

Generic General Advice DBC! RTFM! Last modified: Thu Aug 29 16:03:34 2013 CS164: Lecture #1 4

Plagiarism: Obligatory Warning We have software to detect plagiarism, and we Know How to Use It! If you must use others work (in moderation), cite it! Remember that on projects, you necessarily involve your partner. Most cheating cases result from time pressure. Keep up, and talk to us as early as possible about problems. Last modified: Thu Aug 29 16:03:34 2013 CS164: Lecture #1 5

Project Hidden agenda: programming design and experience. Substantial project in modules. Provides example of how complicated problem might be approached. Validation (testing) part of project. Chance to use version control for real. And this semester (shudder) C++. General rule: start early! Last modified: Thu Aug 29 16:03:34 2013 CS164: Lecture #1 6

Implementing Programming Languages Strategy 1: Interpreter: program that runs programs. Strategy 2: Compiler: program that translates program into machine code (interpreted by machine). Modern trend is hybrid: Compilers that produce virtual machine code for bytecode interpreters. Just-In-Time (JIT) compilers interpret parts of program, compile other parts during execution. Last modified: Thu Aug 29 16:03:34 2013 CS164: Lecture #1 7

Languages Initially, programs hard-wired or entered electro-mechanically Analytical Engine, Jacquard Loom, ENIAC, punched-card-handling machines Next, stored-program machines: programs encoded as numbers(machine language) and stored as data: Manchester Mark I, EDSAC. 1953: IBM develops the 701; all programming done in assembly Problem: Software costs > hardware costs! John Backus: Speedcoding made a 701 appear to have floating point and index registers. Interpreter ran 10 20 times slower than native code. Last modified: Thu Aug 29 16:03:34 2013 CS164: Lecture #1 8

FORTRAN Also due to John Backus (1954 7). Revolutionary idea at the time: convert high-level (algebraic formulae) to assembly. Called automatic programming at the time. Some thought it impossible. Wildly successful: language could cut development times from weeks to hours; produced machine code almost as good as hand-written. Start of extensive theoretical work (and Fortran is still with us!). Last modified: Thu Aug 29 16:03:34 2013 CS164: Lecture #1 9

After FORTRAN Lisp, late 1950s: dynamic, symbolic data structures. Algol 60: Europe s answer to FORTRAN: modern syntax, block structure, explicit declaration. Dijkstra: A marked improvement on its successors. Algol report Set standard for language description. COBOL: late 1950 s (and still with us). Business-oriented. Introduces records (structs). Last modified: Thu Aug 29 16:03:34 2013 CS164: Lecture #1 10

The Language Explosion APL (arrays), SNOBOL (strings), FORMAC (formulae), and many more. 1967-68: Simula 67, first "object-oriented" language. Algol 68: Combines FORTRANish numerical constructs, COBOLish records, pointers, all described in rigorous formalism. Remnants remain in C, but Algol68 deemed too complex. 1968: "Software Crisis" announced. Trend towards simpler languages: Algol W, Pascal, C Last modified: Thu Aug 29 16:03:34 2013 CS164: Lecture #1 11

The 1970s Emphasis on methodology : modular programming, CLU, Modula family. Mid 1970 s: Prolog. Declarative logic programming. Mid 1970 s: ML (Metalanguage) type inference, pattern-driven programming. (Led to Haskell, OCaml). Late 1970 s: DoD starts to develop Ada to consolidate >500 languages. Last modified: Thu Aug 29 16:03:34 2013 CS164: Lecture #1 12

Complexity increases with C++. Then decreases with Java. Into the Present Then increases again (C#, Java 1.5). Proliferation of little or specialized languages and scripting languages: HTML, PHP, Perl, Python, Ruby,... Last modified: Thu Aug 29 16:03:34 2013 CS164: Lecture #1 13

Example: FORTRAN C FORTRAN (OLD-STYLE) SORTING ROUTINE C SUBROUTINE SORT (A, N) DIMENSION A(N) IF (N - 1) 40, 40, 10 10 DO 30 I = 2, N L = I-1 X = A(I) DO 20 J = 1, L K = I - J IF (X - A(K)) 60, 50, 50 C FOUND INSERTION POINT: X >= A(K) 50 A(K+1) = X GO TO 30 C ELSE, MOVE ELEMENT UP 60 A(K+1) = A(K) 20 CONTINUE A(1) = X 30 CONTINUE 40 RETURN END C ---------------------------------- C MAIN PROGRAM DIMENSION Q(500) 100 FORMAT(I5/(6F10.5)) 200 FORMAT(6F12.5) READ(5, 100) N, (Q(J), J = 1, N) CALL SORT(Q, N) WRITE(6, 200) (Q(J), J = 1, N) STOP END Last modified: Thu Aug 29 16:03:34 2013 CS164: Lecture #1 14

Example: Algol 60 comment An Algol 60 sorting program; procedure Sort (A, N) value N; integer N; real array A; begin real X; integer i, j; for i := 2 until N do begin X := A[i]; for j := i-1 step -1 until 1 do if X >= A[j] then begin A[j+1] := X; goto Found end else A[j+1] := A[j]; A[1] := X; Found: end end end Sort Last modified: Thu Aug 29 16:03:34 2013 CS164: Lecture #1 15

An APL sorting program Z SORT A Z A[ A] Example: APL Last modified: Thu Aug 29 16:03:34 2013 CS164: Lecture #1 16

Example: Python (2.5) import sys, re def format(x): return "%10.5f" % x vals = map(float, re.split(r \s+, sys.stdin.read().strip())) vals.sort() print \n.join([.join(map(format, vals[i:i+6])) for i in xrange(0,len(vals),6)]) Last modified: Thu Aug 29 16:03:34 2013 CS164: Lecture #1 17

/* A naive Prolog sort */ Example: Prolog /* permutation(a,b) iff list B is a permutation of list A. */ permutation(l, [H T]) :- append(v,[h U],L), append(v,u,w), permutation(w,t). permutation([], []). /* ordered(a) iff A is in ascending order. */ ordered([]). ordered([x]). ordered([x,y R]) :- X <= Y, ordered([y R]). /* sorted(a,b) iff B is a sort of A. */ sorted(a,b) :- permutation(a,b), ordered(b). Last modified: Thu Aug 29 16:03:34 2013 CS164: Lecture #1 18

Problems to Address How to describe language clearly for programmers, precisely for implementors? How to implement description, and know you re right? Ans: Automatic conversion of description to implementation How to test? How to save implementation effort? With multiple languages to multiple targets: can we re-use effort? How to make languages usable? Handle errors reasonably Detect questionable constructs Compile quickly Last modified: Thu Aug 29 16:03:34 2013 CS164: Lecture #1 19

Classical Compiler Structure (Front) Source Program /* Example */ salary = base + rate[years]; output(salary); Lexical Analysis Token Stream <ID#1, =, ID#2, +, ID#3, [, ID#4, ], ;, ID#5, (, ID#1, ), ;,...> Parsing = ID#1 + ID#2 Abstract Syntax Tree ; [] ID#3 ID#4 ID#5 () ID#1 Static Semantics Optimization Code Generation Optimization Attributed Syntax Tree Optimized Tree Intermediate, Virtual Machine Code A + (double) ID#2 [] (double) (double) ID#3 ID#4 (int) (double[]) Push #2 Push_Addr #3 Push_Addr #4 Index Add Last modified: Thu Aug 29 16:03:34 2013 CS164: Lecture #1 20

Classical Compiler Structure (Back) A Code Generation Real Machine Code Optimization Optimized Real Machine Code (Object file) Back End Linking Executable File Execution Results Other Object Files and Libraries or A Interpretation Results Last modified: Thu Aug 29 16:03:34 2013 CS164: Lecture #1 21