Docsity

Programming Language Design and Implementation: Course Syllabus, Lecture notes of Compiler Design

Partial preview of the text

Download Programming Language Design and Implementation: Course Syllabus and more Lecture notes Compiler Design in PDF only on Docsity!

1

Programming LanguageProgramming Language

Design and Implementation Design and Implementation

Wes Weimer TR 9:30-10: MEC 214

2

Cunning Plan

  • Who Are We?
    • Wes, Pieter, Isabelle
  • Administrivia
  • What Is This Class About?
  • Brief History Lesson
  • Understanding a Program in Stages

3

Your Host For The Semester

4

Course Staff - TA

  • Pieter Hooimeijer
  • Email: ph4uph4uph4uph4u
  • Isabelle Stanton
  • ils9dils9dils9dils9d

5

6

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

10

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

11

Academic Honesty

  • Don’t use work from uncited sources
    • Including old code
  • We use plagiarism detection software

PLAGIARISM

12

The Course Project

  • A big project: an Interpreter!
  • … in five easy parts
  • Start early!

13

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

14

Don’t We Already Have Compilers?

15

Dismal View Of Prog Languages

C++

Java (or C#)

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.

20

The Structure of an Interpreter

  1. Lexical Analysis
  2. Parsing
  3. Semantic Analysis
  4. Optimization (optional)
  5. Run It!

The first 3, at least, can be understood by analogy to how humans comprehend English.

This is the class programming project!

21

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)

22

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-

23

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 , ;

24

Parsing

  • Once words are understood, the next step is to understand sentence structure
  • Parsing = Diagramming Sentences
    • The diagram is a tree

28

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?

29

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.

30

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

31

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

32

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!

33

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

37

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!

38

What Is This?

39

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)

40

Homework

  • Scott Book, parts of Chapter 10 (for Tuesday)
  • Get started on PA0 (due in 8 days)

Questions?