Homework 9: Forest Flame, Due Friday, Nov 15 (Open Collaboration)
For this assignment, you may work in groups of 2. You may also talk with other students in the class about design and implementation approachs, although you should not look at code from another student's solution to this homework.
In this assignment you have a choice: implement garbage collection or write a non-S-expression based parser for your language.
Setup
There is no starter repository for this assignment. You should start based on one of your own compilers, or the compiler of another student in the class.
Option 1: Garbage Collection
Extend your Egg Eater language to support garbage collection. You may use any garbage collection algorithm. Mark/sweep or reference counting are recommended as simple approaches. You may implement a copying collector or compaction for 10% extra credit; adding generational collection or other more advanced GC techniques raises the max extra credit to 20%. Include at least one test case that eventually allocates 10x (or more) of the heap size given (see below), but continues to run successfully due to the garbage collector. You must also include at least one test case that results in an out of memory error, because the memory reachable at one time exceeds the heap size. Include a PDF explaining the algorithm you used, how it is implemented (i.e. where should we look to see the parts) and how to run the tests.
Your compiled program should now take two arguments instead of just one.
The first argument is the input, which may be a number. If no arguments are provided, the default input is 0.
The second argument is the heap size in (8-byte) words, which must be a nonnegative number. If no second argument is provided, the default heap size is 10000.
During a program's execution, if heap space runs out, it runs the garbage collector. If there is still not enough heap space, it exits with the error out of memory
.
Option 2: Parsing
Implement a lexer and a parser for your compiler. You must support at least Diamondback functionality. Supporting Egg Eater is worth 10% extra credit. Your syntax can be anything you want, except that it must not be based on S-expressions (otherwise your prior handin would already be a solution). You can of course use parentheses in the same places that languages like C and Java use them. We recommend choosing a syntax that makes parsing easy. Include test cases that exercise all syntax, and at least 5 test cases that illustrate syntax errors. Include a PDF that specifies an unambiguous grammar for your language.
You can construct a lexer and parser by hand or use any tool you like. We recommend using lalrpop. Note: if you know about Parsing Expression Grammars (PEGs), you can use these, but your PDF must still specify a grammar that is unambiguous without the need to prioritize the first production for every nonterminal, as PEGs do.
Handin
Submit your code, including all tests, and including the PDF in the root of the repository as design.pdf, as your Homework 9.
Happy hacking!
Grading
Grading will be based on a correct implementation of garbage collection or of your grammar, on tests as specified above, and on the clarity and completeness of your design document.