CS 214: Programming Languages
Spring 2009

Home|Syllabus|Schedule
<<|>>|ANTLR API|CITkit API|PolyD API|EasyMock API

Setting Up to Write an Interpreter
Interpreters, Iteration 1

The Tools

There are several tools you'll use to write an interpreter. You'll start with these:

You'll be responsible for all of these tools on your own machines (if you choose to work there).

Getting Started in Eclipse

Create the Project

The instructions on these pages will give you rather limited instructions on where to find features and options in Eclipse. This is to forcibly encourage you to build up intuitions where these features and options can be found. Immediate hint: to create anything new, look at the File menu, or (better yet) right click the the Package Explorer.

You need to first create and configure a Java project in Eclipse for your interpreters. First, create the project:

  1. Start up Eclipse. Use whatever workspace you like.
  2. (optional) Close all other projects. (This will make Eclipse run faster.)
  3. Create a new Java project named CS 214 Interpreters. Some information for the wizard:
    • Create a new project in the workspace.
    • Use a 1.5 or 1.6 JRE.
    • Do create separate folders for source and class files.
    • Don't add to a working set.
    • And "finish".

Now you have to configure the project.

Java Libraries

External and third-party libraries in Java are packaged up in JAR files. The Java compiler and virtual machine uses a classpath for developers to specify where to find those JAR files. Eclipse lets you specify two different classpaths: a build path and a runtime path. For our purposes, specifying just the build path will be sufficient (since it's used by default for runtime paths).

Eclipse already comes with some JAR files for common libraries like JUnit. Eclipse officially calls these "libraries".

Open up the Properties dialog of your interpreter project, and select the Libraries tab of the Java build path. Add JUnit 4 as a library.

You'll also need jars for the ANTLR and Hobbes libraries. There are a couple of options for setting these up in Eclipse. One option would be to declare classpath variables which would allow you to store the jar files in different places on different machines. The drawback to this approach is that each machine needs their own copies of the libraries, and they need to be kept up to date.

An alternative is to store the jar files in your project. They will take up room in your project, and when you commit your files into a repository (like subversion or git), that can be quite expensive, but it will keep the libraries in sync on all of your machines.

We're going to opt for the second approach.

Once these jar files are in your lib folder, they can be added to the build path.

Eclipse is smart. Refresh your project if you don't see the jar files in the lib folder. Right-click on a jar file, select Build Path -> Add to Build Path. Rinse, and repeat.

Folder Configuration

There is one last thing you should do to get your project ready for some real work. As I suggested above, Eclipse will put your source code files and class files into two different directories. This is very handy in managing files, especially in a subversion repository.

Hint: creating anything new in a project can almost always be done with a right-click in the Package Explorer.

You need a second source folder, though, for your tests. It is useful in creating your own JAR files to separate your tests from computation code.

Create a new source folder called tests in your interpreters project.

Summary

That should get you started in Eclipse. You've gotten some experience installing software-development tools. You've had to play around with Java's classpath (Eclipse style). You've created two source folders.