CS712/CS812
Homework 1
Spring 2008
Due: Sunday February 3


Add floating point constants, the addition operator and a code generator to the Simp Compiler (simpc). The source for simpc can be found in cisunix.unh.edu:~cs712/public/simp.

If you successfully add floating point constants, you will receive 60 points. If you successfully add both floating point constants and the addition operator, you will receive 80 points. If you successfully add all three features, you will receive 100 points.

Use the following definition of floating point constants (from "The C Programming Language", first edition, by Kernighan and Ritchie):

A floating constant consists of an integer part, a decimal point, a fraction part, an e or E, and an optionally signed integer exponent. The integer and fraction parts both consist of a sequence of digits. Either the integer part or the fraction part (not both) may be missing; either the decimal point or the e and the exponent (not both) may be missing.

Modify the scanner to recognize floating-point constants and add an AST node for floating-point constants. Be sure to implement "dump" and "analyze" methods to properly process these constants.

The addition operator should be left-associative and should be lower precedence than the division operator. Like division, if the addition operator has one operand of integer type and one operand of floating-point type, then the integer operand should be converted to floating-point type. Add an AST node to represent the addition operator and implement "dump" and "analyze" methods to properly process this node.

Implement the code generator by adding a virtual method called "encode" to the AST class hierarchy. Place the implementations of these methods in a file called "encode.cxx". The code generator should target the Intel IA-32 architecture. All Intel code necessary for this assignment will be discussed in class. The Simp integer type should be mapped to an Intel 32-bit integer type. The Simp floating-point type shold be mapped to IEEE 32-bit floating point. (Be sure to check that Simp floating-point constants fit into the IEEE 32-bit floating-point container.)

The file ~cs712/public/simp/Thw1.simp is a test file that your modified simpc (at the 100% level) should be able to handle. Other test files will be used when grading your submission so be sure you thoroughly test your work.

You should electronically turn in all source files for your modified simpc. Even if you only modified a few of the files, give me all the files back, including the Makefile and any new files you added.

Your program should be submitted for grading from either euler.unh.edu or zeno.unh.edu. (The submission scripts will not run on gauss.unh.edu.) To turn in this assignment, type:
~cs712/bin/submit hw1 [list of files to submit]

Do not turn in any non-Ascii files (i.e. no object files, no executable files, etc.).

Submissions can be checked by typing:
~cs712/bin/scheck hw1

To receive full credit for the assignment, you must turn in your files prior to 8am on Monday February 4. Late submissions will be accepted at a penalty of 2 points for one day late, 5 points for two days late, 10 points for three days late, 20 points for four days late, and 40 points for five days late. No assignment may be turned in more than 5 days late. An assignment is not considered late unless turned in after 8am on the day after the due date.

You are expected to do your own work on this assignment.


Last modified on January 24, 2008.

Comments and questions should be directed to hatcher@unh.edu