Interpreter, V2

In an earlier assignment, you modified some existing classes to create an interpreter for a language that consists of assignments. In this assignment you will start with the classes you wrote before and expand them add selection and loops to the language.


Objectives


Grammar

The basic unit of this language is a statement. Statements will be scanned, parsed and evaluated one at a time. It is not safe to make any assumptions about whitespace.

A program in this language is a sequence of statements. So the start symbol is <statement>.

    < statement> -> < assignStmt > |  < ifStmt > |  < loopStmt >   

    <assignStmt>  -> <var> = <expr> ;

    <expr>  -> <term> {(+ | -) <term> } 

    <term>   -> <primary>  {(* | /) <primary>} 

    <primary>  -> <var> | <number>  | (<expr>) | - <primary> 

    <ifStmt>  -> if (<boolExpr>) <stmtList> [else <stmtList>] end;

    <loopStmt>  -> while (<boolExpr>) <stmtList> end;

    <boolExpr>  -> <logicalExpr> && <logicalExpr> |  !<logicalExpr>  |  <logicalExpr>

    <locicalExpr>  -> <expr> (< | ==) <expr> 

    <stmtList>  -> {<statement>}

Note: All the curly braces in the above grammar are the EBNF notation for repetition. There are no curly braces in the language that the grammar defines.


Example Code

if (a<b) max=b; min=a; else max=a; min=b; end;

if (!a==b) result=0; end;

while (i<10 && sum<100) sum = sum + i * 2 - 3; i = i + 1; end;

Specification

Use your classes from I1. If you don't have a working Environment class, come and talk to me. I'll provide you with a working class file that you can use and help you get the Evaluator working with that class.

Modify and add to the classes of the existing interpreter to add the following functionality:


Testing

Download or copy from the directory on onyx the following files:

Create a new subdirectory called myTests and write at least 5 test files that you can use to test the added functionality of your interpreter. Part of your score will be based on your test files so try to provide tests for everything you added.

FYI: testProg is a shell script written in bash. You should be able to tell what it does by reading the file in an editor or listing it to the screen with the cat command. You might find it helpful to create modified scripts for testing the Lexer and Parser classes separately using TestLexer and TestParser respectively.

The makefile is written to work with the files I provided plus a class called Environment. If you added more classes or if you named your environment class something different, you'll need to modify the makefile accordingly. If you used something other than the default package, you will also have to modify the makefile so that make by itself compiles the program, make run runs the program and make doc generates documentation in a directory called html. Ask for help if you don't know enough about makefiles to do this.


Documentation

Use javadoc comments to document all the methods that you added or modified in the existing classes. You should also include a file called readme that explains your approach to building parse trees and tells me where to look for the changes in your classes. If you are trying for extra credit, tell me what to look for.


Submission

Required files

Put all the required filed for the assignment in a single directory, change to that directory and submit using the following command:

submit tcole cs354 i2