directory: eval 4:26PM 11/13/95 This directory contains files that define symbolic expressions, their I/O, and an evaluator for them (a simple read-eval-print loop called rep). The exercises using these files (and calling for students to create some of them) are intended to provide practice in reusing components through both inheritance by derived types, and extension of capabilities through (generic) child packages. Caveat Emptor: These files work correctly when used correctly, however, they are not robust. The exception handling is minimal, and it is easy to break the interpreter by providing inappropriate input. Generic files: These include the generic list and stack and hashtable packages. The list package is the most general, and is used as a parent for the implementation of stacks, as well as "with"d in the definition of hashtables as they are used to implement buckets. list.ads define a generic (by element type) list package, list.adb providing constructors, selectors, testers, and mutators for an exported type Pointer liststac.ads define a generic child package of list, list.stacks, liststac.adb that implements unbounded stacks as linked lists, exports type Stack (which is derived from Pointer) and primitives for stacks. hashtabl.ads define a generic hashtable package, with parameters hashtabl.adb specifying the type of the Key, the type of the Contents, the number of buckets, a hashfunction, and put procedures for the key and contents types. This package with's the list package and exports a type Table. Symbolic expressions: The following files define the ADT "symbolic expressions" and primitive I/O operations for expressions (get and put). There is no scanner, so spaces must be used to separate all tokens in an input expression. Expressions can be: integers 23 no more than 8 digits variables varx no more than 8 alpha characters definitions ( define x exp ) x is any variable, exp is any expression assignments ( set x exp ) x is any variable, exp is any expression functions ( function ( var1 param2 ) bodyexp ) bodyexp is any expression var1 & param2 are variables, formal parameters (of course there can be any number of them) sequences ( seq exp1 exp2 exp3 ) exp1, exp2, exp3 are any expressions applications ( fname exp1 exp2 ) fname must be any variable with function value (no anonymous functions can be applied) exp1 and exp2 are any expressions (of course the number of actuals should match the number of formals for fname) the words: "define," "set", "function", and "seq" are reserved. Functions can take any number of parameters, and be called with the appropriate number of arguments. Sequences may consist of any number of expressions. The files: expr.ads define the package expr, which provides a type Exp, for expr.adb symbolic expressions, and Symbol, SymbolList, and ExpList. They provide constructors, selectors, and testers for Exp and its subtypes. With's list. int_io.ads instantiates text_io.integer_io for type Integer. With's text_io. expr-io.ads define the child package expr.io that provides Put and Get expr-io.adb on types Exp and Symbol. With's text_io and int_io (an instantiation of text_io.integer_io for Integer. Evaluation environments: These files contain the packages that define evaluation environments as stacks of frames, each frame is a table with key type Symbol (from expr) and contents type Exp (from expr). The files are: hash21.adb dummy hash function (returns 1 regardless of argument). With's expr (for the type Symbol, the argument to the hash). frame instantiates hashtable to create a symbol table for symbols and expressions as defined by types Symbol and Exp in package expr. With's expr.io (for access to Symbol and Exp defined in expr, and put's on Symbol and Exp defined in expr.io), hashtable (in order to instantiate it), and hash21 (the dummy hash function). framelis.ads instantiates list with frame defining package framelist. With's list and frame. framstac.ads defines the package framelist.stacks, which is an instantiation of framelist.stacks. (When I attempted to name this instantiation StackOfFrames, I found that the gnat compiler lost track of its parentage. That is, I did not have visibility of framelist, and the generics from which it came: list.stacks, and list. The name of the package SHOULD not matter, and may not matter in newer versions of gnat.) With's framelist and list.stacks. evalenv.ads define Env as a stack of frames and add several evalenv.adb primitives needed for evaluation environments. With's framelist.stacks, expr.io, and Frame. Evaluation of expressions: These files contain the packages that define evaluation of the symbolic expressions defined in the package expr. A simple read-eval-print loop is provided, as procedure Rep, which can take input from a file or work interactively. The files are: evaluate.ads define eval and apply procedures for interpreting evaluate.adb expressions, as well as a driver which implements a read-eval-print cycle until an "exit" or "done" expression is typed. With's the packages text_io, expr.io, and evalenv. The specification with's expr, but not expr.io. rep.adb defines a procedure Rep, which asks the user whether input should be taken from a file (and if so, requests the filename and another filename for output). The sample input file exps.in is provided as example of appropriate input. Rep opens the files if needed and runs the driver defined in Evaluate, then closes any files that it opened. With's packages Evaluate and text_io. exps.in contains some sample expresions to use as a test for the evaluator.