Practice exercises

Dragon Book practice for lectures 1–7 organises suggested exercises by topic, with a starting set and further practice.

Development environment

Across the six assignments you need a JDK, flex, bison, a C and C++ compiler, and spim (assignment 6 only). Assignment 1 may be written in either C or C++; the packages below give you both. You can install these natively or use the container in the course repository, which has all of them. The container is the least trouble on Windows, and on Apple Silicon where spim is awkward to install.

Container

From your clone of the course repository:

# Linux: build with your own user id, so files you create in the container
# are owned by you and not by root
$ docker build --build-arg UID=$(id -u) --build-arg GID=$(id -g) -t cs3300 .

# macOS and Windows
$ docker build -t cs3300 .

Then start it with your work directory mounted at /workspace:

$ docker run -it --rm -v /absolute/path/to/your/work:/workspace cs3300

Native install

# Ubuntu / WSL
$ sudo apt install build-essential flex bison libfl-dev spim openjdk-21-jdk

# macOS (Homebrew)
$ brew install flex bison spim openjdk

On Windows, use WSL and then the Ubuntu line.

Two platform differences to know about. On macOS the flex library is -ll rather than -lfl when you link assignment 1. And the bison shipped with macOS is version 2.3, which is old; brew install bison gives you a current one, but it is not first on your PATH by default.

Java Programming Language

  • Online tutorial: https://www.w3schools.com/java/
  • Books
    • Kathy Sierra, Bert Bates, Trisha Gee, “Head First Java: A Brain-Friendly Guide”, Third Edition.
    • Herbert Schildt, “Java A Beginner’s Guide”, Eighth Edition.

Flex & Bison

JavaCC

Java Compiler Compiler (JavaCC) is the most popular parser generator for use with Java applications.

JTB

JTB is a syntax tree builder to be used with the Java Compiler Compiler (JavaCC) parser generator.

Git

You will be developing large programs with 100s of lines of code. It is a good idea to learn and use version control system to manage your code development. My recommendation is to learn Git version control system. Git is not essential for the course, but learning it would serve you well in the years to come.