Note that the archive includes some patches for the assembler generation libraries that should fix issues on 64-bit machines.
This is a group project. Groups of size 1 or 2 are acceptable.
Implement an ocamllex parser for integer arithmetic expressions:
You will need to declare new tokens in parser.mly to support your lexer rules.
Implement an ocamlyacc parser for the AST defined in east.ml. Precedences for operators are specified in that file. Parenthesis should have the highest precedence. Don't worry about preserving information for error reporting (besides, where would you use it?). Do not use ocamlyacc's precedence declarations.
Implement rev_lite_of_ast from the module Expressions. This function will build a reversed list of X86lite instructions that Expressions_main will reverse and package into a module.
Since we don't have very much by way of compiler infrastructure at this point, there aren't too many options for storing temporary values. For this assignment, you should store your temporaries on the stack and return results in Eax. You should only have to push new values to the stack when compiling an expression containing a binary operator. In that case, first generate code for the left-hand branch, then push the result, then generate code for the right-hand branch. Remember to pop this value when you're done with it.
You can access the value at the top of the stack with the indirect operand Ind (stk_ofs 0l). To pop an item off the stack without being forced to store it somewhere, just manipulate Esp directly with LInsn.Add (esp, CImm 4l). Remember that the shift instructions put special requirements on the location of the shift amount; also note that you will have to generate some extra code for the comparison and logical negation operators.
You may use only the registers Eax Ecx Edx (and memory) for computation.
Edit the included readme.txt file, making sure to fill in your name(s) and email address(es).
You should also spend some time to ensure that your code is readable and well-commented. We have some suggestions and requirements for your programming style. You will definitely lose points for the file submission requirements (code must compile, 80 column limit, no tabs); however, barring any particularly egregious cases, you may take the remaining rules as suggestions.
Part of your grade will be based on testing. Some example tests and utility functions are provided in expressions_test.ml. For this assignment, we require that you define at least 10 new unit tests. (These must be sufficiently different from one another to count— tests like 1 + 1 is 2, 1 + 2 is 3, 1 + 3 is 4 are too similar to be useful). A good way to hit and surpass this requirement is to write tests for each operator, but remember to test combinations of operators (to check that you have precedence correct and that you aren't doing unusual things to the stack).
Since the tests are a little less tricky this time around, please do not share them on the mailing list.
The grading breakdown for this project is as follows:
Remember that your raw score will be scaled— that is, more difficult assignments will be worth more than less difficult assignments, even if the more difficult assignment has fewer available points.