COS 320 - Assignment 1

Compiling Techniques, Spring 2012, Princeton University.      Due date: Monday 13 February.
Summary: Download as1.zip and modify the two files maxarg.sml and interp.sml as specified in MCIinML, Program 1 (page 10-12).

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 modules, called structures.
  3. Install SML/NJ on your own machine, 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(); 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(); and Test.interp(); (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. Upload your files here to dropbox.
  11. 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).


Back to COS 320 front page