Professional Documents
Culture Documents
Staff Text
• Course has theoretical and practical aspects • Don’t use work from uncited sources
– Including old code
• Need both in programming languages! • We use plagiarism detection software
– many cases in past offerings
• Written assignments = theory
– Class hand-in
PLAGIARISM
• Programming assignments = practice
– Electronic hand-in
1
The Course Project How are Languages Implemented?
• Idea
• An interpreter
– Translate high-level code
to assembly
• Ran 10-20 times slower than hand-written
– Many thought this
assembly impossible
2
FORTRAN I (Cont.) FORTRAN I
• 1958
– >50% of all software is in • Led to an enormous body of theoretical work
FORTRAN
• Lexical analysis is not trivial. Consider: • Lexical analyzer divides program text into
ist his ase nte nce “words” or “tokens”
If x == y then z = 1; else z = 2;
• Units:
3
Parsing Diagramming a Sentence
• Once words are understood, the next step is This line is a longer sentence
to understand sentence structure
subject object
sentence
• Example: • Programming {
Jack said Jerry left his assignment at home. languages define int Jack = 3;
What does “his” refer to? Jack or Jerry? strict rules to avoid
{
such ambiguities
int Jack = 4;
• Even worse: cout << Jack;
• This C++ code prints
Jack said Jack left his assignment at home? “4”; the inner }
How many Jacks are there? definition is used }
Which one left the assignment?
4
More Semantic Analysis Optimization
• Compilers perform many semantic checks • No strong counterpart in English, but akin to
besides variable bindings editing
• Many compilers perform translations between • IL’s are useful because lower levels expose
successive intermediate forms features hidden by higher levels
– All but first and last are intermediate languages – registers
internal to the compiler
– memory layout
– Typically there is 1 IL
– etc.
5
Issues Compilers Today
• Compiling is almost this simple, but there are • The overall structure of almost every compiler
many pitfalls. adheres to our outline
• Example: How are erroneous programs • The proportions have changed since FORTRAN
handled? – Early: lexing, parsing most complex, expensive
• Language design has big impact on compiler – Today: optimization dominates all other phases,
lexing and parsing are cheap
– Determines what is easy and hard to compile
– Course theme: many trade-offs in language design
Prof. Aiken CS 143 Lecture 1 31 Prof. Aiken CS 143 Lecture 1 32