By the time you have completed this work, you should be able to:
Download the template code below.
There is only one file you need to modify in the template code: interpreter.scala
.
In interpreter.scala
, you will need to implement the following components, all of which are described in handout 6:
lookup
helper functionaddRelation
helper functionunifyVals
helper functionunifyMultiValsHelper
helper functionunifyMultiVals
helper functionmini-prolog
, implemented in the nextState
function
If no transition rules apply for a given state, you should throw a StuckException
(defined near the top of interpreter.scala
).
You can compile your code like so:
scalac *.scala
The code can be run as follows, where tests.pl
is a file containing a valid Prolog program in the subset of Prolog we handle, and myLength([1,2,3], X).
is a query to run on tests.pl
:
scala miniprolog.interpreter.Interpreter tests.pl "myLength([1,2,3], X)."
For testing your code, you can run the test suite in the provided tester.scala
file, like so:
scala -cp scala-parser-combinators.jar:. miniprolog.tester.Tests
The provided test suite is not complete, so you are encouraged to add additional tests.
For ease of debugging, your code should be as close to the small-step transition rules as possible. Code that deviates from the mathematical definition is generally difficult to reason about, since it becomes less clear where bugs are relative to the transition rules.
You must use turnin
to turn in all of your code.
The command below will work for this purpose:
turnin assign7@cs162 interpreter.scala