Assignment 7: Adding new data types
1 Problem description
2 Submission

Assignment 7: Adding new data types🔗

Due: Fri 03/01 at 11:59pm

1 Problem description🔗

Most languages have an interesting assortment of representations of numbers: Racket supports arbitrarily large integers, fractions, complex numbers, inexact numbers, etc. Pyret supports several of these as well. So does Python. This is sometimes called “the Numeric Tower”, and it’s worth considering how we might add support for (some of!) these varieties of numbers to our own language.

  1. Suppose we want to add support to Egg-eater for double-precision (IEEE-754 64-bit) floating point numbers. Describe what phases of the compiler might be impacted, and describe the changes needed. Assume that the lexical syntax for doubles is the same as in C or Python.

  2. Suppose we implemented the above correctly. Now suppose we wanted to also add support for complex numbers, whose components could each be either ints or doubles, and that obey the standard rules of complex arithmetic. Describe what else in your compiler might need to change, and how these new numbers interact with any existing language features. Assume that the lexical syntax of complex numbers is A+Bi or A-Bi, where A and B are ints or doubles (and B is non-negative, just for simplicity).

Answer question 1 first, then answer question 2.

Your answers to each question should address all the phases of compilation: if you think a phase is irrelevant to these changes, explain why; if you think the change is trivial, explain it concisely. You should work through the full compiler design recipe, giving concrete syntax, examples, semantics, and descriptions of implementation and interesting test cases. (You do not have to explain how to change the lexer to support floating-point or complex-number literal notation, or how to update the parser to support the grammar updates you describe, and can assume that those two are given to you. You should explain what changes are needed in your abstract syntax, and work from there.)

Your response should be only a few pages long (i.e. I’m not expecting a lengthy writeup, but you should still express yourself as clearly as necessary), and should be written in clear, grammatical English, with pseudocode if you choose. Submit either a plain text file, a Markdown file, a Word document, or a PDF — and make sure that you confirm that your submission renders properly on the handin server, so that I can read it legibly. (Please don’t make me struggle to decipher the formatting... If you do submit a text or Markdown file, please line-wrap it to at most 100 characters per line, so it fits neatly onscreen.)

2 Submission🔗

Wait! Please read the assignment again and verify that you have not forgotten anything!

Please submit your homework to by the above deadline.