1 The new AST definition
2 Errors to Detect
3 Handin
4 Errors and Corrections

Assignment 3, CSC431, Spring 2010

For the next assignment, you must write the static checking and rewriting pass for your compiler. Its job is to transform the AST that is the result of parsing into a form suitable for code generation, and to perform certain simple syntactic checks.

The input to the static pass will be an exp, as defined by the AST module.

You must produce the StaticPass module containing two functions:

1 The new AST definition

Here’s the definition of AST2.fs:

module AST2

 

type exp =

    ID of (string * int * int) // string for debugging

    | BoolExp of bool

    | IntExp of int

    | DoubleExp of int

    | StringExp of int

    | PrimExp of (AST.prim * exp list)

    | IfExp of (exp * exp * exp)

    | WhileExp of (exp * exp)

    | ReturnExp of exp

    | SetExp of ((string * int * int) * exp)

    | BeginExp of (exp list)

    | FieldRefExp of (exp * int)

    | FieldSetExp of (exp * int * exp)

    | MethodCallExp of (exp * int * exp list)

    | NewExp of (exp * exp list)

    | AppExp of (exp * exp list)

    | CloExp of (string * int) // string for debugging

    | ScopeExp of (int * string list * exp)

    with override self.ToString () = (sprintf "%A" self)

 

type funEntry = string * string list * exp * bool

 

type doubleTable = Map<double,int>

type stringTable = Map<string,int>

type funTable = Map<funEntry,int>

type fieldNameTable = Map<string,int>

 

type sframe = (Map<string,int> * int ref)

type senv = (sframe * sframe list)

We’ve discussed the meaning of each of these AST2 forms in class, but feel free to ask for clarification on the newsgroup.

2 Errors to Detect

Your translator must detect and signal the following errors:
  • Unbound identifiers

  • Attempts to bind variables named this.

  • Attempts to mutate this.

3 Handin

Hand in this assignment by creating an Assignment3 subdirectory in the private section of the subversion repository. You should include a makefile that produces StaticPass.dll, and a TEAM file as before, along with all source files needed to compile it.

4 Errors and Corrections

As always, let me know about any errors or ambiguities in the assignment specification.