PLAGIARISM. Administrivia. Course home page: Introduction to Programming Languages and Compilers

Similar documents
Introduction to Programming Languages and Compilers. CS164 11:00-12:00 MWF 306 Soda

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

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

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)

Lecture 1: Course Introduction

Lecture 1: Course Introduction

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

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

ICOM 4036 Spring 2004

Programming Language Specification and Translation. ICOM 4036 Fall Lecture 3

Compilers. Lecture 2 Overview. (original slides by Sam

Introduction to Compilers

trends in programming languages

Introduction. Compilers and Interpreters

CS131: Programming Languages and Compilers. Spring 2017

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.

Principles of Programming Languages. Lecture Outline

Lexical Analysis. Lecture 2-4

Compilers and Interpreters

Programming Language Concepts 1982, 1987, Outline. Period

Low-Level Languages. Computer Programs and Programming Languages

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

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

Introduction. A. Bellaachia Page: 1

Programming Languages, Summary CSC419; Odelia Schwartz

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

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

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

Concepts of Programming Languages

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

Programmiersprachen (Programming Languages)

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

Lecture 16: Static Semantics Overview 1

CS2303 C14 Systems Programming Concepts. Bob Kinicki

CS 415 Midterm Exam Spring 2002

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

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

Lexical Analysis. Lecture 3-4

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

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

Compiler Construction D7011E

CS 3304 Comparative Languages. Lecture 1: Introduction

Concepts in Programming Languages

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

Introduction to Lexical Analysis

Introduction to Programming

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

Introduction to Lexical 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

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

CSCI 3136 Principles of Programming Languages

Seminar in Programming Languages

What is a programming language?

Chapter 1. Preliminaries

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

LECTURE 18. Control Flow

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

Continuations provide a novel way to suspend and reexecute

Compilers. Prerequisites

Formal Languages and Compilers Lecture I: Introduction to Compilers

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

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

Com S 541. Programming Languages I

LECTURE 1. Overview and History

Chapter 1. Preliminaries

Chapter 2 Preview. Preview. History of Programming Languages. History of Programming Languages. History of Programming Languages

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

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

A Tour of Language Implementation

COMP 201: Principles of Programming

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

Informatica 3 Syntax and Semantics

Syntax Errors; Static Semantics

COP 3402 Systems Software. Lecture 4: Compilers. Interpreters

Why study Programming Language Concepts? Chapter One. Language Evaluation Criteria. Programming Domains. Readability Writability Reliability Cost

Semantic Analysis. Lecture 9. February 7, 2018

Grade Weights. Language Design and Overview of COOL. CS143 Lecture 2. Programming Language Economics 101. Lecture Outline

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

COSC 2P90 Programming Languages & Object-Orientation

CS101 Introduction to Programming Languages and Compilers

CST-402(T): Language Processors

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

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

Syntax. A. Bellaachia Page: 1

COMPILER DESIGN LECTURE NOTES

What is a compiler? Xiaokang Qiu Purdue University. August 21, 2017 ECE 573

CS 113: Introduction to

2. Evolution of the Major Programming languages

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

Chapter 2. 5 * B => A V 6 7 (subscripts) S 1.n 1.n (data types)

Lexical Analysis. Chapter 2

Simply-Typed Lambda Calculus

Design & Implementation Overview

CS321 Languages and Compiler Design I. Winter 2012 Lecture 1

Transcription:

Administrivia Introduction to Programming Languages and Compilers CS164 11:00-12:00 MWF 306 Soda Notes by G. Necula, with additions by P. Hilfinger Course home page: http://www-inst.eecs.berkeley.edu/~cs164 Concurrent enrollment: see me after class Pick up class accounts at the end of lecture today. Pick a partner Must move Tu 11:00 section. Prof. Hilfinger CS 164 Lecture 1 1 Prof. Hilfinger CS 164 Lecture 1 2 Course Structure Course has theoretical and practical aspects: analysis and translation of programming languages uses both. Regular homework = theory, should be individual work. Programming assignments = practice, in teams All submissions will be electronic Academic Honesty Don t use work from uncited sources Including old code We use plagiarism detection software 6 cases in last few semesters PLAGIARISM Prof. Hilfinger CS 164 Lecture 1 3 Prof. Hilfinger CS 164 Lecture 1 4 The Course Project Course has hidden agenda: programming design and experience. Substantial project in parts. Provides example of how complicated problem might be approached. Validation (testing) is part of the project. Also a chance to introduce important tool: version control, which we ll use to monitor your progress General rule: start early! How are Languages Implemented? Two major strategies: Interpreters (older, less studied) Compilers (newer, more extensively studied) Interpreters run programs as is Little or no preprocessing Compilers do extensive preprocessing Most implementations use compilers New trend is hybrid: Just-In-Time compilation, interpretation+compilation Prof. Hilfinger CS 164 Lecture 1 5 Prof. Hilfinger CS 164 Lecture 1 6 1

(Short) History of High-Level Languages FORTRAN I Initially, programs hard-wired or entered electromechanically: Analytical Engine, Jacquard Loom, ENIAC, punched-card-handling machines Programs encoded as numbers (machine language) stored as data: Manchester Mark I, EDSAC. 1953 IBM develops the 701 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 Prof. Hilfinger CS 164 Lecture 1 7 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 wks to 2 hrs) Prof. Hilfinger CS 164 Lecture 1 8 FORTRAN I The first compiler 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 After FORTRAN Lisp, late 1950s: dynamic, symbolic data structures. Algol 60: Europe s answer to FORTRAN: modern syntax, block structure, explicit declaration. Set standard for language description. Dijkstra: A marked improvement on its successors. COBOL: late 1950 s. Business-oriented. Records. Prof. Hilfinger CS 164 Lecture 1 9 Prof. Hilfinger CS 164 Lecture 1 10 The 60s 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 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. Late 1970 s: DoD starts to develop Ada to consolidate >500 languages. Prof. Hilfinger CS 164 Lecture 1 11 Prof. Hilfinger CS 164 Lecture 1 12 2

And on into the present Complexity increases with C++. Then decreases with Java. Then increases again (C#). Proliferation of little or specialized languages and scripting languages: HTML, PHP, Perl, Python, Ruby, Prof. Hilfinger CS 164 Lecture 1 13 Problems to address How to describe language clearly for programmers, precisely for implementors? How to implement description, and know you re right? Automatic conversion of description to implementation Testing How to save implementation effort? Multiple languages to multiple targets: can we re-use effort? How to make languages usable? Handle errors reasonably Detect questionable constructs Compile quickly Prof. Hilfinger CS 164 Lecture 1 14 The Structure of a Compiler 1. Lexical Analysis 2. Parsing 3. Semantic Analysis 4. Optimization 5. Code Generation The first 3, at least, can be understood by analogy to how humans comprehend English. Lexical Analysis First step: recognize letters and words. Words are smallest unit above letters This is a sentence. Note the Capital T (start of sentence symbol) Blank (word separator) Period. (end of sentence symbol) Prof. Hilfinger CS 164 Lecture 1 15 Prof. Hilfinger CS 164 Lecture 1 16 More Lexical Analysis Lexical analysis is not trivial. Consider: ist his ase nte nce Plus, programming languages are typically more cryptic than English: *p->f+=-.12345e-5 And More Lexical Analysis Lexical analyzer divides program text into words or tokens if x == y then z = 1; else z = 2; Tokens: if, x, ==, y, then, z, =, 1, ;, else, z, =, 2, ; Prof. Hilfinger CS 164 Lecture 1 17 Prof. Hilfinger CS 164 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. Hilfinger CS 164 Lecture 1 19 Prof. Hilfinger CS 164 Lecture 1 20 Parsing Programs Semantic Analysis 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 Prof. Hilfinger CS 164 Lecture 1 21 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 Some do more analysis to improve the performance of the program Prof. Hilfinger CS 164 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. Hilfinger CS 164 Lecture 1 23 Prof. Hilfinger CS 164 Lecture 1 24 4

More Semantic Analysis Compilers perform many semantic checks besides variable bindings Optimization No strong counterpart in English, but akin to editing 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. Hilfinger CS 164 Lecture 1 25 Automatically modify programs so that they Run faster Use less memory In general, conserve some resource Not an emphasis in the project. Prof. Hilfinger CS 164 Lecture 1 26 Optimization Example (in C) Optimization is tricky for (int i = 0; i < N; i += 1) { for (int j = 0; j < N; j += 1) { A[i][j] += B[i]*C[j] for (i = 0; i < N; i += 1) { double tmp1 = B[i]; double* tmp2 = &A[i]; for (int j = 0; j < N; j +=1) tmp2[j] += tmp1*c[j]; for (i = 0; i < N; i += 1) A[i] *= D/A[0]; is NOT tmp1 = D/A[0]; for (i = 0; i < N; i += 1) A[i] *= tmp1; Prof. Hilfinger CS 164 Lecture 1 27 Prof. Hilfinger CS 164 Lecture 1 28 Code Generation Having understood the program, translate it into something useful (executable) Classical compilers produce machine code or assembly. Target: bare hardware. Java implementations, many scripting languages produce virtual machine code ( bytecode ). Target: interpreter or JIT (Just In Time) compiler. 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 Prof. Hilfinger CS 164 Lecture 1 29 Prof. Hilfinger CS 164 Lecture 1 30 5

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. Hilfinger CS 164 Lecture 1 31 Trends in Compilation 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 from compilation used for improving code reliability: memory safety detecting concurrency errors (data races)... Prof. Hilfinger CS 164 Lecture 1 32 Trends, contd. Parallelism and parallel architectures (esp., multicore: see Berkeley ParLab) Dynamic features: dynamic types, dynamic loading. Compilers More needed and more complex Driven by increasing gap between new languages new architectures Venerable and healthy area Why Study Languages and Compilers? Increase capacity of expression Improve understanding of program behavior Increase ability to learn new languages Learn to build a large and reliable system See many basic CS concepts at work Prof. Hilfinger CS 164 Lecture 1 33 Prof. Hilfinger CS 164 Lecture 1 34 6