Docsity

Lecture 1: Compilers and Programming Languages - Overview and History, Assignments of Computer Science

Toggle sidebar
bg1
1
Prof. Su ECS 142 Lecture 1 1
Compilers
ECS 142
9:00-10:20 TuTh
7 Wellman
Prof. Su ECS 142 Lecture 1 2
Administrivia
• Everything is on the class Web site
http://www.cs.ucdavis.edu/~su/teaching/ecs142
• Syllabus is on-line, of course
– Assignment dates unlikely to change
–Midterm
• Thursday, 11/2
•in class
–Final
• Saturday, 12/15
• 8:00-10:00 AM
•Communication
– Use newsgroup, email, phone, office hours
– But definitely prefer the newsgroup!
Prof. Su ECS 142 Lecture 1 3
Staff
• Instructor
– Zhendong Su
•TA
– Jeff Wu
• Office hours, contact info will be on 142 web
site
Prof. Su ECS 142 Lecture 1 4
Text
• The Red Dragon Book
• Aho, Sethi, Ullman
• Not requir ed
–But a useful reference
Prof. Su ECS 142 Lecture 1 5
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
Prof. Su ECS 142 Lecture 1 6
Academic Honesty
• Don’t use work from uncited sources
– Including old code
• We use plagiarism detection software
PLAGIARISM
pf3
pf4
pf5

Partial preview of the text

Download Lecture 1: Compilers and Programming Languages - Overview and History and more Assignments Computer Science in PDF only on Docsity!

Prof. Su ECS 142 Lecture 1 1

Compilers

ECS 142

9:00-10:20 TuTh 7 Wellman

Prof. Su ECS 142 Lecture 1 2

Administrivia

  • Everything is on the class Web site http://www.cs.ucdavis.edu/~su/teaching/ecs
  • Syllabus is on-line, of course
    • Assignment dates unlikely to change
    • Midterm
      • Thursday, 11/
      • in class
    • Final
      • Saturday, 12/
      • 8:00-10:00 AM
  • Communication
    • Use newsgroup, email, phone, office hours
    • But definitely prefer the newsgroup!

Prof. Su ECS 142 Lecture 1 3

Staff

  • Instructor
    • Zhendong Su

• TA

  • Jeff Wu
  • Office hours, contact info will be on 142 web site

Prof. Su ECS 142 Lecture 1 4

Text

  • The Red Dragon Book
  • Aho, Sethi, Ullman
  • Not required
    • But a useful reference

Prof. Su ECS 142 Lecture 1 5

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

Prof. Su ECS 142 Lecture 1 6

Academic Honesty

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

PLAGIARISM

Prof. Su ECS 142 Lecture 1 7

The Course Project

  • A big project
  • … in 4 easy parts
  • Start early!

Prof. Su ECS 142 Lecture 1 8

How are Languages Implemented?

  • Two major strategies:
    • Interpreters (older, less studied)
    • Compilers (newer, much more studied)
  • Interpreters run programs “as is”
    • Little or no preprocessing
  • Compilers do extensive preprocessing

Prof. Su ECS 142 Lecture 1 9

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

Prof. Su ECS 142 Lecture 1 10

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. Su ECS 142 Lecture 1 11

The Solution

  • Enter “Speedcoding” (IBM, about 1953)
  • An interpreter
    • Pseudocode interpreter for mathematics
    • For IBM 701 and 650
  • Ran 10-20 times slower than hand-written assembly

Prof. Su ECS 142 Lecture 1 12

FORTRAN I

  • Enter John Backus
  • Idea
    • Translate high-level code to assembly
    • Many thought this impossible
    • Had already failed in other projects

Prof. Su ECS 142 Lecture 1 19

Parsing

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

Prof. Su ECS 142 Lecture 1 20

Diagramming a Sentence

This line is a longer sentence

article noun verb article adjective noun

subject object

sentence

Prof. Su ECS 142 Lecture 1 21

Parsing Programs

  • Parsing program expressions is the same
  • Consider:

If x == y then z = 1; else z = 2;

  • Diagrammed:

if-then-else

x == y z 1 z 2

relation assign assign

predicate then-stmt else-stmt

Prof. Su ECS 142 Lecture 1 22

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

Prof. Su ECS 142 Lecture 1 23

Semantic Analysis in English

  • 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?

Prof. Su ECS 142 Lecture 1 24

Semantic Analysis in Programming

  • 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. Su ECS 142 Lecture 1 25

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. Su ECS 142 Lecture 1 26

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. Su ECS 142 Lecture 1 27

Optimization Example

X = Y * 0 is the same as X = 0

NOT!

Valid for integers, but not for floating point numbers

Prof. Su ECS 142 Lecture 1 28

Code Generation

  • Produces assembly code (usually)
  • A translation into another language
    • Analogous to human translation

Prof. Su ECS 142 Lecture 1 29

Intermediate Languages

  • Many compilers perform translations between successive intermediate forms - All but first and last areintermediate languages internal to the compiler - Typically there is one IL
  • IL’s generally ordered in descending level of abstraction - Highest is source - Lowest is assembly

Prof. Su ECS 142 Lecture 1 30

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