Home

Awesome

COOL Compiler

Programming Assignments of CS143 Compilers - C++ version

This repository contains all my solutions to the MOOC Compilers on Coursera:

https://www.coursera.org/course/compilers

You can also find it on Stanford Online:

http://online.stanford.edu/course/compilers-0

How to set up the assignments

The following steps are copied from the "Installing Directly on Linux" page on the course website.

Steps:

For each assignment, you need to set up the starter code according to the assignment specification.

Listed below are (only) the files I modified in each assignment.

Assignment 1

score: 63 / 63

/PA2/cool.flex

Assignment 2

score: 70 / 70

/PA3/cool.y

Important note on assignment 2

According to the assignment spec, you will need to make one slight change to the starter code before it will link.

Please comment out line 29 of the file parser-phase.cc (which you should not otherwise modify), so that it looks like:

//int curr_lineno;               // needed for lexical analyzer

Assignment 3

score: 74 / 74

/PA4/semant.cc

/PA4/semant.h

/PA4/cool-tree.h

Assignment 4

score: 63 / 63

/PA5/cgen.cc

/PA5/cgen.h

/PA5/cool-tree.h

/PA5/cool-tree.handcode.h

Important note on assignment 4

I used some C++11 features in this assignment. In order compile the code, you will have to set up a flag for g++. Go to /PA5/Makefile, and find the line starting with CFLAGS=... (which should be line 29).

Add -std=c++11 at the end of that line. Now that line should be something like:

CFLAGS=-g -Wall -Wno-unused -Wno-write-strings -Wno-deprecated ${CPPINCLUDE} -DDEBUG -std=c++11