Project: Implementation of Program and Statement Kernels


Objectives

  1. Familiarity with writing a kernel class for a new type and its kernel operations (Program using Map and Statement).
  2. Familiarity with writing a kernel class for a new type and its kernel operations (Statement using Tree).
  3. Familiarity with alternative ways of testing software components.

The Problem

The problem is to complete and carefully test implementations of the constructor and kernel methods defined in interfaces ProgramKernel and StatementKernel. These are the core components in the BL compiler.

Setup

Only one member of the team should follow the steps to set up an Eclipse project for this assignment. The project should then be shared with the rest of the team by using the Subversion version control system as learned in the Version Control With Subversion lab.

To get started, import the project for this assignment, ProgramAndStatement, from the ProgramAndStatement.zip file available at this link. If you don't remember how to do this, see these Setup instructions from an earlier project.

Method

  1. Start by implementing ProgramKernel. Carefully review the Program2.java skeleton in the src folder. Pay particular attention to the representation (the private instance variables), the convention, and the correspondence. A String is used to represent the program name, a Map<String, Statement> is used to represent the program context, and a Statement is used to represent the program body. Complete the bodies of the private method createNewRep and the kernel methods (setName, name, newContext, swapContext, newBody, and swapBody). In createNewRep, make sure you use Statement1 from the component library and not Statement2 from this project (otherwise nothing will work until you have a complete and correct implementation of Statement2).
  2. Testing of ProgramKernel is kind of tricky because of the challenge of constructing Program values to test the component. We provide two different testing set-ups. Note that the example test inputs/cases provided are just for illustration purposes and are not meant as a complete test fixture. It is up to you to design appropriate additional inputs and test cases to thoroughly test your implementation.
    1. In the src folder, carefully review the test program for Program2 called ProgramTester and make sure you understand what it does. Design appropriate BL programs meant to exercise your implementation, save them in the data folder and use them as input to the test program.
    2. In the test folder, carefully review the provided JUnit test fixture ProgramTest (and Program2Test). Remember that the provided test input (in the data folder) and test cases are just meant to be examples of how to set up a JUnit test fixture for the Program2 component. Add appropriate additional inputs (in the data folder) and test cases to thoroughly test your kernel implementation.
    Once you are confident that your implementation of Program2 is correct, you can move on to the next part of this project.
  3. The next step is to implement StatementKernel. Carefully review the Statement2.java skeleton in the src folder. Pay particular attention to the representation (the private instance variable), the convention, and the correspondence. The statement is represented by a Tree<StatementLabel> where StatementLabel is a nested class obviously representing a statement label. Note the three constructors provided in the nested class. Complete the bodies of the private method createNewRep and the kernel methods (kind, addToBlock, removeFromBlock, lengthOfBlock, assembleIfElse, disassembleIfElse, assembleWhile, disassembleWhile, assembleCall, and disassembleCall). Code for the kernel methods assembleIf and disassembleIf is provided as a guide. Make sure you understand each line of code in these methods before you attempt to complete the others.
  4. Testing StatementKernel presents challenges similar to testing ProgramKernel and the set-up is similar too. Again, it is up to you to design appropriate additional inputs and test cases to thoroughly test your implementation.
    1. In the src folder, carefully review the test program for Statement2 called StatementTester and make sure you understand what it does. It is similar to the ProgramTester program but reads a sequence of BL statements instead of a complete BL program. Design appropriate BL statements meant to exercise your implementation, save them in the data folder and use them as input to the test program.
    2. In the test folder, carefully review the provided JUnit test fixture StatementTest (and Statement2Test). Remember that the provided test input (in the data folder) and test cases are just meant to be examples of how to set up a JUnit test fixture for the Statement2 component. Add appropriate additional inputs (in the data folder) and test cases to thoroughly test your kernel implementation.
    Once you are confident that your implementation of Statement2 is correct, you are done with the project.
  5. When you and your teammate(s) are done with the project, decide who is going to submit your solution. That team member should select the Eclipse project ProgramAndStatement (not just some of the files, but the whole project) containing the complete group submission, create a zip archive of it, and submit the zip archive to the Carmen dropbox for this project, as described in Submitting a Project. Note that you will only be allowed one submission per group, that is, your group can submit as many times as you want, but only the last submission will be on Carmen and will be graded. Under no circumstance will teammates be allowed to submit separate solutions. Make sure that you and your partner agree on what should be submitted.