CPS710

Assignment 4

Toronto Metropolitan University University

Evaluator - Part 1

Due: December 7


Objectives

In this assignment you will writing a complete interpreter for most of the components of HL that do not involve identifiers. This interpreter will not handle errors in programs.

This should start familiarizing you with evaluation and the JJTree support for visitors.

The learning objectives covered in this assignment are: 6Cb (which automatically generates 6Ca and 6Db), 6Ba, and 6Ab. Some of these learning objectives will be identified in the description of this assignment, and some in the tests.

Unlike for previous programming assignments, solutions to this assignment will not be provided. You will therefore need to do most of this assignment as a base for the next two. However, you will be able to submit this assignment by itself or along with the other two. This is explained in the submission section.

Preparation

  1. The working directory for the fourth assignment should have the same structure as the third assignment: for example:
    mkdir 710A4
    cd 710A4
    mkdir Tests
    mkdir AST
    
  2. Copy all the files in the Handouts directory into your working directory. These files are located on the moons at ~cps710/public_html/doc/F2024/A4/Handouts:
    cp ~cps710/public_html/doc/F2024/A4/Handouts/* .
    cp ~cps710/public_html/doc/F2024/A4/Handouts/src/* .
    mv SimpleNode.java AST
    
    Some of the files are the same as the ones in the previous handouts, but TestHL.java, SimpleNode.java, makefile, t, and runtests have been modified for this assignment.

  3. Prepare HL.jjt and HLEval.java:

    You need to decide whether you will work from your own assignment 3 solution or the one handed out.

  4. Run make to recompile everything
      make
    

  5. Final Comment

    Whether you chose to use your own assignment 3 or the solution handed out, the HLEval.java in your working directory works in tandem with the HL.jjt in that same directory: HLEval contains a visit method which is overloaded once for each type of AST defined in HL.jjt.

    You may want to change some of these ASTs in HL.jjt, but if you do so, be aware that you will also need to change HLEval manually to reflect these changes. You will also need to clean up some of the files in the AST directory manually.

    Nonetheless, even though this is not necessary for the implementation of this assignment, you may do this if you wish, as long as you do not change the syntax or the semantics of HL.

Assignment

In this assignment you will be writing the initial component of the interpreter for the language HL, which is a special-purpose language for the manipulation of ordered sets of integers. Its semantics are defined in the HL Semantics - Part 1 document which describes the semantics of the language for the components of the interpreter implemented in this assignment: mostly expressions, and a few statements.

Below are the components that you will need to implement in this assignment. As you do so, remember that, as with previous assignments, you can continue to assume that the HL programs are error free. This means that your program does not need to handle invalid situations yet.

6Cb: Literals, print and if statements, arithmetic expressions

For this learning objective, you should implement eval visitors for HL string literals can simply evaluate to java Strings, and HL Boolean literals can evaluate to java Booleans. However, because the operators used with the other two HL types are overloaded, it is useful to define special HL classes for HL numbers and HL sets. These are called HLNumber and HLSet respectively.

We are proposing the following class infrastructure that will facilitate the implementation of the HL evaluator by taking advantage of the OOP nature of Java: In the src subdirectory of the Handouts directory you will find a fully implemented version of HLObject.java and skeleton files for the other two classes.

The first reason why HL needs its own classes is that this OOP infrastructure with overridden generic methods will naturally devolve all the evaluation work into the appropriate type of value. As a result, the HLEval methods can be very generic and do not need to perform any type checking.

The second reason is that the classes provided in Java that are naturally aligned with these two HL types, Integer and TreeSet respectively, do not have the all the features required by the HL semantics.

At first this will seem like an onerous infrastructure just to perform a few operations on integers and sets, but as soon as more functionality needs to be implemented, this organisation will pay off. As explained in the submission section, you can overwrite as much of this provided infrastructure if you want, but I encourage you to review what is already provided, as it is probably a lot less work to use it rather than coming up with your own, which may turn out not to be substantially different.

6Ba: Set literals and remaining integer and Boolean functionality

For this learning objective, you should implement eval visitors and supporting HLNumber and HLSet methods to evaluate

See the HL Semantics - Part 1 for further details.

Hints:

6Ab: Sets

For this learning objective, you should implement eval visitors and supporting HLSet methods to evaluate See the HL Semantics - Part 1 for further details.

Testing your assignment

The testing process for this assignment is quite similar to the previous assignments. However, it is simpler this time: There is a single test script which simply tests all the learning objectives in order. You can find this test script (called runtests), and the unit test t in the Handouts directory.

The tests and results are in the Tests directory.

Submitting the assignment

You can submit this assignment by itself, to be assessed independently of the next assignment, or later on with the next assignment (this will be explained in the next assignment).
To submit this assignment by itself:

References

JJTree

Java


This page is maintained by Sophie Quigley (cps710@cs.torontomu.ca)
Last modified Friday, 22-Nov-2024 15:03:08 EST