Logo University of Washington Department of Computer Science & Engineering
 CSE 401Sp '01: Assignment #7, Due Friday, 6/1/01
  CSE Home  About Us    Search    Contact Info 

Individual homework

This is an individual, not group, assignment.

Extend your pl/0 compiler, scanner to codegen, to support one of the following two features:

  1. A C-like conditional operator: in any expression, the construct bexpr ? expr1 : expr2 will evaluate the Booolean expression bexpr; if true the value of the construct is the the r-value of expr1; otherwise expr. Use "short circuit" evaluation, i.e., only one of expr1 and expr2 is evaluated. Both expr1 and expr2 must be of the same scalar type, either Boolean or integer. The ? : operator has lower precedence than the other arithmetic and logical operators.

  2. Pointers. Add a new scalar type pointerto T, where T is any type except a procedure or function type. Add a new C-like unary "address of" operator "&"; assuming x is a variable of type T, "&x" returns the lvalue of x, which is of type pointerto T. Finally, add a C-like dereference operator. To avoid potential parsing problems, we'll use " at " instead of "*", but the intent is the same: for any pointer p, " at p" refers to the object pointed to by p (either its lvalue or rvalue, depending on whether it's on the left or right of an assignment, or being passed to a function by reference or by value). Pointers may be compared for equality or inequality, but other arithmetic/logical operations do not apply.

    Example:

        procedure P();
        var 
          x:   int,
          xp:  pointerto int, 
          xpp: pointerto pointerto int;
        begin
          x   := 0
          xpp := &xp;
          xp  := &x;
          @ at xpp := @@xpp+1;
          output := x;           # Should print "1".
        end P;
    

In either case, give us a short file, hw7.txt, say, outlining what changes you had to make in all phases of the compiler (scanner to codegen, especially the kinds of conditions you checked for in typechecking related to your additions), as well as a summary of your test cases. You probably don't need explicit test cases for scanning and parsing, since those will be exercised by your tests of the later phases.

You only need to turn in printouts of the above summary plus changed files. As usual, please turn in your whole directory electronically, and carefully highlight your changes on your listings. (I expect changes to be small, but widespread, so highlighting them for the TA's benefit is especially important this week.)

As usual, you will be graded on correctness of your implementation, on clarity and good design of your implementation, and on sufficiency of your test cases.

In summary, turn in: