CPSC 411 Compiler construction I

Author: Robin Cockett
Date: 21 March. 2008


Assignment #3: Test programs for M+ parser and scanner




  1. Exponential function (here) -- simple test of variable scope.
  2. The Fibonacci sequence (here) -- example of a recursive program.
  3. A more efficient way of computing Fibonacci numbers here.
  4. An example using local functions here.
  5. Computing the maxium of two numbers here.
  6. Over use of names (should parse but fails semantic checks) here.
  7. How to decrement a number here.
  8. Badly typed expression which parse but will fail type checking here.
  9. If you can parse this you are seriously deviating from the grammar!



Assignment #4:  Test programs for M+ semantic checking.




From the tests above 1, 3, 4, 5, 6, 7, 8, together with the following additional tests:
  1. Local functions can be declared in blocks here
  2. Does your type checking really work on functions here
  3. So you should be able to compute averages ... here



Assignment #5: Test programs for M+ code generation.



From the test set for Assignment #3:  1,2,3,7 as corrected here
From the test set for Assignment #4: 1,3
... and a last program here to calculate the GCD.



Test cases for M: the bonus ...


  1. Can you append lists here.
  2. Can you multiply matrices here.
  3. Quicksort here.
  4. Mergesort here.
  5. Backslang here.
  6. Three dimensional arrays here.
  7. Are you checking dimensions correctly here?
  8. Can you mix arrays and datatypes here.