This repo contains my work and notes as I progress through Stanford's CS 143 - Compilers
- Cool Programming Language Reference Manual
- Cool Programming Language Support Code
- Lexical Analysis with Flex Manual
- Bison Manual
- Cool Programming Language Runtime
- SPIM Manual
I set up the environment on Linux using the steps below.
Install packages (If you only intend to use the C++ version, you don't need the jdk):
sudo apt-get install flex-old bison build-essential csh openjdk-17-jdk libxaw7-dev wget
Make the /usr/class directory:
sudo mkdir -p /usr/class/cs143/cool
Make the directory owned by you:
sudo chown $USER /usr/class/cs143/cool
Go to /usr/class and download the tarball:
cd /usr/class/cs143/cool
wget "https://courses.edx.org/asset-v1:StanfordOnline+SOE.YCSCS1+1T2020+type@[email protected]" -O student-dist.tar.gz
Untar:
tar -xf student-dist.tar.gz
Add a symlink to your home directory:
ln -s /usr/class/cs143/cool ~/cool
Add the bin directory to your .profile:
vi ~/.profile
Add the following line inside:
export PATH=/usr/class/cs143/cool/bin:$PATH
Source the file for changes to take effect:
source ~/.profile
Confirm that coolc
is available now:
which coolc
Compile one of the example programs to test everything works:
cd /usr/class/cs143/cool/examples/
coolc cool.cl
Test running the compiled file with spim
:
spim /usr/class/cs143/cool/examples/cool.s
If you get the following error:
line82: /usr/class/cs143/cool/bin/../bin/.i686/spim: No such file or directory
To fix this, we need to add the i386 architecture to run 32-bit executable files:
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install gcc-multilib
- Course Overview
- Cool: The Course Project
- Lexical Analysis
- Implementation of Lexical Analysis
- Introduction to Parsing
- Syntax-Directed Translation
- Top-Down Parsing
- Bottom-Up Parsing
- Semantic Analysis & Type Checking I
- Type Checking II
- Run-time Environments
- Code Generation
- Operational Semantics
- Intermediate Code & Local Optimization
- Global Optimization
- Register Allocation
- Automatic Memory Management
- Fast Runtime Compilation