Compilers: Programming Assignment 3

Abstract syntax trees for php--

Due date: Friday, March 14, 2008

The goal of this programming assignment is to implement abstract syntax trees (including relevant symbol tables) for php-- and a conversion process from concrete parse trees to abstract syntax. You will also implement a pretty printer which well let you unparse abstract syntax back into something approximating php--.


What you need to do

Read this assignment in its entirety.

Download the starter project, try compiling and running it. As it stands, it is not good for much: it can only successfully generate (and print) abstract syntax for really simple programs like:

  <?php
    break;
  ?>

The assignment can be divided roughly into three parts. You do not have to do them entirely in order; it will be helpful to work on parts of the pretty printer, once you have most of expressions implemented. The middle part - conversion between concrete and abstract syntax - is far and away where most of your time should be spent.

  1. Complete the implementation of the abstract syntax hierarchy.

    I have supplied you with almost all of the ast package; you need to figure out which kinds of statement and expressions to add and then to add them. You should need a total of less than ten expressions and statement classes. In each case, you can and should follow the model of the other ast classes I have provided.

    You need to figure out what information is required to represent the parameters for abstract functions in the AST. You will want to know at least the Uid associated with each parameter; but you may also want to take into account whether or not the arguments are to be passed by reference. (Hint: you do.) Add the necessary information (look for the ellipses).


  2. Implement the conversion between concrete parse trees and abstract syntax. There are quite a few subparts to this portion of the assignment:

    1. Get enough of expressions and statements working so that you can generate and print abstract syntax for the literal loop example.

    2. Implement a class that matches the supplied ast.SymbolTable interface

    3. Finish the implementation of the Environment class which implements the supplied EnvironmentIfc interface.

    4. Finish the implementation of statements and expressions.

    5. Implement the conversion of functions.

    6. Uncomment the part of the main conversion routine that adds standard-library functions to the environment. Test to see if you can generate abstract syntax for selection sort.


  3. Finish the pretty printer for ASTs. As mentioned in class, the output will not perfect reflect the source input since explicit variable declarations will be lost.

    Test your project as thoroughly as possible. This means try both valid php-- programs and programs that have non-syntactic (non-typed based) errors like undefined or redefined variables and functions.


Binaries

You may find it useful to experiment with the binaries for the solution.


Submission

Upload a suitably compressed tar ball or zip archive of your completed project here.