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

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

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

Programming Language Design and Implementation. Wes Weimer MW 2:00 3:15 Thornton E-303

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

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

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

1DL321: Kompilatorteknik I (Compiler Design 1)

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

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

COMP 181 Compilers. Administrative. Last time. Prelude. Compilation strategy. Translation strategy. Lecture 2 Overview

Compilers. Lecture 2 Overview. (original slides by Sam

ICOM 4036 Spring 2004

Programming Language Specification and Translation. ICOM 4036 Fall Lecture 3

Introduction to Compilers

Introduction. Compilers and Interpreters

CS131: Programming Languages and Compilers. Spring 2017

Compilers. Introduction. Yannis Smaragdakis, U. Athens (original slides by Sam

Compilers and Interpreters

Lexical Analysis. Lecture 2-4

Lecture 1: Course Introduction

Lecture 1: Course Introduction

trends in programming languages

CS 415 Midterm Exam Spring 2002

Formal Languages and Compilers Lecture I: Introduction to Compilers

Administrivia. Lexical Analysis. Lecture 2-4. Outline. The Structure of a Compiler. Informal sketch of lexical analysis. Issues in lexical analysis

Introduction to Lexical Analysis

Introduction to Lexical Analysis

Syntactic Analysis. CS345H: Programming Languages. Lecture 3: Lexical Analysis. Outline. Lexical Analysis. What is a Token? Tokens

Lexical Analysis. Lecture 3-4

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

Lexical Analysis. Chapter 2

Philadelphia University Faculty of Information Technology Department of Computer Science --- Semester, 2007/2008. Course Syllabus

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

CS415 Compilers Overview of the Course. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

ECE573 Introduction to Compilers & Translators

CSCI 3136 Principles of Programming Languages

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

CS 4120 and 5120 are really the same course. CS 4121 (5121) is required! Outline CS 4120 / 4121 CS 5120/ = 5 & 0 = 1. Course Information

15-411/ Compiler Design

CS453 Compiler Construction

Lexical Analysis. Lecture 3. January 10, 2018

Cunning Plan. One-Slide Summary. Functional Programming. Functional Programming. Introduction to COOL #1. Classroom Object-Oriented Language

Compiling Techniques

Semantic Analysis. Lecture 9. February 7, 2018

CS-XXX: Graduate Programming Languages. Lecture 9 Simply Typed Lambda Calculus. Dan Grossman 2012

Semester Review CSC 301

Functional Programming. Introduction To Cool

CS 242. Fundamentals. Reading: See last slide

Lexical Analysis. Finite Automata

Compiler Construction D7011E

Cunning Plan. Informal Sketch of Lexical Analysis. Issues in Lexical Analysis. Specifying Lexers

More Lambda Calculus and Intro to Type Systems

CSE 582 Autumn 2002 Exam 11/26/02

Principles of Programming Languages. Lecture Outline

Lecture 16: Static Semantics Overview 1

Syntax. A. Bellaachia Page: 1

CS 3110 Lecture 1 Course Overview

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

Introduction to Compiler Construction

CSE 504: Compiler Design

Compiler Design. Computer Science & Information Technology (CS) Rank under AIR 100

Introduction to Compiler Construction

Welcome to CS 115 (Winter 2018)

CS153: Compilers Lecture 1: Introduction

Implementation of Lexical Analysis

CSE 3302 Programming Languages Lecture 2: Syntax

Introduction to Compiler Construction

Welcome to CS 115 (Winter 2019)

Simply-Typed Lambda Calculus

Languages and Automata

Programming Languages

Operational Semantics. One-Slide Summary. Lecture Outline

CS1 Lecture 2 Jan. 16, 2019

Seminar in Programming Languages

What is a compiler? var a var b mov 3 a mov 4 r1 cmpi a r1 jge l_e mov 2 b jmp l_d l_e: mov 3 b l_d: ;done

CS 3304 Comparative Languages. Lecture 1: Introduction

Software Lesson 2 Outline

CS240: Programming in C

CSE450 Translation of Programming Languages. Lecture 4: Syntax Analysis

CS 415 Midterm Exam Spring SOLUTION

CSE P 501 Compilers. Parsing & Context-Free Grammars Hal Perkins Spring UW CSE P 501 Spring 2018 C-1

Implementation of Lexical Analysis

San Jose State University College of Science Department of Computer Science CS151, Object-Oriented Design, Sections 1,2 and 3, Spring 2017

CST-402(T): Language Processors

Programming Languages, Summary CSC419; Odelia Schwartz

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

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

Semantic Analysis. How to Ensure Type-Safety. What Are Types? Static vs. Dynamic Typing. Type Checking. Last time: CS412/CS413

Lexical Analysis. Finite Automata

CSC 261/461 Database Systems. Fall 2017 MW 12:30 pm 1:45 pm CSB 601

Working of the Compilers

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

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

CS 526 Advanced Topics in Compiler Construction. 1 of 12

CS 6371: Advanced Programming Languages

Welcome to CS 135 (Winter 2018)

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

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

CS 106B, Lecture 1 Introduction to C++

Transcription:

Programming Language Design and Implementation Wes Weimer TR 9:30-10:45 MEC 214 #1 Who Are We? Cunning Plan Wes, Pieter, Isabelle Administrivia What Is This Class About? Brief History Lesson Understanding a Program in Stages #2 Your Host For The Semester #3 1

Course Staff - TA Pieter Hooimeijer Email: ph4u Isabelle Stanton ils9d #4 #5 Course Home Page google: virginia cs 415 www.cs.virginia.edu/~cs415/ Lectures slides are available before class You should still take notes! Assignments are listed also grading breakdown, regrade policies, etc. Use the class forum for all public questions #6 2

Discussion Sections There will be two one-hour-long structured office hours each week Hosted by the TAs We will not take attendance, but you are encouraged to show up to one each week Notes posted on web For your benefit! Answer questions, go over lecture material, help and hints on the homework and projects Fill out the time signup sheet #7 #8 #9 3

Course Structure Course has theoretical and practical aspects Best of both worlds! Need both in programming languages! Reading = both Many external and optional readings Written assignments = theory Class hand-in, right before lecture, pass/fail Programming assignments = practice Electronic hand-in Strict deadlines #10 Academic Honesty Don t use work from uncited sources Including old code We use plagiarism detection software PLAGIARISM #11 The Course Project A big project: an Interpreter! in five easy parts Start early! #12 4

How are Languages Implemented? Two major strategies: Interpreters (take source code and run it) Compilers (translate source code, run result) Distinctions blurring (e.g., just-in-time compiler) Interpreters run programs as is Little or no preprocessing Compilers do extensive preprocessing Most implementations use compilers #13 Don t We Already Have Compilers? #14 Dismal View Of Prog Languages C++ Java (or C#) #15 5

(Short) History of High-Level Languages 1953 IBM develops the 701 Defense Calculator 1952, US formally ends occupation of Japan 1954, Brown v. Board of Education of Topeka, Kansas All programming done in assembly Problem: Software costs exceeded hardware costs! John Backus: Speedcoding An interpreter Ran 10-20 times slower than hand-written assembly #16 FORTRAN I 1954 IBM develops the 704 John Backus Idea: translate high-level code to assembly Many thought this impossible 1954-7 FORTRAN I project By 1958, >50% of all software is in FORTRAN Cut development time dramatically (2 weeks 2 hours) #17 The first compiler FORTRAN I Produced code almost as good as hand-written Huge impact on computer science Led to an enormous body of theoretical work Modern compilers preserve the outlines of FORTRAN I #18 6

Q: TV (100 / 842) In this 1985-1992 ABC television series, the gunless title character Angus works for Pete and the Phoenix Foundation and makes heavy use of his Swiss Army knife and duct tape. The Structure of an Interpreter 1. Lexical Analysis 2. Parsing 3. Semantic Analysis 4. Optimization (optional) 5. Run It! This is the class programming project! The first 3, at least, can be understood by analogy to how humans comprehend English. #20 Lexical Analysis First step: recognize words. Smallest unit above letters This is a sentence. Note the Capital T (start of sentence symbol) Blank (word separator) Period. (end of sentence symbol) #21 7

More Lexical Analysis Lexical analysis is not trivial. Consider: How d you break this up? Plus, programming languages are typically more cryptic than English: *p->f += -.12345e-6 #22 And More Lexical Analysis Lexical analyzer divides program text into words or tokens if x == y then z = 1; else z = 2; Broken up: if, x, ==, y, then, z, =, 1, ;, else, z, =, 2, ; #23 Parsing Once words are understood, the next step is to understand sentence structure Parsing = Diagramming Sentences The diagram is a tree #24 8

Diagramming a Sentence This line is a longer sentence article noun verb article adjective noun subject object sentence #25 Parsing Programs Parsing program expressions is the same Consider: if x == y then z = 1; else z = 2; Diagrammed: x == y z 1 z 2 relation predicate assign then-stmt if-then-else assign else-stmt #26 Semantic Analysis Once sentence structure is understood, we can try to understand meaning But meaning is too hard for compilers Compilers perform limited analysis to catch inconsistencies: reject bad programs early! Some do more analysis to improve the performance of the program #27 9

Semantic Analysis in English Example: Kara said Sharon left her sidearm at home. What does her refer to? Kara or Sharon? Even worse: Sharon said Sharon left her sidearm at home. How many Sharons are there? Which one left the sidearm? #28 Semantic Analysis in Programming Programming languages define strict rules to avoid such ambiguities This C++ code prints 4 ; the inner definition is used { int Sydney = 3; { int Sydney = 4; cout << Sydney; } } Scoping or aliasing problem. #29 More Semantic Analysis Compilers perform many semantic checks besides variable bindings Example: Gregory House left her cane at home. A type mismatch between her and Gregory House; we know they are different people Presumably Gregory House is male #30 10

Optimization No strong counterpart in English, but akin to editing Automatically modify programs so that they Run faster Use less memory In general, conserve some resource The project has no optimization component #31 Code Generation Produces assembly code (usually) which is then assembled into executables by an assembler A translation into another language Analogous to human translation We will not do codegen in this class Instead you will interpret the program directly! #32 Issues Compiling and interpreting are almost this simple, but there are many pitfalls. Example: How are erroneous programs handled? Language design has big impact on compiler Determines what is easy and hard to compile Course theme: trade-offs in language design #33 11

Languages Today The overall structure of almost every compiler & interpreter follows our outline The proportions have changed since FORTRAN Early: lexing, parsing most complex, expensive Today: optimization dominates all other phases, lexing and parsing are cheap #34 Trends in Languages Optimization for speed is less interesting. But: scientific programs advanced processors (Digital Signal Processors, advanced speculative architectures) Small devices where speed = longer battery life Ideas we ll discuss are used for improving code reliability: memory safety detecting concurrency errors (data races) type safety automatic memory management #35 Why Study Prog. Languages? Increase capacity of expression See what is possible Improve understanding of program behavior Know how things work under the hood Increase ability to learn new languages Learn to build a large and reliable system See many basic CS concepts at work #36 12

What Will You Do In This Class? Reading (textbook, outside sources) Learn about different kinds of languages Imperative vs. Functional vs. Object-Oriented Static typing vs. Dynamic typing etc. Learn to program in different languages Python, Ruby, ML, Cool (= micro-java) Write an interpreter! #37 What Is This? #38 The Rosetta Stone The first programming assignment involves writing the same simple (50-75 line) program in five languages Ruby, Python, OCaml, Cool and C PA0, due next Friday, requires you to write the program in just one language (you pick) PA1, due one week later, requires all five Long, long be my heart with such memories fill'd! Like the vase in which roses have once been distill'd: You may break, you may shatter the vase if you will, But the scent of the roses will hang round it still. - Thomas Moore (Irish poet, 1779-1852) #39 13

Homework Scott Book, parts of Chapter 10 (for Tuesday) Get started on PA0 (due in 8 days) Questions? #40 14