CSC 330 Assignment 4

Assignment 4: Some Further Clarifications



Revised Due Date

As announced in class, the revised due date for Assignment 4 is 5PM Friday 13 May.

Fix to ejay.cup

Please make the following patch to your copy of ejay.cup: In the very last rule at the bottom of the file, change the first argument in the two invocations of LeafNode from "sym.IDENT" to "sym.TRUE" for the TRUE alternative, and "sym.FALSE" for the FALSE alternative. I.e., change the rule from this
Boolean ::= TRUE:t
              {: RESULT = new LeafNode(sym.IDENT, null, tleft, tright); :}
        | FALSE:f
              {: RESULT = new LeafNode(sym.IDENT, null, fleft, fright); :}
        ;
to this
Boolean ::= TRUE:t
              {: RESULT = new LeafNode(sym.TRUE, null, tleft, tright); :}
        | FALSE:f
              {: RESULT = new LeafNode(sym.FALSE, null, fleft, fright); :}

Limited main Method in EJay Programs

In test programs you write yourself, do not declare any parameters or local variables in the main method. We don't need parameters at all. Anything that you'd want for a local in main, make a global program variable, i.e., declare it outside of any function. The final test data for Assignment 4 will have only parameterless and variable-free main methods.

No Unary Arithmetic Operators

Your interpreter does not need to handle unary arithmetic operators, i.e., unary plus and unary minus. The final test data for Assignment 4 will have no expressions containing these operators.

No Multi-Dimensional Arrays of the Form type[d1,...dn]

Your interpreter need only work for arrays declared with one dimension in the bracketed list of dimensions. E.g., it needs to interpret arrays such as this
int [10] a;
but not this
int[10,10,10] a;

Your interpreter does need to handle arrays of arrays, e.g., of the form

int[10][10][10] a

Refinements to the Specification of Error Handling for Arrays and Structs

Your interpreter must perform the following semantic checks related to arrays:
  1. The array index operator can only be used on an array type. E.g., the following is an error:
    int i,j;
    

    ...

    i = j[5];
    since j is not an array type.
  2. An array index expression cannot be out of bounds. E.g., the following is an error:
    int i;
    int a[10];
    

    ...

    i = a[11];
    Note that array indices start at 0, as in Java and C. Therefore, a[10] is also an out-of-bounds index for the array declared as "int a[10]".

Your interpreter must perform the following semantic checks related to structs:

  1. The left operand of the dot operator must be a struct type.
  2. The right operand of the dot operator must be the name of a field declared in the left-operand struct type.
E.g., the following is an error that violates both of these rules:
int i,j,k;


...

i = j.k;

Update Necessary to evalAssmt Method for Arrays and Structs

To get arrays and structs working, you need to update a simplification in the Pascal version of evalAssmnt. In the Pascal subset, there are no arrays or records, so the LHS of the assignment is evaluated using evalIdentLValue. In an EJay interpreter that does arrays and structs, this needs to be changed to evalDesigLValue.

A Freebie -- evalPrint

Being able to print variable and parameter values from inside an EJay program can be a very hand way to debug your interpreter. So here's a freebie implementation of evalPrint (sorry to any of you who may have spent hours working on it):
    public void evalPrint(TreeNode1 printStmt, SymbolTable symtab) {
        Value val;
        for (TreeNodeList list = (TreeNodeList) printStmt.child; list != null;
                list = list.siblings) {
            val = eval(list.node, symtab);
            if (val != null) {
                System.out.print(val.val);
            }
        }
    }

Assignment 4 Scoring

The following table summarizes the scoring that will be used to grade Assignment 4:
Statements and expressions with simple types: 40%
Function calls, no return: 32   
Return: 5   
Arrays: 9   
Structs: 9   
Call-by-ref parameters: 5   

AN IMPORTANT NOTE: The latter parts of the assignment may be exponentially difficult, in that the number of hours you may spend on them is not directly proportional to their point values relative to the the earlier parts. As always, you can earn partial credit if you pass some but not all test cases.