Lecture 01
Lecture 01
CS143
Tuesday/Thursday 9:45–11:15
2
Staff
• Instructor
– Fredrik Kjolstad
• TAs
– Scott Kovach
– Wonyeol Lee
– Nikhil Raghuraman
– Toby Bell
– Timothy Gu
3
Administrivia
• Syllabus is on-line
– cs143.stanford.edu
– Assignment dates will not change
– Midterm (Thursday April 28)
– Final
• Office hours
– 22 office hours spread throughout the week
– Some zoom office hours where SCPD students get preference
– My office hours this week: Thursday 4-5pm (zoom) and Friday 10-11am
(Gates 486)
– Office hours starting next week to be announced
• Communication
– Use discussion forum, email, zoom, office hours
4
Webpages and servers
• Canvas at canvas.stanford.edu
– Lecture recordings available under the Panopto Course Videos tab
• Ed Discussion at https://edstem.org/us/courses/21322/discussion/
– This is where you should ask most questions
– Also accessible from Canvas
• Gradescope at gradescope.com
– This is where you will hand in written assignments
• Not required
– But a useful reference
6
Course Structure
7
Course Goal
8
Academic Honesty
PLAGIARISM
9
The Course Project
• … in 4 parts
• Start early!
Program
Program Compiler Binary Code
Interpreter
Machine Machine
Machine
11
Language Implementations
12
History of High-Level Languages
• Problem
– Software costs exceeded
hardware costs!
13
The Solution
• Enter “Speedcoding”
• An interpreter
14
FORTRAN I
• Idea
– Translate high-level code to
assembly
15
FORTRAN I (Cont.)
• 1954-7
– FORTRAN I project
• 1958
– >50% of all software is in
FORTRAN
• Performance close to
hand-written assembly!
16
FORTRAN I
17
The Structure of a Compiler
18
Lexical Analysis
This is a sentence.
19
More Lexical Analysis
20
And More Lexical Analysis
• Units:
21
Parsing
22
Diagramming a Sentence
subject object
sentence
23
Parsing Programs
Semantic Analysis
25
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?
26
Semantic Analysis in Programming
• Programming {
languages define strict int Jack = 3;
rules to avoid such {
ambiguities
int Jack = 4;
cout << Jack;
• This C++ code prints
“4”; the inner definition }
is used }
27
• Example:
Jack left her homework at home.
28
Optimization
• Akin to editing
– Minimize reading time
– Minimize items the reader must keep in short-term
memory
X = Y * 0 is the same as X = 0
30
Code Generation
31
Intermediate Representations
– Highest is source …
– Lowest is assembly IR
Assembly
32
Intermediate Representations (Cont.)
33
Issues
34
Compilers Today
35