Assignment 1 (Introduction to SML)


Due Date: April 3, 2000 before class

The goal is to start interacting with the SML/NJ compiler and to use SML to write simple little functions. For help on the SML/NJ system, including the available libraries, consult the following page: The SML/NJ Page.

Here is a grammar for the abstract syntax of some simple arithmetic expressions, specified as a collection of ML datatypes:

(* binary operations *)
datatype BOp = Plus | Minus | Multiply | Divide 

(* unary operations: 
  Inverse is the function that divides 1 by its argument, Inverse 2.0 = 0.5
  Ln is the natural logarithm on your calculator
*)
datatype UOp = Inverse | Square | SquareRoot | Sin | Cos | Tan | Ln 

(* expressions: 
  Pi is the constant 3.1415926...
*)
datatype Expression =
    Pi
  | Number of real
  | Binary of Expression * BOp * Expression
  | Unary of UOp * Expression
Using the grammar, the abstract parse tree for the expression 3+4 is represented in ML as Binary(Number(3.0), Plus, Number(4.0)) :


Page visited times since November 18, 1996.

sabry@cs.uoregon.edu