COS 320, Spring 2000. Programming Assignment

Programming Assignment 1: Intro to SML

Getting started with ML:

  1. Use CIT Sparc machines ( If you have a PC running Linux, then you should also be able to install ML there. You can grab a copy of the compiler from the official server at Bell Labs.
  2. Edit your .cshrc or equivalent so that your path contains /u/cos320/ml.
  3. Make a new directory as1 for this assignment.
  4. Copy the files *.sml *.sig and *.cm from directory /u/cos320/chap1/ into as1.
  5. Please, familiarize yourself with the code that is already there. Pay special attention to how it is divided into separate structures.
  6. Read Chapter 1 of the textbook, Andrew Appel's "Modern Compiler Implementation in ML," particularly pages 7-12.
  7. Edit maxarg.sml and interp.sml (described in the text) until they do something useful.
  8. You may find the ML Basis documentation handy.
  9. Run sml.
  10. Inside the running ML session invoke CM.make(); to compile your code.
  11. Observe the compiler's messages and fix the problems that are reported. It may be a good idea to have the ML session in a separate xterm window. 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.
  12. Test your code by invoking Test.maxarg(); and Test.interp(); (still within the running ML session).
  13. If your code still does not work as intended, then debug, recompile, rerun. Repeat as necessary.
  14. Submit by submit 1 maxarg.sml interp.sml.
  15. 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 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).