Assignment 2: Untyped SimpleScala Interpreter

Description

By the time you have completed this work, you should be able to:

  • Write non-trivial code in SimpleScala, a Scala-like language we have created (defined in handout 2)
  • Read and implement a formal small-step semantics of SimpleScala, creating a SimpleScala interpreter in the process

Download the template code below. There are two files you need to modify in the template code:

  1. lists.simplescala
  2. interpreter.scala

In lists.simplescala, you will need to implement a number of list operations in SimpleScala, a language we have developed specifically for this class. These operations are largely based on the operations you implemented in MyList.scala, as part of Assignment 1. lists.simplescala contains more relevant information.

In interpreter.scala, you will need to implement the transition rules for SimpleScala, which are defined in handout 2. All the code you write should be in the nextState method of interpreter.scala, which currently has an implementation of ???. If no transition rules apply for a given state, you should throw a StuckException (defined near the top of interpreter.scala).

Running, Compiling, and Testing

We have provided a .jar file containing a reference solution. Note that this contains only compiled class files, no actual code. The purpose of providing this reference solution is twofold:

  1. You can play around with SimpleScala directly, without having to first implement your own SimpleScala interpreter.
  2. You can test your lists.simplescala code independently from your own SimpleScala interpreter. This makes it so you can debug your lists.simplescala implementation separately from your SimpleScala interpreter.

The provided reference solution includes a REPL, which can be run like so:

scala -cp reference.jar simplescala.interpreter.Repl

From within the Repl, you can load a file full of defs like so (assuming lists.simplescala holds the defs):

:load lists.simplescala

You can declare vals and evaluate expressions in the SimpleScala REPL, just as you can with Scala's REPL. The one limitation is that inputs to the SimpleScala REPL must start and end on the same line; you cannot spread a definition across multiple lines, for instance.

We recommend getting lists.simplescala working before working on interpreter.scala. This will allow you to familiarize yourself with SimpleScala before writing an interpreter for it. This way, you will have a better intuitive notion of how execution should work before you need to actually implement how execution works.

The test suite for lists.simplescala can be run like so:

scala -cp reference.jar simplescala.interpreter.MultiTester lists.simplescala list_tests

Note that this line above runs the test suite with the reference solution, which you can assume to be correct.

Once you have lists.simplescala working, move on to implementing interpreter.scala. You can compile interpreter.scala like so:

scalac *.scala

You can run the test suite for interpreter.scala like so:

scala simplescala.interpreter.SingleTester tests

The above test suite is fairly shallow. Once that test suite is passing, you can do more in-depth testing by running the test suite for lists.simplescala directly on your own interpreter, like so:

scala simplescala.interpreter.MultiTester lists.simplescala list_tests

Be advised that neither of these test suites are particularly good for testing your code in interpreter.scala. You are strongly encouraged to write your own tests, which can be added to the tests and list_tests directories above.

Grading

A breakdown of the grade follows (out of 100 points):

  • Implementing the missing routines in lists.simplescala
  • Implementing the small-step transition rules in interpreter.scala

Downloads

Assignment 2 (zip)

Deliverables

You must use turnin to turn in all of your code. The command below will work for this purpose:

turnin assign2@cs162 lists.simplescala interpreter.scala              

Note

As a reminder: with interpreter.scala, you may not use any mutable state. This is to encourage you to think in a functional way, rather than to write Java/Python with a new syntax.