|CSE Home||About Us||Search||Contact Info|
This is an individual, not group, assignment.
Extend your pl/0 compiler, scanner to codegen, to support one of the following two features:
A C-like conditional operator: in any expression, the
bexpr ? expr1 : expr2
will evaluate the Booolean expression
true the value of the construct is the the r-value of
"short circuit" evaluation, i.e., only one of
expr2 is evaluated.
expr2 must be of
the same scalar type, either Boolean or integer. The
? : operator has lower precedence than the
other arithmetic and logical operators.
pointerto T, where
Tis any type except a procedure or function type. Add a new C-like unary "address of" operator "&"; assuming
xis 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
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.
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: