Jay Interpreter Programming Project:
A major programming project for this term will be to implement a Jay interpreter in Haskell. The interpreter program (which is a function, of course) should return the final state of the Jay program's environment. The program's input should be a parse tree of the form that will be / has been presented in class. A sample parse tree (aka intermediate representation) syntax for a simple Fibonacci program is available here:
JayFibSampleParseTree.hs
The TestSuiteSupportModule is available from the following link:
TestSuiteSupportModule.hs
.
You may use the following Main module for this project, if you like,
uncommenting the import
and print
statements
for the various test suites as you go.
Main.hs
Part 1: Representing State
The first step will be to implement a way of representing state, which we will simplistically define as a set of {Name, Value} pairs (also known as bindings), where Name is a variable name (identifier for a memory location) and Value is the value bound to the identifier. This definition leaves out the actual locations, meaning, if you think about it, that it does not support aliases.
JayValueStateIntro.txt
contains an explanation of the data type definitions used by this program for representing state.
ValuesAndState.hs
contains function signatures for accessing and modifying state, with associated test cases.
The first step of the project is to copy the type
and
data
definitions (the entire "Final definitions" section)
from
JayValueStateIntro.txt
into the
ValuesAndState.hs
file. Then implement the functions for accessing and modifying state.
(Remove the [ CODE MISSING ! ]
comments as you replace
each with the missing code!)
You can test your work when you are done by running the
zero-parameter stateFunctionsTestSuite
function defined
at the bottom of
ValuesAndState.hs
or by uncommenting the appropriate import
and
print
statements in
Main.hs
.
Part 2: Declarations
The next step will be to write code to interpret Jay declarations expressed in our intermediate language. The data types definitions and function signatures for representing interpreting declarations, and the associated test cases, are in this file:
JayDecls.hs
You can test your work when you are done by running the
zero-parameter declarationTestSuite
function defined
at the bottom of
JayDecls.hs
or by uncommenting the appropriate import
and
print
statements in
Main.hs
.
Part 3: Expressions
The data types definitions and function signatures for representing expressions, and the associated test cases, are in this file:
JayExpressions.hs
Simplest Expressions:
The place to start is with the
simplest expressions — constants and variables. You should test
these using the expressionTestSuite
function
before you implement the expressions composed of binary
operators. Don't worry or be surprised if you get test failures and/or
pattern matching errors for the test cases that test features you
haven't implemented yet. (This is standard procedure for "test-driven
development.")
Binary Operators: Once you have the most basic expressions implemented and tested, you can implement the other expression types. As you implement the various categories of binary operators, I strongly recommend that you implement and test each type before moving on to the next (agile development). Again, don't worry or be surprised if you get test failures and/or pattern matching errors for test cases that test features you haven't implemented yet.
Note: for division, you want to use the "div" operator in Haskell rather than the "/" operator, since the former does integer division.
Part 4
The next step is to implement the semantics for various types of statements. The data types definitions and function signatures for representing statements, and the associated test cases, are in this file:
JayStatements.hs
Simplest Statements: The simplest statements are
the empty statement and assignment. You should implement and test
these using the statementTestSuite
function
before implementing the more complex statements types.
Again, don't worry or be surprised if you get test failures and/or
pattern matching errors for test cases that test features you
haven't implemented yet.
More Complex Statements: Once you have the simplest statements implemented and tested, you can implement and test the other statement types, testing each before moving on to the next.
Wrapping it all up
The final step is to implement the function that interprets a Jay program expressed in our intermediate parse tree format.
The file for the program as a whole is:
JayInterpreter.hs
The file for the sample fibonacci program from p. 43 of Tucker and Noonan (1st Ed.) is:
JayFibSampleParseTree.hs