trends in programming languages

Similar documents
CS164: Final Exam. Fall 2003

Hack Your Language! CS164: Introduction to Programming Languages and Compilers

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

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

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

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

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

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

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

Compilers. Lecture 2 Overview. (original slides by Sam

Lecture 1: Course Introduction

Lecture 1: Course Introduction

Programming Language Specification and Translation. ICOM 4036 Fall Lecture 3

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

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

Introduction to Compilers

ICOM 4036 Spring 2004

CS164: Programming Assignment 5 Decaf Semantic Analysis and Code Generation

CS164: Midterm I. Fall 2003

Compilers and Interpreters

CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer

CS101 Introduction to Programming Languages and Compilers

CS131: Programming Languages and Compilers. Spring 2017

CS453 Compiler Construction

Course introduction. Advanced Compiler Construction Michel Schinz

CSE450 Translation of Programming Languages. Lecture 4: Syntax Analysis

CS 406/534 Compiler Construction Putting It All Together

Semantic Analysis. Lecture 9. February 7, 2018

Program Abstractions, Language Paradigms. CS152. Chris Pollett. Aug. 27, 2008.

15-411/ Compiler Design

Lexical Analysis. Lecture 2-4

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

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

An Introduction to Software Engineering. David Greenstein Monta Vista High School

COP 3402 Systems Software. Lecture 4: Compilers. Interpreters

Important Project Dates

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

Project #1 rev 2 Computer Science 2334 Fall 2013 This project is individual work. Each student must complete this assignment independently.

Introduction to Lexical Analysis

CS 415 Midterm Exam Spring 2002

Project Compiler. CS031 TA Help Session November 28, 2011

A Tour of Language Implementation

An Overview to Compiler Design. 2008/2/14 \course\cpeg421-08s\topic-1a.ppt 1

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

Syntax Errors; Static Semantics

Formal Languages and Compilers Lecture I: Introduction to Compilers

Welcome to CS120 Fall 2012

Name & Recitation Section:

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

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

CMSC 350: COMPILER DESIGN

Lexical Analysis. Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast!

CSE 504: Compiler Design

CS152 Programming Language Paradigms Prof. Tom Austin, Fall Syntax & Semantics, and Language Design Criteria

Lexical Analysis. Lecture 3-4

Compilers. Computer Science 431

The Environment Model. Nate Foster Spring 2018

Programming Project 4: COOL Code Generation

CS354 gdb Tutorial Written by Chris Feilbach

Principles of Programming Languages. Lecture Outline

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

CS 536. Class Meets. Introduction to Programming Languages and Compilers. Instructor. Key Dates. Teaching Assistant. Charles N. Fischer.

CS4120/4121/5120/5121 Spring /6 Programming Assignment 4

General Course Information. Catalogue Description. Objectives

The Environment Model

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

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

First Midterm Exam CS164, Fall 2007 Oct 2, 2007

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

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

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square)

Lecture 16: Static Semantics Overview 1

Introduction. Compilers and Interpreters

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILERS

Undergraduate Compilers in a Day

Is it ever useful to be confident that a problem is hard?

Welcome to CSE131b: Compiler Construction

CS 3110 Lecture 1 Course Overview

Software Lesson 2 Outline

CMPT 379 Compilers. Anoop Sarkar.

LESSON 13: LANGUAGE TRANSLATION

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

EECS483 D1: Project 1 Overview

Project 1 Computer Science 2334 Spring 2016 This project is individual work. Each student must complete this assignment independently.

Administrativia. Extra credit for bugs in project assignments. Building a Scanner. CS164, Fall Recall: The Structure of a Compiler

CS 432 Fall Mike Lam, Professor. Compilers. Advanced Systems Elective

Basic Concepts. Computer Science. Programming history Algorithms Pseudo code. Computer - Science Andrew Case 2

Principles of Compiler Construction ( )

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.

CS131 Compilers: Programming Assignment 2 Due Tuesday, April 4, 2017 at 11:59pm

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

CSE 3302 Programming Languages Lecture 2: Syntax

Syntactic Analysis. The Big Picture Again. Grammar. ICS312 Machine-Level and Systems Programming

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

Type Inference. Prof. Clarkson Fall Today s music: Cool, Calm, and Collected by The Rolling Stones

Transcription:

Announcement Introduction to Programming Languages and Compilers CS164 3:30-5:00 TT 10 Evans all tomorrow s discussion sections will be held in 330 Soda (Windows PC lab) discussion section agenda: Eclipse tutorial how to install the PA1 starter kit using CVS remote testing 1 2 Overview trends in programming languages and why they matter to you the structure of the compiler the project course logistics why you want to take this course trends in programming languages 3 Trends in programming languages ENIAC (1946, University of Philadelphia) programming language and its compiler: programmer s key tools languages undergo constant change from C to C++ to Java in just 12 years be prepared to program in new ones design simple languages yourselves an example in this lecture to see the trend let s examine the history ENIAC program for external ballistic equations: (how different is ENIAC in spirit from gaming video cards?) 5 6 1

Programming ENIAC ENIAC (1946, University of Philadelphia) programming done by rewiring the interconnections to set up desired formulas, etc Problem: slow, error-prone, this is how program was loaded Lesson: store the program in memory! (the von Neuman paradigm) 7 8 UDSAC (1947, Cambridge University) the first real computer large-scale, fully functional, stored-program electronic digital computer (by Maurice Wilkes) problem: Wilkes realized: a good part of the remainder of my life was going to be spent in finding errors in... programs solution: so he invented procedures (1951) reusable software was born procedure: the first (implemented) language construct Assembly the language (UNIVAC 1, 1950) Idea translate mnemonic code (assembly) by hand write programs with mnemonic codes (add, sub), with symbolic labels, then assign addresses by hand Example: clear-and-add a add b store c translate it to something like B100 A200 C300 9 10 Assembler the compiler (Manchester, 1952) Assembly programming caught on, but it was assembler nearly as we know it, called AutoCode a loop example, in MIPS, a modern-day assembly code: loop: addi $t3, $t0, -8 addi $t4, $t0, -4 lw $t1, thearray($t3) lw $t2, thearray($t4) add $t5, $t1, $t2 sw $t5, thearray($t0) addi $t0, $t0, 4 blt $t0, 160, loop jr $ra # Gets the last # two elements # Adds them together... #...and stores the result # Moves to next "element # of thearray # If not past the end of # thearray, repeat Problem: Software costs exceeded hardware costs! John Backus: Speedcoding An interpreter for a high-level language Ran 10-20 times slower than hand-written assembly way too slow 11 12 2

FORTRAN I (1954-57) The first compiler Produced code almost as good as hand-written Huge impact on computer science (laid foundations for cs164) Modern compilers preserve its outlines FORTRAN (the language) still in use today By 1958, >50% of all software is in FORTRAN Cut development time dramatically 2 wks 2 hrs that s more than 100-fold FORTRAN I (IBM, John Backus, 1954) Example: nested loops in FORTRAN a big improvement over assembler, but annoying artifacts of assembly remain: labels and rather explicit jumps (CONTINUE) lexical columns: the statement must start in column 7 The MIPS loop in FORTRAN: DO 10 I = 2, 40 A[I] = A[I-1] + A[I-2] 10 CONTINUE 13 14 Designing a good language is hard Object-oriented programming (1970s) A good language protects against bugs, but lessons take a while. An example that cause a failure of a NASA planetary probe: buggy line: DO 15 I = 1.100 what was intended (a dot had replaced the comma): DO 15 I = 1,100 because Fortran ignores spaces, compiler read this as: DO15I = 1.100 which is an assignment into a variable DO15I, not a loop. This mistake is harder (if at all possible) to make with the modern lexical rules (white space not ignored) and loop syntax for (i=1; i < 100; i++) { inheritance faked using procedural programming: draw(2delement p) { switch (p.type) { SQUARE: // draw a square break; CIRCLE: // draw a circle break; Problem: unrelated code (drawing of SQUARE and CIRCLE) mixed in the same procedure; hard to reuse code common to both 15 16 Object-oriented programming Review of historic development In Java, the same code has the desired separation: class Circle extends 2DElement { void draw() { <draw circle> // similar for Square the dispatch is now much simpler: p.draw() wired interconnects von Neuman machines & machine code procedures assembly (compile by hand) assembler FORTRAN I cleaner loops object-oriented programming in C virtual calls Do you see a trend? 17 18 3

Where will languages go from here? and why the trends matter to you As you just saw, the trend is towards higherlevel abstractions express the algorithm concisely! which means hiding often repeated code fragments new language constructs hide more of these lowlevel details. Or at least try to detect more bugs when the program is compiled stricter type checking we ll leave this for later 20 A simple GUI-building language You ll be able to design a simple language yourself to simplify a repetitive programming task next example is from Fall 03 final exam problem: writing GUI clients is pain; simplify it! A window contains nested windows first row of the top-level window; contains three elements: a text, a dialog box, and a button. Two windows nested in their parent window. Each nested window contains two elements; the left window has two rows, the right window has one. 21 22 Current programming model Design yourself a better programming model Window top = new Window(null); top.settitle(``find''); Text t = new Text(top); t.setposition(0,0); t.setlabel("find what:"); Dialog d = new Dialog(top); d.setposition(20,0); d.setwidth(18*someconstant); Button f = new Button(top); settype(regular_button); f.setposition(80,0); f.setlabel("find Next"); Window w1 = new Window(top); w1.setposition(0,50); Selection s1 = new Selection(w1); s1.setposition(0,0); s1.setlabel("match whole word only"); Selection s2 = new Selection(w1); s2.setposition(0,50); s2.setlabel("match case"); s2.setselected(true); Window w2 = new Window(top); w2.setposition(45,50); w2.settitle("direction"); w2.setframed(true); Button r1 = new Button(w2); r1.settype(radio); r1.setposition(0,0); r1.setlabel("up"); Button r2 = new Button(w2); r2.settype(radio); r2.setposition(50,0); r2.setlabel("down"); r2.setselected(true); Button c = new Button(top); c.settype(regular_button); c.setposition(80,50); c.setlabel("cancel"); top.draw(); (See Fall 03 final exam for comments and details) window "Find" { "Find what:" <------------------> ["Find next"], window "" { x "Match whole word only", X "Match case" window framed "Direction" { o "Up" O "Down" ["Cancel"] 23 24 4

Three execution environments the structure of a compiler Interpreters Scheme, lisp, perl, python popular interpreted languages later got compilers Compilers C Java (compiled to bytecode) Virtual machines Java bytecode runs on an interpreter interpreter often aided by a JIT compiler 26 The Structure of a Compiler 1. Scanning (Lexical Analysis) 2. Parsing (Syntactic Analysis) 3. Type checking (Semantic Analysis) 4. Optimization 5. Code Generation The first 3, at least, can be understood by analogy to how humans comprehend English. Lexical Analysis Lexical analyzer divides program text into words or tokens if x == y then z = 1; else z = 2; Units: if, x, ==, y, then, z, =, 1, ;, else, z, =, 2, ; 27 28 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 29 30 5

Parsing Programs Semantic Analysis in English 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 31 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? 32 Semantic Analysis I Semantic Analysis II Programming languages define strict rules to avoid such ambiguities This Java code prints 4 ; the inner definition is used { int Jack = 3; { int Jack = 4; System.out. print(jack); Compilers also perform checks to find bugs Example: Jack left her homework at home. A type mismatch between her and Jack we know they are different people (presumably Jack is male) 33 34 Code Generation A translation into another language Analogous to human translation Compilers for Java, C, C++ produce assembly code (typically) Code generators produce C or Java the project 35 6

The project A compiler for Decaf (a small Java) PA1: interpreter of a subset of Decaf, a warm-up PA2-5: the compiler of Decaf, in four easy pieces PA2: scanner (plus scanner generator) PA3: parser (plus parser generator) PA4: code generator for non-oo features PA5: code generator for OO features The Decaf compiler PA2: lexer PA3: parser Decaf program PA4: PA5: non-oo OO checker+ checker+ code gen code gen stream of tokens Abstract Syntax Tree (AST) x86 assembly 37 run it on Windows PC (Linux?) 38 PA1: SkimDecaf Interpreter How you will implement the scanner, parser SkimDecaf pgm. Eclipse Java parser SkimDecaf pgm. PA2: lexer PA3: parser PA2 PA3 lexer parser Java lexer code Java parser code lexer generator lexer generator lexer description parser description AST PA1: interpreter run! PA4: PA5: non-oo OO checker+ checker+ code gen code gen automatically generated you write this 39 40 Academic (Dis)honesty Read the policy at: http://www.eecs.berkeley.edu/policies/acad.dis.shtml course logistics (see course info on the web for more) We ll be using a state-of-the art plagiarism detector. Before you ask: yes, it works very well. You are allowed to discuss the assignment but you must acknowledge (and describe) help in your submission. 42 7

Grading This is going to be a fun course, but graded on a on a curve, as customary so, yes, you re competing against one another. grades will follow department guidelines course average GPA will be around 2.9 (before extra credit for the optimization contest) more at http://www.eecs.berkeley.edu/policies/ugrad.grading.shtml this has proven to be fair and just A lot of grade comes from a project form a strong team use the course newsgroup to find a partner Remote testing A new testing infrastructure to help you debug your compiler being introduced this semester (may have a few rough edges, so bear with us) The rationale: give you (indirect) access to our reference solution you will be able to compile and run your Decaf programs on our compiler and check if your compiler behaves like our compiler does 43 44 Remote testing The process: you write test programs to test your compiler store them with your compiler in a CVS repository our scripts will pick them up and run your tests on your compiler and also our compiler mismatch in outputs indicates a bug (guess in whose code) our scripts will also measure test coverage what fraction of our compiler did your tests execute low coverage indicates you didn t write enough tests, and hence a bug in your code may be undetected you pick up results of remote testing via CVS and display them using a special Eclipse plugin (on cs164 web site) conclusion 45 Why are you taking cs164? To learn how languages are executed compiler is programmer s most frequently used tool be prepared for new languages To go through a cool project where major parts are automatically generated with your own generators! To develop your own small languages and a compiler (or code generator) for it become a more productive programmer Take cs164. Become unoffshorable. We design them here, but the labor is cheaper in Hell. 47 48 8