Files

The goal of this part is to get the files, familiarize yourself with them, and run the application and the tests.

1 Clone the repo

Use the GitHub classroom link to accept the assignment and get access to the starter code.

You can do this assignment in pairs, if you choose! Regardless of whether you work with someone else, you will need to use the group workflow. If you are working in a pair, only one person on the team should accept the assignment.

2 Empty repo?!

When you clone the repo, you will notice that there is almost nothing in it!

We are going to create our compiler (almost) from scratch. The only starter code will come from a template, which has the architecture for our compiler, but no implementation of any of the phases, nor any of the usual files (e.g., for a lexer, a parser, etc.).

To use the template, open a terminal in the directory that contains your newly cloned repo. Type the following command:

stack new hmc hmc-cs132/compiler --bare --resolver=lts-22.44

This command asks stack to create a new project named hmc, using the template hmc-cs132/compiler. With this template, stack will install an empty compiler implementation in the current directory (thanks to the --bare argument). The --resolver argument configures the project to use the version of GHC that we have been using so far this semester.

3 Check that everything works

  1. Open the directory in VS Code, and open one of the Haskell files.

If VSCode asks to install Haskell or other parts of the toolchain, decline. Instead, open stack.yaml and add the following lines to the bottom of the file:

system-ghc: true
install-ghc: false
skip-ghc-check: true

These lines will configure the project to use the Haskell toolchain you have already installed.

  1. Build the code and run the (unimplemented) tests, just to make sure that everything is working before we begin.

4 Add and commit all the files

If everything works, add and commit all the files. The stack new command added a lot of new files to the project!

5 Run the main program

The main program uses a bare-bones implementation of the phases that just returns the program input. Try it out by running the following command

stack run -- "hello"

Compilation succeeded: hello

6 Browse the files

Look through the files in the app, src, and test directories. They should look familiar to you from the previous assignment. Notice that there are no files for the lexer, parser, tokens, AST, etc.