COS 320, Spring 2000. Programming Assignment

Programming Assignment 1: Interpreter

Described in Modern Compiler Implementation, Chapter 1.

Getting started with ML

  1. Use CIT Sparc machines (CS 101 cluster, sunlab1-sunlab4, yuma, tucson, flagstaff). 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/cs320/ml.
  3. Make a new directory as1 for this assignment.
  4. Copy the files /u/cos320/chap1/*.sml and /u/cos320/chap1/*.cm 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. Edit maxarg.sml and interp.sml until they do something useful.
  7. You may find the ML Basis documentation handy.
  8. Run sml.
  9. Inside the running ML session invoke CM.make(); to compile your code.
  10. 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.
  11. Test your code by invoking Test.maxarg(); and Test.interp(); (still within the running ML session).
  12. If your code still does not work as intended, then debug, recompile, rerun. Repeat as necessary.
  13. Submit by submit 1 maxarg.sml interp.sml.
  14. 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.