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)

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

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

Concepts of Programming Languages

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

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

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

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.

Concepts in Programming Languages

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

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

Introduction. A. Bellaachia Page: 1

Principles of Programming Languages. Lecture Outline

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

CS 415 Midterm Exam Spring 2002

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

CS2303 C14 Systems Programming Concepts. Bob Kinicki

LECTURE 1. Overview and History

LECTURE 18. Control Flow

Programming Language Concepts 1982, 1987, Outline. Period

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

Compilers. Prerequisites

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

A Tour of Language Implementation

COSC 2P90 Programming Languages & Object-Orientation

Programmiersprachen (Programming Languages)

Continuations provide a novel way to suspend and reexecute

COP 3402 Systems Software. Lecture 4: Compilers. Interpreters

Low-Level Languages. Computer Programs and Programming Languages

Programming Languages, Summary CSC419; Odelia Schwartz

CSCI 3136 Principles of Programming Languages

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

Introduction to Scientific Computing Languages

Logic Programming II & Revision

COMPILER DESIGN LECTURE NOTES

Comp 333: Concepts of Programming Languages Fall 2016

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

15-411/ Compiler Design

Informatica 3 Syntax and Semantics

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

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

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

Introduction to Scientific Computing Languages

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

Compilation 2012 The What and Why of Compilers

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

CS 3304 Comparative Languages. Lecture 1: Introduction

CS321 Languages and Compiler Design I. Winter 2012 Lecture 1

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

Compiler Construction D7011E

CSc 372 Comparative Programming Languages

The role of semantic analysis in a compiler

CST-402(T): Language Processors

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

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

Chapter 5 Names, Binding, Type Checking and Scopes

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

Working of the Compilers

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

Introduction. Compilers and Interpreters

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

Design & Implementation Overview

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

Lecture 16: Static Semantics Overview 1

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

Formal Languages and Compilers Lecture I: Introduction to Compilers

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

CS 113: Introduction to

Seminar in Programming Languages

CS153: Compilers Lecture 1: Introduction

CS 6371: Advanced Programming Languages


Programming Languages Third Edition. Chapter 7 Basic Semantics

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

Chapter 1. Preliminaries

Semantic Analysis. Lecture 9. February 7, 2018

Compilation I. Hwansoo Han

Why are there so many programming languages?

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

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

CS 415 Midterm Exam Spring SOLUTION

G Programming Languages - Fall 2012

COMP 201: Principles of Programming

CSE 504: Compiler Design

What is a programming language?

Chapter 1. Preliminaries

CSC 533: Organization of Programming Languages. Spring 2005

Topic 9: Type Checking

Topic 9: Type Checking

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

G Programming Languages - Fall 2012

Transcription:

Lecture 1: Course Introduction CS164: Programming Languages and Compilers P. N. Hilfinger, 787 Soda Spring 2015 Acknowledgement. Portions taken from CS164 notes by G. Necula. Last modified: Wed Jan 21 01:57:08 2015 CS164: Lecture #1 1

Administrivia All course information, readings, and documentation is online from the course web page (constantly under construction). Get a class account electronically from the website with your CalId (under Account Administration), and register it there. If you don t have a CalId, send me mail. Projects require partnerships of 2 4. Start looking now. Please read Chapter 2 of the online Course Notes for the next few lectures. Last modified: Wed Jan 21 01:57:08 2015 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: Wed Jan 21 01:57:08 2015 CS164: Lecture #1 3

Generic General Advice DBC! RTFM! Last modified: Wed Jan 21 01:57:08 2015 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: Wed Jan 21 01:57:08 2015 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: Wed Jan 21 01:57:08 2015 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: Wed Jan 21 01:57:08 2015 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: Wed Jan 21 01:57:08 2015 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: Wed Jan 21 01:57:08 2015 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: Wed Jan 21 01:57:08 2015 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: Wed Jan 21 01:57:08 2015 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: Wed Jan 21 01:57:08 2015 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: Wed Jan 21 01:57:08 2015 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: Wed Jan 21 01:57:08 2015 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: Wed Jan 21 01:57:08 2015 CS164: Lecture #1 15

An APL sorting program Z SORT A Z A[ A] Example: APL Last modified: Wed Jan 21 01:57:08 2015 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: Wed Jan 21 01:57:08 2015 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: Wed Jan 21 01:57:08 2015 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: Wed Jan 21 01:57:08 2015 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: Wed Jan 21 01:57:08 2015 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: Wed Jan 21 01:57:08 2015 CS164: Lecture #1 21