CS451/651 Compilers
Bill Campbell
Spring 2009
Programming Exercise 6: Analysis and Code Generation II

Your job here is to implement analysis and code generation for the following constructs, which you parsed in programming exercise 3. You will want to see Chapter 7 of our text, and Chapter 7 (and other chapters) of the JVM Spec: http://java.sun.com/docs/books/jvms/second_edition/html/VMSpecTOC.doc.html.

1.     Double literals. This will affect most numeric operations and casts.  Notice that there are no implicit conversions, but you must implement any necessary casts.

2.     The classical for statement and the enhanced for statement.

It’s probably best to write a set of test programs first. Then you can compile them with javac to see what it generates for code.  And you have some measure as to when you are done.   (Welcome to extreme programming.)

Hand in hard copy of your program, your test program and their results, and your narrative no later than 4:00 p.m., Monday May 11.  And, as usual, put your tree in p6/ of your course directory.

3.     (Extra credit) The conditional || operator, making sure to implement short-circuiting correctly.

4.     (Extra credit) Implement implicit conversions wherever the specification says this is possible.  Discuss the conversions you think the specification calls for and discuss the conversions that you have implemented.

Your narrative will be very important in this assignment, since there are things left unsaid. This assignment makes use of many classes, I strongly suggest that you start out on this assignment immediately; there is lots of programming to do, there is lots of testing to do, and probably there will be lots of repairing to do. And, of course there is lots of writing to do. Have fun!

Grade sheet