org.hccp.lisp
Class Interpreter

java.lang.Object
  |
  +--org.hccp.lisp.Interpreter
Direct Known Subclasses:
TestInterpreter

public class Interpreter
extends java.lang.Object

The interpreter takes a java.util.List of Java objects, usually generated from a text file or stream by a Parserand "compiles" them into evaluable Sexp expressions. It then the evaluates the expressions and returns an ordered collection of the resulting objects. For instance, if the following Lisp expressions are passed to the interpreter (by file reference or by input stream):

(= 5 5)

(IF
   (= 4 2)
       (* 3 4)
       (+ 5 2)
)
 
one would expect to get back a list containing, in order, a Boolean.TRUE and a Double with the value 7.0.

See Also:
Parser

Constructor Summary
Interpreter()
           
Interpreter(java.util.Map env)
           
 
Method Summary
 org.hccp.lisp.Sexp compile(java.util.List l, java.util.Iterator itr)
           
 org.hccp.lisp.Sexp compile(java.lang.Object o, java.util.Iterator itr)
          the "compile" methods convert Strings, Doubles, and Lists to their Sexp equivalents.
 org.hccp.lisp.Sexp createLiteral(java.lang.Object o)
           
static void display(java.util.List l)
          Prints out a list of lists.
 java.util.List interpret(java.util.List list)
           
 boolean isDefun(java.util.List l)
          Checks to see if list starts with "DEFUN"
 boolean isFunction(java.util.List list)
          Determines if List is a function.
static void main(java.lang.String[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Interpreter

public Interpreter()

Interpreter

public Interpreter(java.util.Map env)
Method Detail

main

public static void main(java.lang.String[] args)

interpret

public java.util.List interpret(java.util.List list)
                         throws IllegalArgumentException
Parameters:
list - a collection of objects that are reducible to some implementation of Sexp.
Returns:
an ordered list of the values resulting from the evaluation of the "compiled" Sexp objects.
Throws:
IllegalArgumentException - thrown if the Interpreter cannot resolve argument list into Sexp objects.

compile

public org.hccp.lisp.Sexp compile(java.lang.Object o,
                                  java.util.Iterator itr)
                           throws IllegalArgumentException
the "compile" methods convert Strings, Doubles, and Lists to their Sexp equivalents.

Parameters:
o - object to convert to Sexp
Returns:
Throws:
IllegalArgumentException

compile

public org.hccp.lisp.Sexp compile(java.util.List l,
                                  java.util.Iterator itr)
                           throws IllegalArgumentException
Parameters:
l - list to convert to Sexp
Returns:
Throws:
IllegalArgumentException

isFunction

public boolean isFunction(java.util.List list)
Determines if List is a function.

Parameters:
list -
Returns:

isDefun

public boolean isDefun(java.util.List l)
Checks to see if list starts with "DEFUN"

Parameters:
l -
Returns:

display

public static void display(java.util.List l)
Prints out a list of lists.

Parameters:
l -

createLiteral

public org.hccp.lisp.Sexp createLiteral(java.lang.Object o)