By the time you have completed this work, you should be able to:
SimpleScala
, a Scala-like language we have created (defined in handout 2)SimpleScala
, creating a SimpleScala
interpreter in the processDownload the template code below. There are two files you need to modify in the template code:
lists.simplescala
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
).
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:
SimpleScala
directly, without having to first implement your own SimpleScala
interpreter.
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 def
s like so (assuming lists.simplescala
holds the def
s):
:load lists.simplescala
You can declare val
s 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.
A breakdown of the grade follows (out of 100 points):
lists.simplescala
interpreter.scala
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
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.