Compiler Crafting

From Compiler Crafting
Jump to: navigation, search

This is the webpage for the experiment part of the course Principles and Techniques of Compilers at Spring 2012. Students who take this course should check this page periodically for content updates and new announcements.


Latest News

  • (2012-6-05) Slides for today's lecture are available here.
  • (2012-5-28) Programming Assignment 3 has due. Besides, on next Tuesday (Jun. 5) I will give a full 2-hour lecture. It may be my final lecture in this semester.
  • (2012-5-20) Programming Assignment 4 is out. Remember that the deadline for PA3 is May 27. You may want to hand in your PA3 first before starting to deal with PA4.
  • (2012-5-08) Slides for today's lecture are available here.
  • (2012-5-05) Handouts for programming assignment 3 are (partly) available. I have returned to Nanjing so let's get back to work: next Tuesday (May. 8) there will be a short lecture about scope and type system.
  • (2012-4-29) Programming Assignment 3 is out. We are pipe-lining these assignments a little bit because there is really not too much time left. Note that I will be away from Nanjing for a while so both the lecture for PA2 and a complete wiki update of PA3 will be deferred.
  • (2012-4-28) Programming assignment 2 will due tomorrow. Please be sure to get your source codes uploaded soon.
  • (2012-4-12) Handouts for programming assignment 2 are available. You will notice that this time the handouts are significantly shorter than the last ones. Besides, the second assignment will due Apr. 29.
  • (2012-4-10) Slides for today's lecture are available here. Note that we have updated the automaton used for comment processing, and the original one presented in class was wrong.
  • (2012-4-06) On next Tuesday (Apr. 10)'s class I will give a short lecture.
  • (2012-4-05) Programming Assignment 2 is out. I apologize for those typos in the previous assignment, and as before you may want to contact me when you find something that needs to be corrected.
  • (2012-4-01) Programming Assignment 1 due today. Anyone who failed to submit their codes before today will be given a penalty on their score.
  • (2012-3-22) We've corrected several typos in C-- Grammar and Programming Assignment 1. There could be more of them, so please contact me immediately if you find something.
  • (2012-3-09) Handouts for programming assignment 1 are out.
  • (2012-2-28) Slides for today's lecture are available here
  • (2012-2-25) On next Tuesday (Feb. 28)'s class there will be a short lecture by me.
  • (2012-2-24) Programming Assignment 1 is out. Try to finish the lexer part on your own, and don't worry if you fail to do so. Further readings and handouts will be available soon.
  • (2012-2-23) New handout Compiler Q&A is ready. This page shares some interesting and fundamental insights about compilers, and it will also be updated in the future.
  • (2012-2-20) New handout Getting started is ready.
  • (2012-2-18) The course wiki is established.

Course Info

  • Teaching assistant: Jia Chen
  • Lectures: TBD
    • The "Latest News" part will be updated once I am going to give a short lecture.


Motivation and goal

In this part of the course, you will be assigned the task of building a simple compiler from start to finish—beginning with a generated lexical analyzer and parser and ending with a MIPS code generator.

The construction of an optimizing compiler requires both the insights from your theoretical study and a prudent design that can deal with all the implementation details. You will get a more thorough understanding of many practical concerns related to compiler from an engineering perspective after finishing the whole set of experiments.

Modern compilers make effective use of wide variety of both classic and contemporary algorithms and techniques that are far beyond the scope of this course. Rather than letting everyone become an expert in compiler construction, our ultimate goal is to offer you an opportunity of training the essential skills for a qualified CS practitioner: namely, the skills of designing, coding and problem solving. Hope you have fun taking this course!


  • Since most of the programming assignment in this course will be written in C under a Linux environment, students should at least be familiar with C programming and Linux before taking this class.
  • Expertise in Architecture and Operating System are slightly touched, but NOT required. However, it would be very helpful if you have finished the OS experiment on your own.


  • The programming assignments constitute up to 30% of your overall grading of the course.
  • There are altogether 4 programming tasks, each of which is scored separately based on a hundred-mark system. Scores will be given mainly according to the correctness of your program.
  • Extra scores can be earned through finishing the optional requirements in the first 3 tasks.

Standard testing environment

  • Your codes will be compiled and tested in the following environment:
    • Linux Release: Ubuntu 10.10, kernel 2.6.35-22
    • GCC: version 4.4.5
    • GNU Flex: version 2.5.35
    • GNU Bison: version 2.4.1
    • QtSPIM: version 9.1.4
  • If you are using a more recent version of these software, normally it would not be a problem. Older version may have potential compatibility issues.



Academic Integrity

  • The significance of academic integrity can never be over-emphasized. Everyone shall, and shall be able to, complete the programming assignments individually. Acts that exceed the bounds defined by the approved collaboration practices will be considered cheating and such behaviors are strictly forbidden. Such acts include:
    • Copying solutions, code, or programs from someone else or giving someone else your solutions, code, or programs
    • Participation in a discussion group that develops a solution that everyone copies
We urge everyone in the class to take appropriate measures for protecting one's work. You should protect your files, codes, etc. as deemed reasonable.
  • Once plagiarism is confirmed, we could cancel the grades of BOTH the plagiarist(s) AND the author of the original copy.

Programming Assignment

  1. Programming Assignment 1 | PDF | test cases (Due Date: 2012-4-01)
  2. Programming Assignment 2 | PDF | test cases (Due Date: 2012-4-29)
  3. Programming Assignment 3 | PDF | test cases (Due Date: 2012-5-27)
  4. Programming Assignment 4 | PDF (Due Date: 2012-6-17)


  1. Getting started | PDF
  2. Lexical analysis | PDF
  3. Parsing | PDF
  4. Semantic analysis | PDF
  5. Intermediate Code Generation | PDF
  6. Target Code Generation | PDF
  7. Miscellaneous Topics

Lecture Slides


Personal tools