CS330 Spring 2004 Lecture 8

George Tzanetakis

Slides 

This lecture will not contain any slides as it consists mainly of
programming examples in sml.

SML code

Code in text format

Suggested exercises

8.1)  Make a datatype declaration for abstract syntax trees of arithmetic expressions
with rational numbers. Write a function evaluate that given an abstract syntax tree returns
the result of the evaluating the expression. Declare an SML function with type
rexpr->string which computes the textual, postfix form of expression trees
(similar to assignment 1). You can use Int.toString to convert an integer number
to a string.

8.2) In this exercise we consider symbolic expression built from real
numbers and 'names' using the operators: sign change, sum, difference
and product, and where a name is a character string. A set of bindings
of real values vi to names niis given by a list
[(name1, value1), (name2,value2),.....(namen,valuen)] of pairs.
Declare types for such expressions and bindings, and a function
to compute the value of an expression for a given set of bindings of values
to names. The function should raise an exception if a name occuring
in the expression has no binding to a value.