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

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

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

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

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

ICOM 4036 Spring 2004

Programming Language Specification and Translation. ICOM 4036 Fall Lecture 3

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

CS131: Programming Languages and Compilers. Spring 2017

Compilers. Lecture 2 Overview. (original slides by Sam

Introduction. Compilers and Interpreters

Introduction to Compilers

Compilers and Interpreters

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

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

trends in programming languages

Lecture 1: Course Introduction

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

Formal Languages and Compilers Lecture I: Introduction to Compilers

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

Lecture 1: Course Introduction

Compilers Crash Course

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

CS426 Compiler Construction Fall 2006

CSE 504: Compiler Design

Lexical Analysis. Lecture 2-4

CS 415 Midterm Exam Spring 2002

ECE573 Introduction to Compilers & Translators

CSE450 Translation of Programming Languages. Lecture 4: Syntax Analysis

LECTURE NOTES ON COMPILER DESIGN P a g e 2

CSE4305: Compilers for Algorithmic Languages CSE5317: Design and Construction of Compilers

Introduction to Lexical Analysis

Compiler Design (40-414)

General Course Information. Catalogue Description. Objectives

Introduction to Compiler Construction

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

Earlier edition Dragon book has been revised. Course Outline Contact Room 124, tel , rvvliet(at)liacs(dot)nl

Introduction to Compiler Construction

CS453 Compiler Construction

Overview of the Class

Compiler Theory Introduction and Course Outline Sandro Spina Department of Computer Science

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

Overview of the Class

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

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

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

Compilers. Pierre Geurts

CSCI 565 Compiler Design and Implementation Spring 2014

Principles of Programming Languages. Lecture Outline

Chapter 10: Compiler I: Syntax Analysis

Anatomy of a Compiler. Overview of Semantic Analysis. The Compiler So Far. Why a Separate Semantic Analysis?

CSE4305: Compilers for Algorithmic Languages CSE5317: Design and Construction of Compilers

Lexical Analysis. Lecture 3-4

Compilers. Prerequisites

Principles of Compiler Construction ( )

ST. XAVIER S COLLEGE

Compilers for Modern Architectures Course Syllabus, Spring 2015

Application Specific Signal Processors S

Working of the Compilers

Introduction to Lexical Analysis

Welcome to CSE131b: Compiler Construction

Compiler I: Sytnax Analysis

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 415 Midterm Exam Spring SOLUTION

Lecture 16: Static Semantics Overview 1

Lecture 1: Introduction. 23. August, 2010

CST-402(T): Language Processors

The Compiler So Far. Lexical analysis Detects inputs with illegal tokens. Overview of Semantic Analysis

CS 3813/718 Fall Python Programming. Professor Liang Huang.

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

CSE4305: Compilers for Algorithmic Languages CSE5317: Design and Construction of Compilers

Compiling Regular Expressions COMP360

COP 3402 Systems Software. Lecture 4: Compilers. Interpreters

CSCI 3136 Principles of Programming Languages

Lexical Analysis. Chapter 2

Principles of Compiler Construction ( )

Compiling Techniques

Software Lesson 2 Outline

Modules, Structs, Hashes, and Operational Semantics

15-411/ Compiler Design

Syntax. A. Bellaachia Page: 1

CSE 582 Autumn 2002 Exam 11/26/02

COMP 3002: Compiler Construction. Pat Morin School of Computer Science

Implementation of Lexical Analysis

CA Compiler Construction

Compiler Design Overview. Compiler Design 1

INF5110 Compiler Construction

Lexical Scanning COMP360

Compiler Construction

CS 314 Principles of Programming Languages

Introduction to Compiler Construction

Theory and Compiling COMP360

Undergraduate Compilers in a Day

CMSC 350: COMPILER DESIGN

Overview of the Course

Transcription:

Administrivia Everything is on the class Web site http://www.stanford.edu/class/cs143/ Compilers CS143 11:00-12:15TT B03 Gates Syllabus is on-line, of course Assignment dates will not change Midterm Thursday, 10/21 in class Final Wednesday, 12/8 7-10pm Communication Use newsgroup, email, phone, office hours But definitely prefer the newsgroup! Prof. Aiken CS 143 Lecture 1 1 Prof. Aiken CS 143 Lecture 1 2 Staff Instructor Alex Aiken TAs Peter Boonstoppel Isil Dillig Tom Dillig Steven Elia Text The Purple Dragon Book Aho, Lam, Sethi & Ullman Not required But a useful reference Office hours, contact info on 143 web site Prof. Aiken CS 143 Lecture 1 3 Prof. Aiken CS 143 Lecture 1 4 Course Structure Course has theoretical and practical aspects Need both in programming languages! Written assignments = theory Class hand-in Programming assignments = practice Electronic hand-in Academic Honesty Don t use work from uncited sources Including old code We use plagiarism detection software many cases in past offerings PLAGIARISM Prof. Aiken CS 143 Lecture 1 5 Prof. Aiken CS 143 Lecture 1 6 1

The Course Project A big project in 4 easy parts Start early! How are Languages Implemented? Two major strategies: Interpreters (older) Compilers (newer) Interpreters run programs as is Little or no preprocessing Compilers do extensive preprocessing Prof. Aiken CS 143 Lecture 1 7 Prof. Aiken CS 143 Lecture 1 8 Language Implementations Batch compilation systems dominate gcc Some languages are primarily interpreted Java bytecode Some environments (Lisp) provide both Interpreter for development Compiler for production History of High-Level Languages 1954 IBM develops the 704 Successor to the 701 Problem Software costs exceeded hardware costs! All programming done in assembly Prof. Aiken CS 143 Lecture 1 9 Prof. Aiken CS 143 Lecture 1 10 The Solution Enter Speedcoding An interpreter Ran 10-20 times slower than hand-written assembly FORTRAN I Enter John Backus Idea Translate high-level code to assembly Many thought this impossible Had already failed in other projects Prof. Aiken CS 143 Lecture 1 11 Prof. Aiken CS 143 Lecture 1 12 2

FORTRAN I (Cont.) FORTRAN I 1954-7 FORTRAN I project 1958 >50% of all software is in FORTRAN Development time halved The first compiler Huge impact on computer science Led to an enormous body of theoretical work Modern compilers preserve the outlines of FORTRAN I Prof. Aiken CS 143 Lecture 1 13 Prof. Aiken CS 143 Lecture 1 14 The Structure of a Compiler 1. Lexical Analysis 2. Parsing 3. Semantic Analysis 4. Optimization 5. Code Generation Lexical Analysis First step: recognize words. Smallest unit above letters This is a sentence. The first 3, at least, can be understood by analogy to how humans comprehend English. Prof. Aiken CS 143 Lecture 1 15 Prof. Aiken CS 143 Lecture 1 16 More Lexical Analysis Lexical analysis is not trivial. Consider: ist his ase nte nce And More Lexical Analysis Lexical analyzer divides program text into words or tokens If x == y then z = 1; else z = 2; Units: Prof. Aiken CS 143 Lecture 1 17 Prof. Aiken CS 143 Lecture 1 18 3

Parsing Once words are understood, the next step is to understand sentence structure Parsing = Diagramming Sentences The diagram is a tree Diagramming a Sentence This line is a longer sentence article noun verb article adjective noun subject object sentence Prof. Aiken CS 143 Lecture 1 19 Prof. Aiken CS 143 Lecture 1 20 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 assign assign 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 predicate then-stmt else-stmt if-then-else Prof. Aiken CS 143 Lecture 1 21 Prof. Aiken CS 143 Lecture 1 22 Semantic Analysis in English Semantic Analysis in Programming Example: Jack said Jerry left his assignment at home. What does his refer to? Jack or Jerry? Even worse: Jack said Jack left his assignment at home? How many Jacks are there? Which one left the assignment? Programming languages define strict rules to avoid such ambiguities This C++ code prints 4 ; the inner definition is used { } int Jack = 3; { int Jack = 4; cout << Jack; } Prof. Aiken CS 143 Lecture 1 23 Prof. Aiken CS 143 Lecture 1 24 4

More Semantic Analysis Compilers perform many semantic checks besides variable bindings Example: Jack left her homework at home. A type mismatch between her and Jack; we know they are different people Presumably Jack is male Prof. Aiken CS 143 Lecture 1 25 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 Prof. Aiken CS 143 Lecture 1 26 Optimization Example Code Generation Produces assembly code (usually) X = Y * 0 is the same as X = 0 A translation into another language Analogous to human translation Prof. Aiken CS 143 Lecture 1 27 Prof. Aiken CS 143 Lecture 1 28 Intermediate Languages Many compilers perform translations between successive intermediate forms All but first and last are intermediate languages internal to the compiler Typically there is 1 IL IL s generally ordered in descending level of abstraction Highest is source Lowest is assembly Intermediate Languages (Cont.) IL s are useful because lower levels expose features hidden by higher levels registers memory layout etc. But lower levels obscure high-level meaning Prof. Aiken CS 143 Lecture 1 29 Prof. Aiken CS 143 Lecture 1 30 5

Issues Compiling is 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: many trade-offs in language design Compilers Today The overall structure of almost every compiler adheres to 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 Prof. Aiken CS 143 Lecture 1 31 Prof. Aiken CS 143 Lecture 1 32 Prof. Aiken CS 143 Lecture 1 33 6