Programming Assignment 4 Out
August 7, 2012

The final programming assignment (IR generation) is out and is due on Saturday, August 18 at 11:30 AM (note the time change). Once you've completed this assignment, you'll have a full working compiler for Decaf. Isn't that cool?

As a logistical note, be aware that there will be no late submissions allowed for this assignment. The due date for pp4 is the latest possible time that we can have assignments due, so please try to get it in on time.

Good luck!

Windows Starter Code for pp3
July 20, 2012

Windows starter code for pp3 is now available. If you have done pp1 and pp2 on Windows, you should be all set to go. Otherwise, you will need to follow the setup instructions for those assignments before proceeding to ensure that the appropriate tools are installed on your system.

Programming Assignment 3 Out
July 20, 2012

The third programming assignment (semantic analysis) goes out today. This assignment is broken into two portions - a checkpoint assignment due on Monday, July 30 at 11:59PM (hard deadline), and the main assignment, which is due on Monday, August 6 at 11:59PM. In this assignment, you will perform the final set of checks necessary to confirm that the input program is indeed well-formed, setting the stage for IR generation in the next assignment.

This assignment is substantially larger than the previous assignments, so be sure to start early.

Good luck!

Midterm Logistics
July 18, 2012

The CS143 midterm exam is next Wednesday, July 25, from 11:00AM - 1:00PM. We'll meet in the normal room (Thornton 102). The exam covers the material up to and including Earley parsing, with an emphasis on scanning, LL, and LR parsing. The exam is open-book, open-note, open-computer, but closed-network, meaning that you can have the slides and other notes available during the exam. You just can't go Googling the answers.

There is a practice exam available, which is the exam that was given last summer quarter. The structure and content of this exam is similar to that of the upcoming exam.

If you are taking this class remotely, you will receive an electronic copy of the exam at around 11:00AM on July 25 and can start taking the exam any time between 11:00AM on July 25 and 11:00AM on July 26. You should return the exam to us no later than 1:00PM on July 26, and we'll include submission instructions along with the exam itself.

There will be a review session on Monday, so please feel free to show up with questions!

Visual Studio Starter Files for PP2
July 11, 2012

Windows starter files for the second programming project are now available. To use them, you will need to follow these instructions:

  1. Download the Windows version of bison. When prompted for an installation directory, do not use the default directory. Instead, install bison to C:\GnuWin32, not in "Program Files." This is due to a bug in the bison implementation that causes it not to work correctly if it's placed in a directory whose name contains a space.
  2. Download the Windows version of sed and m4. When prompted for an installation directory, do not use the default directory. Instead, install bison to C:\GnuWin32, not in "Program Files."
  3. Download the Windows pp2 starter project. The project should be all set up to go, so if you're encountering any problems please let us know so we can try to fix them.

If you do your development work in Windows, you will still need to submit using the existing submissions framework.

Hope this helps!

Written Assignment 2 Out
July 11, 2012

The second written assignment is out and comes due next Wednesday, July 18 at 5:00PM. This will give you a chance to explore the strengths, weaknesses, and nuances of the parsing algorithms we've developed over the past few weeks.

Good luck!

Programming Assignment 2 Out
July 9, 2012

Programming Assignment 2 (Syntax Analysis) goes out today. It's due on Friday, July 20 at 11:59PM. In this assignment, you will build up the parser for Decaf, and will learn how to use the bison tool in the process. Additionally, you will get experience introducing new features into the language as you add switch statements and a few other extensions to Decaf.

We will be releasing a Windows version of this assignment later today once we've confirmed that our starter project files work correctly.

Good luck!

Logging in Remotely
July 4, 2011

Several of you have asked how to log in to the Stanford machines remotely. To do so, you will need an SSH client. On Linux or Mac computers, you can do this from the command-line with ssh. On Windows, you will need to download a SSH client such as PuTTY or SecureCRT (available with your SUNetID here). From there, you will want to connect to either or You will probably get a warning about a RSA key not matching, which is perfectly fine; these above hostnames will forward you to a free machine on the cluster. From there, you should be good to go!

If you're having trouble logging in, or if you have any other questions, as always feel free to contact us.

Hope this helps!

Phone Numbers
July 3, 2012

Phone Numbers During Office Hours:
Keith: (650) 723-4350
Jinchao: (650) 736-1817

Discussion Forum
June 29, 2012

Please use Piazza to ask and discuss questions.

Office Hours
June 29, 2012

We have scheduled our office hours as following:

  • Keith Schwarz
    • Monday 2-4pm Gates 178
    • Tuesday 2-4pm Gates 178
  • Jinchao Ye
    • Wednesday 6-8pm Gates B26
    • Thursday 6-8pm Gates B26

Written Assignment 1 Out
June 29, 2012

The first written assignment is out and comes due next Friday, July 6 at 5:00PM. This problem set explores the theoretical aspects of scanning, and will ask you to play around with the different algorithms we explored in lecture.

Good luck!

Visual Studio Starter Files for PP1
June 27, 2012

As an experiment this quarter, we've put together Windows starter files for the first programming assignment. To use these starter files, follow these steps:

  1. Download the Windows version of flex. When prompted for an installation directory, please use the default; the project file I've cooked up will assume that the binary is in this folder.
  2. Download the Windows pp1 starter project. The project should be all set up to go, so if you're encountering any problems please let me know and I can try to fix them. I built this project using Visual C++ 2008, which is available free for download.

If you do your development work in Windows, you will still need to submit using the existing submissions framework. I'll get directions on how to do this posted later.

Hope this helps!

Programming Assignment 1 Out
June 27, 2012

Programming Assignment 1 (lexical analysis) goes out today. It's due on Monday, July 9 at 11:59PM. This assignment asks you to build the very first piece of the Decaf compiler. In doing so, you'll learn about the flex tool, and will master regular expressions. You have plenty of time to complete this assignment, but I would strongly suggest starting early.

Good luck!

Welcome to CS143!
June 25, 2012

Welcome to CS143, Stanford's course in the practical and theoretical aspects of compiler construction. We have an exciting quarter ahead of us loaded with that wonderful combination of concepts and coding that makes compilers so cool. Class meets Monday/Wednesday/Friday in Thornton 102 from 11:00AM - 12:15PM, and I hope that you're able to join.

In the meantime, feel free to check out the course information handout to learn more about what this class is all about, the prerequisites, and the course policies. If you have any questions in the meantime, feel free to email me at


00: Course Information
01: Syllabus
02: Course Overview
03: Decaf Specification
04: Lexical Analysis
05: flex in a Nutshell
06: Programming Assignment 1
07: Written Assignment 1
07S: Written Assignment 1 Solutions
08: Formal Grammars
09: Top-Down Parsing
10: Bottom-Up Parsing
11: LR and SLR Parsing
12: Introducing bison
13: Programming Assignment 2
14: LALR Parsing
15: Miscellaneous Parsing
16: Syntax-Directed Translation
17: Written Assignment 2
17S: Written Assignment 2 Solutions
18: Semantic Analysis
19: Programming Assignment 3
20: Practice CS143 Midterm
20S: Practice CS143 Midterm Solutions
21: CS143 Midterm
21S: CS143 Midterm Solutions
22: Runtime Environments
23: Intermediate Representations
24: Three-Address Code Examples
25: Programming Assignment 4


Programming Assignment 1
Written Assignment 1 (solutions)
Programming Assignment 2
Written Assignment 2 (solutions)
Programming Assignment 3
Programming Assignment 4


Submission Instructions

Regular Expressions
Flex Online Manual
Bison Online Manual
SPIM Simulator Documentation
CS1U: Practical Unix Videos
Unix Reference Documentation
xemacs Command Reference
vi Command Reference
gdb Command Reference C++ Reference
CS106L Course Reader (C++ Reference)
Fall 2010 CS143 Page


00: Intro to Compilers
01: Lexical Analysis
02: Syntax Analysis
03: Top-Down Parsing, Part I
04A: Top-Down Parsing, Part II
04B: Bottom-Up Parsing, Part I
05: Bottom-Up Parsing, Part II
06: Bottom-Up Parsing, Part III
07: Advanced Parsing
08: Semantic Analysis
09: Type-Checking, Part I
10: Type-Checking, Part II
11: Runtime Environments, Part I
12: Runtime Environments, Part II
13: TAC
14: Local Optimization
15: Global Optimization, Part I
16: Global Optimization, Part II
17: Register Allocation
18: Garbage Collection
19: Code Optimization