Summary: Download as1.zip and modify the two files maxarg.sml and interp.sml as specified in MCIinML, Program 1 (page 10-12). Write two additional test programs.

Details:

  1. Read Chapter 1 of the textbook, "Modern Compiler Implementation in ML," particularly pages 7-12.
  2. Download the files and read them. Pay special attention to how it is divided into separate structures.
  3. Install SML/NJ on your own machine (preferred), or use the preinstalled SML/NJ on the CS or OIT machines* (see the installation notes).
  4. Run sml in the same directory as your as1 files.
  5. At the sml prompt, type CM.make "sources.cm"; (semicolon and all). This should compile and load all the source files. Still in SML/NJ, type Test.maxarg(); This should run the maxarg function on the test program; since you haven't yet modified the program I provided you, it should raise an exception.
  6. Edit maxarg.sml until it's the right program. Still in the same session of sml, type CM.make "sources.cm"; Observe the compiler's messages and fix the problems that are reported. You can keep a running ML session while you are debugging. Simply type CM.make "sources.cm"; again when you think you have fixed the problem. This procedure saves a lot of time, because you avoid starting ML over and over again.
  7. Test your code by invoking Test.maxarg(); (still within the running ML session).
  8. If your code still does not work as intended, then debug, recompile, rerun. Repeat as necessary.
  9. Do the same for interp.sml, using Test.interp();
  10. Write two additional test programs and integrate them to the test infrastructure: in testprog.sml, add two additional programs, named prog1 and prog2. Then, in test.sml, add functions interp1, interp2, maxarg1, and maxarg2 that invoke programs prog1 and prog2. Recompile, test, debug as necesary. (You should not modify sources.cm);
  11. Upload the following files here to dropbox: maxarg.sml, interp.sml, testprog.sml, README. In README, mention any help you gave or received, briefly say why your testcases don't simply duplicate the test case given to you and what the expected outputs are. You may also mention addional aspectes - things you struggled with, or things you enjoyed.
  12. Once you are done, to further familiarize yourself with ML and with simple interpreters you may want to spend some time extending the language and your interpreter. The extension might add new operators for comparison (use 0 for false and non-zero for true outcomes), and syntax that takes the "straight-line programming language" to something with pattern matching, conditionals (if) or loops (while). This does not give you extra credit immediately, but it could help you get up to speed. Eventually it may even pay a nice dividend when you are working on future assignments. If you are unfamiliar with ML, play around some more. The more the better. Write a file of your own and import it and test it in the top-level environment. To quit the top-level environment, type ctrl-D (ctrl-Z if using SML under Windows).

Available from: Thursday, 4 February 2016
Due date: Monday, 15 February 2016, 9:00 PM

*Note: Some students have noted issues when using the university machines. Please install on your own machines if possible.