Reading

Files

You'll need just one new source code file to add to the project this week, FunEntry.java (LINK). Add this file to the package tigerc.semant.analysis

If you had any trouble with any part of Assignment 4, I've provided a .class of my solution. You may, but are not required to, use this compiled binary as a superclass which you extend for this assignment. Neither penalty nor reward will be imposed/offered for this option.

Here's a link—LINK—compiled with Java 1.7.

To avoid reinventing the wheel, I've made a few things in this class protected:
'
public abstract class AbstractSemantV implements IAbsynVisitor {

    protected Type ty = null;
    // The "return value" of each visit() call is stored in ty

    protected Env<Entry> venv; // (variable / type identifier bindings)
    protected Env<Type> tenv; // (type identifier / type bindings)

    protected ErrorMsg err;

    protected AbstractSemantV(ErrorMsg e) {
        this(new Env(), new Env(), e);
    }

    protected AbstractSemantV(Env ve, Env te, ErrorMsg err) {
        assert ve != null && te != null && err != null;
        this.venv = ve;
        this.tenv = te;
        this.err = err;
    }
    
   ... < etc. >

Your Job

Complete the implementation of the SemantV class, for all of the remaining constructs not already implemented in Part I.

You'll need to pay special attention to corner cases in the checking of these constructs. We'll discuss many—but not necessarily all—of the subtleties that arise in the next few class periods. Consult Edwards' Tiger documentation, Appel's Appendix A (from Modern Compiler Implementation), and the guidelines for constructs that was published Assignment 4.

Finally, you'll need to add the entries for the "standard library" to your value and type environments (venv and tenv). My solution defines a makeStdLib(), which localizes the tedium of constructing each entry. Here's the start of it:
    private void makeStdLib() {

        // There are no keyword type names in Tiger.  The types "int" and 
        // "string" are simply type aliases defined in the standard library
        
        tenv.extend(Symbol.sym("int"), INT.inst);
        tenv.extend(Symbol.sym("string"), STRING.inst);
        
        // FunEntry bindings for the standard library functions & procedures
        
        // ord
        List<Pair<Symbol, Type>> ordFmls = new java.util.ArrayList<>();
        ordFmls.add(new Pair<Symbol, Type>(Symbol.sym("s"), STRING.inst));
        venv.extend(Symbol.sym("ord"), new FunEntry(ordFmls, INT.inst));

        // print
        List<Pair<Symbol, Type>> printFmls = new java.util.ArrayList<>();
        printFmls.add(new Pair<Symbol, Type>(Symbol.sym("s"), STRING.inst));
        venv.extend(Symbol.sym("print"),
                new FunEntry(printFmls, VOID.inst));
        
        // ... etc. ...

Your test file from last week should be usable for this part of the project, too.

Turn In:

Please put all files in a folder named "lab5", or something similar. If you can, I'd appreciate paper copies of the work, too.


John H. E. Lasseter