Start on May 19, 2025
Due on May 26, 2025
Find a group to work with for the homework assignments and the final course project. The group size is 3 people or less. We will be checking that all group members are contributing equally to the homework submission and the final project.
Along with your group members, register yourself as part of a group on Coursys.
Create a memorable name for your group. If you need help, seek help. Make sure there is no whitespace in your group name or anything that might cause a mojibake (please use plain ascii). Please use an underscore to join together words instead of hyphens.
Important: Do not use any obscene words in your group name. Be mature about your choice of group name. That does not mean it cannot be funny, just be aware that your choice of group name may offend someone else so be considerate of others.
Go to the Course Discussion Page and select [Activity Digest]
.
Change the Digest Email Frequency:
to a setting that send you email notifications, like so:
In this course, your programs will be managed and archived using Git. The basic idea is as follows:
Decide in your group the person that will create the repository on SFU Github Enterprise and invite the other group members as a Developer with write/admin permissions. The main maintainer in the group should follow the instructions in this section.
Go to SFU Github Enterprise and log in with your SFU username and password, the same one you use to check your e-mail on the SFU Outlook mail server. You should enable 2FA if you have not done so already and also go through the 2FA authentication.
Once logged in, you will see a list of your existing repos if you
have created any in the past. Create a new Private repository for
this class by clicking the New Repository
button (if this is your
first repository on SFU Github) or the New
button to create a new
repository for the homework assignments for this course.
On the Create a new repository
page, select a Repository name
.
You must name your repo: CMPT379-1254-g-GROUP
where
GROUP
is the group you registered on Coursys (see above).
For example, a repository name might be CMPT379-1254-g-ethicsgradient
.
Make sure you add the g-
before your group
name. It is important to name the repo exactly as you see here.
Write an optional Description
.
Important: You must choose this repository to be
Private
. We will not accept any repository for the homeworks in this course that is marked asPublic
. Your repo must be visible only to yourself and your group members. You must not give access to your repo to any other students except your group members, the TA(s) and the instructor..
Plagiarism is a serious academic offense.
At any point in the future you are also not allowed to either mark this repository as Public or copy the code to a different public repository (on Github or elsewhere).
The other initialization choices are optional (there is more about
setting up your .gitignore
file below).
Then click on the Create repository
button.
Your repo has now been created. You will be taken to the web page for your newly created repo.
This is the most important step in the setup of your GitHub repository
The course instructor and the TAs need access to your repo in order to test
and grade your code. Add the instructor and TAs as a member of your
repo by clicking on the Settings menu and choosing Add People
which looks like this:
On the page that loads up type in (or individually copy/paste) each of the
following list of names: anoop
,mam47
,sba236
,yha274@sfu.ca
,and invite them as a Collaborator.
You should be automatically set up to “Watch” changes to your repository, but ensure that you are watching changes.
Set up your notifications by going to your personal settings accessed through your user icon on the upper right corner:
Then select Notifications
(with the bell icon) and make
sure you are notified about changes to the repository:
Make sure you are notified about Github Issues.
Next we will set up the Secure Shell (ssh) keys so you can access your repo without a password. If you do not already have an SSH key then first generate a new ssh key.
If you have set up your SSH key correctly then you will have a public key. View it
cat ~/.ssh/id_*.pub
Then add your public SSH key to the GitHub server using these instructions. .
Download a copy of your repo to your CSIL machine. The action of making a local copy of your online repo is known as a “clone”.
In the terminal window, enter the commands
git config --global user.name USER
git config --global user.email USER@sfu.ca
git config --global core.editor nano # or set it to your favourite editor
git config --global push.default current
cd $HOME
git clone git@github.sfu.ca:GROUPUSER/CMPT379-1254-g-GROUP.git
where USER
is your SFU username, GROUPUSER
is the SFU username of
the person who created the group repository and GROUP
is the name of the
group you have already setup on Coursys. If
you skipped any of the above steps in setting up your GitHub repo
this command will not work. The system might prompt you for a
username/password combo. Supply the usual answers. To avoid entering
your username/password over and over again you can set up passwordless
ssh.
Your repo will be cloned into a new directory (also known as a folder)
called CMPT379-1254-g-GROUP
.
After cloning your repository, make sure you are inside your repository and at the top level. Create a directory for Homework 0:
mkdir hw0
cd hw0
pwd
When you print your working directory it should look like this:
CMPT379-1254-g-GROUP/hw0
Add a file README.md
to this directory using your favourite editor
and then git add README.md
and git commit -m "Initial hw0 commit"
and then git push
to send your new directory and file to the
GitHub server. Open up GitHub on a web browser to check that you
can see hw0/README.md
in your repository on the web browser.
Add a .gitignore
file at the top level of your git repository
to avoid committing and pushing useless files to the GitHub
server. Here is a typical .gitignore
file for C++ projects.
# Compiled Object files
*.slo
*.lo
*.o
*.obj
# Compiled Dynamic libraries
*.so
*.dylib
*.dll
# Compiled Static libraries
*.lai
*.la
*.a
*.lib
You must have git and python (3.x) on your system to run the assignments. Once you’ve confirmed this, run this command:
git clone https://github.com/anoopsarkar/compilers-class-hw.git
In the rmprefix
directory you will find various python programs
which you will use to test your solution to this homework and to
prepare files you will upload to Coursys.
You will get updates to the homework files by going to the directory where you cloned the repository and then doing:
# go to the directory where you did a git clone
git pull origin master
Before you start a new homework make sure you do a git pull
to get the latest homework files.
To get started with your homework do the following steps.
Clone your git repository and enter that directory and copy over the files:
git clone git@github.sfu.ca:GROUPUSER/CMPT379-1254-g-GROUP.git
cd CMPT379-1254-g-GROUP
mkdir -p rmprefix
cd rmprefix
cp -r /your-path-to/compilers-class-hw/rmprefix/* .
git add *
git commit -m 'initial commit'
git push
If you update my repository using git pull
then you might have to copy over the
new files into your repository. Be careful you do not clobber your own files
in the answer
directory.
Your solution must be compiled in the answer
directory and must be called rmprefix
.
There is an incomplete solution to this homework in answer/default.cc
. Copy
it over as your initial solution:
cd CMPT379-1254-g-GROUP/rmprefix/answer
cp default.cc rmprefix.cc
make rmprefix
The objective of this homework is to lay out the development and testing methodology for the rest of the homeworks so it is designed to be a trivial task that can be tested.
Your task for this homework is to write a very simple C++ program
that trims the leading whitespace (if any) from each line read from
the standard input stream std:cin
. Any other whitespace should
be left untouched. For this homework we define whitespace to be
only the ASCII space ' '
and tab '\t'
characters.
For example, for the following input:
line1
line2
line3
The output on standard output std::cout
should be:
line1
line2
line3
Make sure only leading whitespace is removed. Any other whitespace should be preserved in the output.
Write a C++ program called rmprefix.cc
that does the task that
is described above and add it to your git repository in the answer
directory.
If your program succeeds you should exit from your program using
exit(EXIT_SUCCESS)
. In this homework this should not happen but
if your program exits with an error you should exit using
exit(EXIT_FAILURE)
. The definitions of EXIT_SUCCESS
and
EXIT_FAILURE
are in cstdlib
(for C++) and in stdlib.h
(for
C).
Remember to push your solution source code to your git repository:
cd CMPT379-1254-g-GROUP/rmprefix/answer
git add rmprefix.cc
git commit -m 'initial solution'
git push
Then each time you finish a component of your solution you can push it to the remote repository:
git add answer/rmprefix.cc # or other files you worked on
git commit -m 'commit message'
git push
You have been given three helper programs to help you develop your solution to this homework.
Run your solution program on the testcases using the Python program zipout.py
.
Your solution must be compiled in the answer
directory and must be called rmprefix
.
Run against all testcases as follows:
# go to the directory with the file zipout.py
python3 zipout.py
This creates a directory called output
and a file output.zip
which can be checked against the reference output files
(see section on Check your solution below).
If you run zipout.py
multiple times it will overwrite your output directory and zip file which should be fine most of the time (but be careful).
For this homework the program zipout.py
uses the binary answer/rmprefix
by default. To discover the
command line options for this program, run:
python3 zipout.py -h
The option to log verbose debugging information to a log file will be very useful in future homeworks to debug your own code.
Check your solution accuracy using the Python program check.py
. You must create an output.zip
file using the above step in Run your solution on testcases.
Note that the references are only available for the dev
testcases. When you are graded you will be evaluated on both the dev
and test
testcases.
output.zip
contains your output for both sets of testcases.
python3 check.py
Correct(dev): 4 / 6
Score(dev): 4.00
Total Score: 4.00
You must upload your output zipfile and source code to Coursys. You should prepare your source for upload using the Python program zipsrc.py
.
# go to the directory with the file zipsrc.py
python3 zipsrc.py
This will create a zip file called source.zip
. You should upload this file as your submission to hw0
on Coursys.
Be careful: zipsrc.py
will only package files in the answer
directory. Make sure you have put all your supporting files in that directory. In particular, put relevant documentation into answer/README.md
.
If you add any testcases of your own please put them in the directories answer/testcases/[your-username]/
and answer/references/[your-username]/
using the same convention used by zipout.py
and check.py
.
answer
directory as a zip file source.zip
produced by running python3 zipsrc.py
must be uploaded to the hw0
submission page on Coursys.output.zip
produced by running python3 zipout.py
must be uploaded to the hw0
submission page on Coursys. When we run check.py
on the public testcases it should have a value higher than the output from the default.cc
program to get any marks.source.zip
must be in your git repository. Please commit and push often in order to get feedback on your code.answer/README.md
file.If you have any questions or you’re confused about anything, just ask.