
Stanford Compilers Course - tu7001
https://lagunita.stanford.edu/courses/Engineering/Compilers/Fall2014/about
======
nfriend
I took this course for fun a few years ago - it was fantastic! I modified the
project a bit to match my own interests - instead of compiling to an
executable, my compiler generated browser-friendly JavaScript code. I built a
small web application that uses my compiler and allows you to run COOL code in
your browser:
[http://nathanfriend.io/cooltojs/](http://nathanfriend.io/cooltojs/)

~~~
dbrgn
I also did the course, in parallel to the "real" university course. Both had
almost the same structure since they're both roughly based on the dragon book.

I can strongly recommend it - really great material!

------
virgilp
I hate it that you can't see the syllabus without signing in. How is someone
supposed to know whether (s)he's interested?

I've looked over it, it's not too dissimilar (on surface) with what I used to
teach at the university. Might not be an accident since I remember at some
point we switched from our own compiler skeleton to COOL, which is apparently
what Stanford uses; so maybe I inspired my syllabus from Stanford's? I forget
:) (for sure I did check the syllabi of several big US universities when
building mine).

Interesting that he recommends "Engineering a Compiler"; I don't doubt that
it's a good book but I don't know it. The third on my list (though admittedly
a bit advanced) was Muchnick's "Advanced Compiler Design and Implementation".

~~~
rayiner
Muchnik covers a lot of ground, so is pretty dense. Cooper & Torczon's book is
more approachable, though it covers less ground. In some cases, Cooper &
Torczon choose which algorithms to present because they're easier to
understand. (E.g., they don't cover partitioning-based value numbering, but
rather a simpler hash-based technique.)

------
tombert
As an autodidact, I really appreciate that the big "brand-name" universities
do this. MIT OpenCourseware and the free Stanford lectures have been so
incredibly valuable in making me an at-least-half-decent engineer.

I've written a Scheme interpreter a few years back, but never a compiler, so
this should be a pretty fun time-dump for the weekends.

~~~
pjmlp
Have a look at "An Incremental Approach to Compiler Construction", you might
find it interesting.

[http://scheme2006.cs.uchicago.edu/11-ghuloum.pdf](http://scheme2006.cs.uchicago.edu/11-ghuloum.pdf)

~~~
seanmcdirmid
Not to be confused with “an approach to incremental compiler construction.”

------
chmaynard
I believe this course was developed by Alex Aiken during his time at Berkeley.
I assume he brought the material with him when he moved over to Stanford. The
Cool language as a didactic tool seems a little dated now. When I took the
Coursera version of the course a few years ago, Aiken distributed the Cool
compiler development environment as a VirtualBox image, which was a nice
cross-platform solution at the time. Today, Docker would probably be the
preferred approach. I didn't get very far in the course because I lacked the
necessary C++ skills (and the motivation to learn them).

------
dolguldur
Syllabus:

Week Videos Quiz / Exam PA assigned PA due

1 Course Overview | Cool: The Course Project

2 Lexical Analysis | Finite Automata Quiz #1 PA1

3 Parsing | Top-Down Parsing Quiz #2

4 Bottom-Up Parsing I | Bottom-Up Parsing II Quiz #3 PA2 PA1

5 Semantic Analysis and Type Checking | Midterm

6 Cool Type Checking | Runtime Organization Quiz #4 PA3 PA2

7 Code Generation | Operational Semantics Quiz #5

8 Local Optimization | Global Optimization Quiz #6

9 Register Allocation | Garbage Collection PA4 PA3

10 Java | Final Exam

------
amelius
They still reference the Dragon book, but how relevant is it still? I recall
that a lot of it deals with parsing (which nowadays seems an almost trivial
problem), and it doesn't treat garbage collected runtime systems, or JIT
compilers. Or type inference with any of the newer typesystems as used by e.g.
Rust, or even Hindley Milner.

~~~
virgilp
This is an undergrad-level course. Of course it needs to teach parsing - a lot
of people are going to have to write some form of parser during their career,
so it's good to have some fundamentals. (and the Dragon book doesn't
exclusively talk about parsing, either)

~~~
megaman22
Man, it's really unconscionable the way that textbooks juice people. There is
no reason that book ought to cost $190 (what I just saw on Amazon for the
hard-cover). It's across the board; once a book gets entrenched as one of
these go-to textbooks for a subject, it can for some reason be marked up 400%
over equivalent books.

~~~
rayiner
> There is no reason that book ought to cost $190

Why? How many copies of these textbooks do you think they sell? There is about
50,000 "computer and information science" bachelors degrees awarded each year
(which is broader than what you'd think of as CS). Let's say, generously, 5%
take a compilers course. That's 2,500 books per year in the entire subject.
Let's say any one book gets about 1,000 of those sales. At $190 per book,
that's $190,000 gross. Over an entire edition, maybe you sell 2-3 times that
much (considering campus book rentals, people buying used books, etc.) That's
maybe $500,000 to write, edit, publish, and distribute an entire textbook.
That doesn't seem unreasonable to me at all.

~~~
rifung
5% is generous?

It's a requirement at some universities so I wouldn't be surprised if it's
higher. Then again, I don't know what % of universities requires it either.

~~~
rayiner
I think 5% is generous if you're looking not just at computer science degrees,
but "computer and information science" degrees (which is what the government
tracks).

------
hiram112
Could someone who has taken a decent compiler course and been in the industry
a few years comment on how / why this course would be beneficial?

There are a lot of things I'd like to look into these days, but only so much
time. And I do realize that some courses I took in University a decade ago
were far more valuable than others (e.g. learning to program the m68K was
extremely useful just to understand how stacks, interrupts, etc. work. OTOH, I
haven't used anything from in my programming languages course since then).

~~~
rifung
Recently, a coworker of mine told me how she thought the compiler should catch
when you don't give printf the right arguments. Another example is when a
coworker said you couldn't define flags in a Go library but she didn't
realized you would have to import the package from that library to force the
code to run first.

In my mind, both of these examples showed a lack of understanding in how the
compiler works. I would say learning about compilers should help with being
able to make good assumptions of how things work. Whether it's worth the rare
times it comes in handy is probably dependent on what else you could learn.

Note that I actually didn't take a compilers course myself and said co-workers
did, so I can't say for sure even taking a course is sufficient (but I am
currently reading a compilers book, though out of enjoyment and not for career
skills). I should also say I believe my co-workers are significantly better
developers/employees than I am.

~~~
glangdale
> Recently, a coworker of mine told me how she thought the compiler should
> catch when you don't give printf the right arguments.

The fact that you think she's wrong, and that you're right, on this issue,
suggests you don't understand how compilers work either. 99% of printf fails
are catchable through static analysis, and should be caught that way.

~~~
rifung
> The fact that you think she's wrong, and that you're right, on this issue,
> suggests you don't understand how compilers work either.

I'm happy to be proven wrong and certainly know I have much more to learn but
I suspect in this case I was not clear in my comment and consequently you made
assumptions about what I think is right or not. Feel free to correct me =]
Either way I appreciate the response

> 99% of printf fails are catchable through static analysis, and should be
> caught that way.

I never said that it wasn't possible! But that would require the compiler have
special logic just for printf or in this case the fmt and log packages. Maybe
you would think that's the right thing to do, and I can see that point of
view, but I suspect you would at least understand why it is a controversial
decision and thus not necessarily assume it's there.

~~~
cardiffspaceman
GCC does catch problems with printf arguments vs the format string and it has
mechanisms for defining functions that take the same format strings. I operate
at a high enough warning level that I see this type of warning now and then.

TL;DR: the compiler DOES have that special logic.

~~~
rifung
Ah interesting to know that GCC does this! I figured there would be compilers
which did this but I sadly didn't have any examples.

> the compiler DOES have that special logic.

Indeed it being a controversial decision does not imply that no compilers
would do it; if anything it implies that there should be some compilers which
make that choice.

------
gfredtech
A few days ago I had to download this course (along with Stanford's course on
Automata theory) from a torrent tracker because it was no longer available on
Coursera...

~~~
leadingthenet
Any idea why they're no longer on Coursera?

~~~
gfredtech
Sadly, no

------
jcadam
My compilers course was the single most difficult college course I've ever
taken (it was an undergrad/graduate cross-listed course usually taken senior
year, and at least at my school, UCCS in Colorado, was the cause of many a CS
student not graduating on time -- putting a weed-out course that close to the
end of the BSCS program wasn't cool, man).

More all-nighters during that class than any other. It occurs to me, I've
spoken to several Junior devs over the last few years with CS degrees that
never had to take a compilers course. That just isn't right.

~~~
kochthesecond
It was optional in my degree, and I concur it was the single most difficult
course I took. At least twice as much work as any other course, learned twice
as much too.

------
stevefan1999
Yes! This is what I’m exactly looking for! By the way, what other free
compiler courses would you hackers recommend?

~~~
tdaniels
I have worked through the following, and found it quite good
[http://www.diku.dk/~torbenm/Basics/basics_lulu2.pdf](http://www.diku.dk/~torbenm/Basics/basics_lulu2.pdf)

*Full disclosure that the following is mine [https://troydaniels.github.io/diku/compiler/course/2017/01/0...](https://troydaniels.github.io/diku/compiler/course/2017/01/03/building-a-compiler-p1.html)

------
bitL
For those of you who took it - does it go into detail how to do advanced LALR
languages, including handling semantics and types? Can I use the knowledge to
make my own OOP + FP language right away (Scala/Kotlin-like), or do I need to
study much much more than what is covered in this course? Thanks!

~~~
jfoutz
I didn't take this course. I have taken compiler classes.

Short answer, yes.

Longer answer, compilers of any sort are hard, because there's both a lot of
special cases and also pressure to be algorithmically efficient.

Writing any kind of compiler is going to force you to do stuff with the parse
tree. It's up to you to decide if

    
    
       float a = 1
    

is an error or not. doing things like constant value evaluation

    
    
       int a = 1 + 2 + 3
       =>
       int a = 6
    

will get you a feel for all the different ways you can transform the parse
tree. It's going to feel frustrating, because it's not the language you want
to work on. But building up the skills to shuffle ast nodes is really really
helpful.

Making your own language is hard. if your goal is a working language, i'd
suggest building an interpreter first, so you can really nail down the
semantics. at the end of that you're going to have a call that looks like
eval(ast, context). you can do a simple compiler by just reimplementing eval,
rather than doing the work, spit out the code that would do the work.

also, if you have an adequate interpreter, you can you can write your compiler
in your own language.

------
avarsh
I took a PL/Compilers course based on COOL with Wes Weimer at UVA. We built an
interpreter and compiler for COOL using its manual (i.e. a document with a
verbal/maths spec for the language) and virtually no skeleton code. It was the
hardest class in the department and I consider it to be the most valuable
class I took as an undergrad. Before that class I didn't really understand
what happened when I 'hit go' on my programs. Weimer is at UMich now but still
publishes course materials online:
[https://web.eecs.umich.edu/~weimerw/](https://web.eecs.umich.edu/~weimerw/)

------
dhawalhs
More Stanford free online courses/MOOCs(over 150) here: [https://www.class-
central.com/university/stanford](https://www.class-
central.com/university/stanford)

~~~
2_listerine_pls
Too bad Stanford doesn't care much about free material as MIT does.

~~~
sn9
Check out Stanford's Lagunita.

~~~
2_listerine_pls
They have very few courses.

~~~
sn9
They have the Compilers course, though.

------
zellyn
I did the Coursera version of this course a few years ago. I didn't read any
book, but definitely watched parts of the videos more than once.

Their scaffolding code is only available for C++ and Java, but (at least when
I took it) many of the tests could be downloaded and reverse-engineered, so I
was still able to adequately test my Go implementation. See
[https://github.com/zellyn/gocool](https://github.com/zellyn/gocool) for my
working but probably quite nasty code :-)

~~~
dochtman
I also took the Coursera version, and I have a Python version of the tooling
for those who are interested:

[https://github.com/djc/cs143-python](https://github.com/djc/cs143-python)

------
DSingularity
I have wonderful memories coding the lexer, parser, runtime, and code
generation support for OO aspects of COOL. Knowing how inheritance and
polymorphism were implemented really does bring some clarity to programming.

Compilers was one of my favorite courses. Definitely humbling and
enlightening. Would recommend :D

------
towndrunk
This is worth a look if you have not seen it.
[https://interpreterbook.com/](https://interpreterbook.com/)

