org.omegahat.Environment.Interpreter
Class BasicEvaluator

java.lang.Object
  |
  +--org.omegahat.Environment.Interpreter.BasicEvaluator
All Implemented Interfaces:
DatabaseCustomer, Evaluator, ManagedEvaluatorInt, java.lang.Runnable, java.io.Serializable
Direct Known Subclasses:
UtilityEvaluator

public class BasicEvaluator
extends java.lang.Object
implements DatabaseCustomer, java.io.Serializable, ManagedEvaluatorInt, java.lang.Runnable

The standard low-level evaluator used in the interactive Omegahat language from which most of the others are derived. This controls things such as

Other evaluators provide additional facilities and methods to make them more useful.

See Also:
GUIHelpEvaluator, InteractiveEvaluator, SignallableEvaluator, TaskQueueEvaluator, UserClassEvaluator, TracingEvaluator, UtilityEvaluator, OrbacusEvaluator, Serialized Form

Field Summary
protected  boolean allowUnrestrictedAccess
           
protected  ClassLocatorInt class_lists
           
protected  ExpressionInt currentExpression
          Stores the sub-expression within the expression tree that is currently being evaluated.
protected  java.lang.Object data
          User-specifiable data that can be retrieved by the different expressions as they are evaluated without having to supply the information as an argument.
protected  SearchPath databases
          Ordered container of databases in which omegahat variables are stored and the evaluation of expressions looks for referenced variables.
protected  Debugger debugger
          The object to use for debugging errors as they arise in the evaluation of expressions by this evaluator.
protected  int DefaultAttachIndex
          The default position into which databases are added to the search path.
protected  Database defaultDatabase
           
protected  DynamicClassLoader dynamicClassLoader
           
protected  ErrorHandler errorHandler
           
protected  EvaluationEvent evaluationEvent
           
protected  java.util.Vector evaluationListeners
          Container for the listeners to be notified of the start of a new evaluation.
protected static boolean initialized
           
protected  OrderedTable internalFunctionTables
          Collection of elements in which we search for methods when a function-like (that is, an unqualified call or one prefixed with this) is evaluated and no corresponding function or method is found.
static java.lang.String[] internalPrimitiveClassNames
           
static java.util.Hashtable internalPrimitiveClassTable
           
protected  antlr.Tokenizer lexer
           
protected  LocalClassLocator localClasses
           
protected  EvaluatorManager manager
           
protected  Options options
          Container for the options governing the creation and run-time behavior of this evaluator and associated objects.
protected  ObjectDisplayFilter output
           
protected  omegaJavaGrammar parser
           
static java.lang.Class[] primitive_classes
          The classes representing the primtive types in Java
static java.util.Hashtable primitiveClasses
           
static java.lang.String[] PrimitiveClassNames
          Then names of the different classes that mirror the primitives
static java.lang.String[] primitiveTypeNames
          The names of the different primitive entitites in Java.
static java.util.Hashtable primitiveTypes
           
static java.util.Hashtable reversePrimitiveTypes
           
static boolean ShowMultipleClasses
          Controls whether to search for multiple classes when resolving a partially qualified class name.
protected  java.util.Stack sourceStack
           
protected  java.io.PrintWriter stderr
           
protected  java.io.PrintWriter stdout
           
protected  java.util.Vector SubEvaluationListeners
          Container for listeners to be notified of all evaluation events , including all sub-expression being evaluated.
protected  java.util.Vector taskHistory
           
protected  ExpressionInt toplevelExpression
          Stores the currently active top-level task expression being evaluated.
protected  java.util.Vector warningMessages
           
 
Fields inherited from interface org.omegahat.Environment.Interpreter.Evaluator
ThisVariableName
 
Constructor Summary
  BasicEvaluator()
          Default constructor which uses the default options (usually read from the file OmegaOptions).
protected BasicEvaluator(Evaluator ev)
          Creates an evaluator using the characteristics of the specified "parent" evaluator.
  BasicEvaluator(EvaluatorManager mgr)
          Creates an evaluator by attempting to copy the options from the default Evaluator available from the EvaluatorManager, and registers itself with that manager.
  BasicEvaluator(Options opts)
          Creates the evaluator with a reference to a collection of options controlling its characteristics.
 
Method Summary
 int addEvaluationListener(EvaluationListener l)
          Register a listener to be notified of the different evaluation events, such as the start and completion of a top-level evaluation, of starting the evaluation of a node in the parse tree, an error, etc.
 int addFunctionTable(java.lang.Object source)
          Register an object or class as a potential source of function-like methods that can be called from unqualified function-like calls.
 int addFunctionTable(java.lang.Object source, java.lang.String name)
           
 boolean addMethod(Method method, Name name)
           
 java.lang.Object addSourceInput(java.lang.Object description)
           
 Task addToHistory(java.lang.Object expr, java.lang.Object obj, java.lang.String command)
           
 boolean allowUnrestrictedAccess()
          Indicate whether access to methods and fields that are not usually accessible (non-public classes and/or methods and fields) are tolerated.
 boolean allowUnrestrictedAccess(boolean val)
           
 java.lang.Object asObject(Name name)
           
 java.lang.Object asObject(Name name, int max_num_components)
           
 java.lang.Object asObject(Name name, int max_num_components, boolean getClass)
          Resolves the object in the evaluation model identified by the first max_num_components elements of the name argument.
 java.lang.String asObjectName(Name name)
           
 java.lang.Class asPrimitiveClass(java.lang.String name)
          Return the primitive class (that is, double, int, etc.) corresponding the specified string of the form "double", etc.
 boolean assign(java.lang.String name, java.lang.Object obj)
          Assign the value to the specified variable name in the default database.
 boolean assign(java.lang.String name, java.lang.Object obj, Database db)
          Bind the value of obj to the variable called name in the specified databases.
 boolean assign(java.lang.String name, java.lang.Object obj, int which)
          Assign the value of the object to the specified variable name in the database identified by the index in the search path.
 java.io.PrintWriter asWriter(java.io.OutputStream str)
          Converts an OutputStream to a writer object that we can use println()
 AttachedDatabase attach(Database db)
          Add the specified database to the evaluator's search path using the default attachment position which is governed by
 AttachedDatabase attach(Database db, int idx)
          Attach the given database at the specified position in the evaluator's search path.
 AttachedDatabase attach(java.io.File name)
          Construct a database associated with the given file and attach it to the search path.
 AttachedDatabase attach(java.io.File name, int idx)
          Constructs a databases associated with the file (either a previously serialized database or a directory containing objects) and attach it to the search path in the specified position.
 AttachedDatabase attach(java.lang.String name)
          Creates and attaches a new database (of the default class) into the search path at the default position, specified by the value
 AttachedDatabase attach(java.lang.String name, int idx)
          Create a database using the default class and give it the specified name and attach it a the position idx in the search path.
 AttachedDatabase attach(java.net.URL u)
          Intended to attach the URL which is a jar or zip file as a database.
protected static java.util.Hashtable classInit()
           
 ClassLocatorInt classLists()
           
protected  ClassLocatorInt classLists(ClassLocatorInt tb)
           
 java.util.Vector classPath()
          Compute the classpath for the application.
 java.util.Vector classPath(java.lang.String path)
           
 java.lang.String[] commandLine()
           
 java.lang.Object convertPrimitive(java.lang.Object value, java.lang.Class target)
          Convert an object to a primitive object such as an Integer to a Double or vice-versa.
 java.lang.Object copy(java.lang.Object o)
          Attempts to obtain a copy of the object by calling a constructor for that class that takes an object of the same class, or if that fails serializing the object and reading it back.
 java.lang.Object copy(java.lang.Object o, boolean deep)
           
 java.lang.Object copyByConstructor(java.lang.Object o, boolean deep)
          Attempts to "copy" the specified object by invoking a constructor in the class of the argument that takes a single argument of the same class.
 java.lang.Object copyBySerialization(java.lang.Object o)
          Perform a deep copy of the specified object by serializing its contents and reading them back.
 ClassLocatorInt createClassLists()
           
 ExpressionInt currentExpression()
          Returns the currently active sub-expression that is being evaluated as part of the active task.
 ExpressionInt currentExpression(ExpressionInt e)
          Sets the currently active sub-expression being evaluated at this moment.
 java.lang.Object data()
          Retrieve the user-level data.
 java.lang.Object data(java.lang.Object val)
          Set the user-level data.
 Database database()
           
 Database database(int index)
           
 Database database(java.lang.String name)
           
 boolean Debug()
           
 boolean Debug(boolean v)
           
 boolean Debug(java.lang.Boolean v)
           
 boolean Debug(java.lang.Object o)
           
 boolean Debug(java.lang.String val)
           
 Debugger debugger()
          Return the debugger object being used by this evaluator.
 Debugger debugger(Debugger d)
          Set the default debugger instance to be used by this evaluator.
 Database defaultDatabase()
          Retrieve the database into which assignments are made by default (i.e.
 Database defaultDatabase(boolean force)
          Get the default database to which assignments will be made.
 Database defaultDatabase(Database db)
          Set the database to which assignments are made by default.
 ErrorHandler defaultErrorHandler()
           
 int detach(Database db)
          Remove the specified database from the search path.
 int detach(int which)
          Remove the database in the specified position of the searchpath.
 boolean displayTask(java.lang.Object parsed_tree, java.lang.Object result, java.lang.String input)
           
 boolean displayTask(Task task)
           
 int displayWarnings()
           
 int displayWarnings(int n)
           
 DynamicClassLoader dynamicClassLoader()
           
 DynamicClassLoader dynamicClassLoader(DynamicClassLoader loader)
           
 void endSource()
           
 void endSource(java.lang.String msg)
           
 void endSource(java.lang.String msg, boolean silent)
           
 void endTaskEvaluation(ExpressionInt expr)
          Method called when a top-level task has been completed.
 java.lang.Exception error(java.lang.String msg)
          Signal an error, using the error message to indicate why.
 java.lang.Exception error(java.lang.Throwable e, java.lang.String msg)
          Raise an error based on the exception that was caught during the evaluation of the current top-level task.
 ErrorHandler errorHandler()
           
 ErrorHandler errorHandler(ErrorHandler e)
           
 java.lang.Object evaluate(ExpressionInt expr)
          Evaluate a top-level expression, notifying listeners when it has started and finished and displaying any warnings that arise.
 java.lang.Object evaluate(java.lang.Object expr, java.lang.String input)
           
 java.lang.Object evaluate(java.lang.String input)
           
 java.lang.Object evaluate(Task task)
          Evaluate a top-level task expression, storing the result in the Task object.
 boolean evaluationError(java.lang.Throwable e)
          Handle errors during a top-level task evaluation by handing it to the registered debugger, if one exists, or using the default error handler.
 java.util.Vector evaluationListeners()
          Returns the collection of registered listeners and initializes the Vector if it has not been previously created.
 java.util.Vector evaluationListeners(boolean force)
          Return the collection of current evaluation listeners or the container
 java.util.Vector evaluationListeners(java.util.Vector v)
          Sets the (potentially empty) container for the listener objects which are notified This is usually called with an empty, but initialized Vector object when it is needed, e.g.
 boolean exists(java.lang.String name)
          Determines whether a variable with the specified name exists in any of the databases in the search path.
 void exit()
          Default exit.
 void exit(int val)
          Terminate the session as quickly as possibly
 java.lang.String expandClassName(java.lang.String name)
           
 java.lang.String expandedClassPathElement(java.lang.String el, java.lang.Object base)
          Used when constructing the classpath elements, specifically when running via the java -jar option.
protected  Database[] find(java.lang.String name, boolean all)
           
 java.lang.Object findAsField(Name name, int max_num_components, boolean getClass)
           
 java.lang.Class findClass(Name name)
          Find the Class object corresponding to a multi-component Name object.
 java.lang.Class findClass(java.lang.String name)
          Locate a Class object with the given name, using incomplete matching such as Vector or util.Vector to resolve Vector.
 java.lang.Class findClass(java.lang.String name, boolean internalPrimitives)
          Primarily used for the dynamic compiler to allow for lookup up primitive classes by their internal names.
 java.lang.Class findClass(java.lang.String name, int error)
          Version of findClass that is used for interactive use where we don't want to put a try-catch clause around this but we don't want to get errors when the class is not found.
 Function findFunction(java.lang.String name)
           
 Evaluable findFunctionOrMethod(java.lang.String name)
           
 OrderedTable functionTableList()
          Retrieve the collection of objects in which we can potentially find internal function-like methods.
 java.lang.Object get(Name name)
           
 java.lang.Object get(NameTypeSearchFilter filter)
           
 java.lang.Object get(java.lang.String name)
           
 java.lang.Object get(java.lang.String name, boolean evaluate)
           
 java.lang.Object get(java.lang.String name, boolean evaluate, boolean strip)
           
 java.lang.Object get(java.lang.String name, java.lang.Class type)
           
 java.lang.Object get(java.lang.String name, java.lang.Class type, boolean strict)
          Searches for an object named @name which is an instance of the class specified by the argument @type.
 java.lang.Object get(java.lang.String name, java.lang.String type)
          This is a convenience function that calls get(String,Class,boolean).
 java.lang.Object get(java.lang.String name, java.lang.String type, boolean strict)
           
 java.lang.Object getBaseURL(java.lang.String el)
          Computes the parent of a file or URL object.
 EvaluationEvent getEvaluationEvent()
          Accessor for evaluationEvent field
 java.util.Vector getEvaluationListeners()
          Accessor for evaluationListeners field
 java.lang.Object getField(java.lang.String name, java.lang.Object obj, boolean getClass)
           
 java.util.Vector getSubEvaluationListeners()
          Accessor for SubEvaluationListeners field
 java.lang.Object help()
          Creates the default help system.
 ClassList Import(java.io.File f)
           
 ClassList Import(Name n)
          Creates a ClassList of the appropriate type for the sub-directory specified in the argument n
 ClassList Import(java.net.URL u)
           
 void init()
          Initializes this object so that it can be used to evaluate expressions.
 boolean initialize(Evaluator ev)
          Initializes this evaluator by copying/referencing the different components of the parent evaluator.
 void initTaskEvaluation(ExpressionInt expr)
          Method called when a new task expression is just about to be evaluated.
protected  OrderedTable internalFunctionTables(OrderedTable list)
          Internal method for controlling the list of sources in which we look for function-like methods.
static boolean isPrimitive(java.lang.Class c)
           
static boolean isPrimitive(java.lang.Object o)
           
 int javaVersion()
           
 antlr.Tokenizer lexer()
           
 antlr.Tokenizer lexer(java.io.Reader reader)
           
 antlr.Tokenizer lexer(antlr.Tokenizer lex)
           
 LocalClassLocator localClasses()
          the object that determines what classes the evaluator can locate.
 LocalClassLocator localClasses(LocalClassLocator l)
           
 EvaluatorManager manager()
          Retrieve the manager under whose nominal control the object is.
 EvaluatorManager manager(EvaluatorManager m)
          Set the manager which "controls" this object.
 Database newDatabase()
           
 Database newDatabase(java.lang.String name)
           
 int notifyListeners(ExpressionInt e)
          Notify the listeners that the given sub-expression is about to be evaluated.
 int notifyListeners(ExpressionInt e, boolean task)
          Notify the evaluation listeners that the given expression is about to be evaluated as a top-level task or as a sub-expression, depending on whether task is true or false.
 java.lang.String[] objects()
           
 java.lang.String[] objects(Database db)
           
 java.lang.String[] objects(int index)
           
 Options options()
          Get the current Options object in effect for this evaluator.
 Options options(Options opts)
          Set the Options object for the evaluator.
 ObjectDisplayFilter output()
           
 ObjectDisplayFilter output(boolean force)
           
 ObjectDisplayFilter output(ObjectDisplayFilter src)
           
 ExpressionInt parse(omegaJavaGrammar parser)
           
 ExpressionInt parse(java.io.Reader reader)
          Parse the contents of the text available on the specified reader.
 ExpressionInt parse(java.lang.String input)
           
 ExpressionInt parse(antlr.Tokenizer lexer)
           
 omegaJavaGrammar parser(antlr.Tokenizer lexer)
           
static java.lang.Class primitiveClass(java.lang.Object o)
           
 boolean q()
           
 boolean q(boolean force)
           
 boolean remove(java.lang.String name)
          Discards the variable identified by name in the first database containing such a variable.
 boolean remove(java.lang.String name, Database db)
          Discards the specified variable in the particular database.
 boolean remove(java.lang.String name, int which)
          Remove the specified variable (identified by name) in the database identified by the index in the search path.
 boolean removeFunctionTable(java.lang.Object o)
          Remove a previously registered object that is considered as a potential source of function-like methods available to the scripting language with an `unqualified' call.
 void run()
          Basic method that allows this evaluator to be run in a thread.
 boolean same(java.lang.Object x, java.lang.Object y)
          Utility method for comparing two objects by reference.
 java.lang.Class searchForClass(java.lang.String name)
           
 SearchPath searchPath()
           
 SearchPath searchPath(SearchPath dbs)
           
 SearchPath searchPath(SearchPath dbs, boolean copy)
           
 SearchPath searchPath(java.util.Vector dbs)
           
 EvaluationEvent setEvaluationEvent(EvaluationEvent value)
          Accessor for setting evaluationEvent field
 java.util.Vector setEvaluationListeners(java.util.Vector value)
          Accessor for setting evaluationListeners field
 java.util.Vector setSubEvaluationListeners(java.util.Vector value)
          Accessor for setting SubEvaluationListeners field
 java.lang.Object show()
          Print a new line.
 java.lang.Object show(java.lang.Object obj)
           
 java.lang.Object show(java.lang.Object obj, boolean newline)
           
 java.lang.Object source(ArchiveEntry entry)
           
 java.lang.Object source(java.io.File f)
          Evaluate the contents of the specified file.
 java.lang.Object source(InputFileInt f)
          Evaluate the contents of the specified "file" (regular file or jar entry) as Omegahat commands.
 java.lang.Object source(java.lang.Object obj)
          Read evaluable input from an arbitrary object in a manner suitable for its class (including throwing an exception).
 java.lang.Object source(java.io.Reader reader)
           
 java.lang.Object source(java.io.Reader reader, java.lang.Object desc)
           
 java.lang.Object source(java.lang.String text)
          Read and evaluate input from a string, by attempting to treat it as a URL, a File and then an expression.
 java.lang.Object source(java.lang.String text, boolean asText)
           
 java.lang.Object source(java.net.URL u)
          Parse contents of URL.
 java.util.Stack sourceStack()
          Retrieve the stack detailing the ordered list of input sources currently active.
 java.io.PrintWriter stderr()
          Return the current error output device.
 java.io.PrintWriter stderr(java.io.OutputStream str)
           
 java.io.PrintWriter stdout()
          Return the current output device.
 java.io.PrintWriter stdout(java.io.OutputStream str)
           
 java.util.Vector taskHistory()
           
 java.util.Vector taskHistory(java.util.Vector v)
           
 ExpressionInt toplevelExpression()
          Returns the currently active top-level task expression.
 ExpressionInt toplevelExpression(ExpressionInt e)
          Sets the currently active top-level task expression.
 boolean useLazyEvaluation()
           
 void warning(java.lang.String msg)
          Register the specified warning message to be displayed at a suitable time, usually when the active task has been completed.
 void warning(java.lang.String msg, boolean immediate)
           
 void warning(java.lang.Throwable e, java.lang.String msg)
          Issue a warning about the exception that was caught at some point in the evaluation of the current task.
 java.util.Vector warnings()
           
 java.util.Vector warnings(java.util.Vector v)
           
 Database[] where(java.lang.String name)
           
 Database which(Name name)
           
 Database which(java.lang.String name)
          Identifies the first database in the evaluator's search path in which a variable with this name can be found
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

primitive_classes

public static final java.lang.Class[] primitive_classes
The classes representing the primtive types in Java

primitiveTypeNames

public static final java.lang.String[] primitiveTypeNames
The names of the different primitive entitites in Java.

PrimitiveClassNames

public static final java.lang.String[] PrimitiveClassNames
Then names of the different classes that mirror the primitives

internalPrimitiveClassNames

public static final java.lang.String[] internalPrimitiveClassNames

ShowMultipleClasses

public static boolean ShowMultipleClasses
Controls whether to search for multiple classes when resolving a partially qualified class name. This could be made evaluator-instance specific.
See Also:
findClass(java.lang.String), #findClasses(java.lang.String)

initialized

protected static boolean initialized

primitiveClasses

public static java.util.Hashtable primitiveClasses

primitiveTypes

public static java.util.Hashtable primitiveTypes

internalPrimitiveClassTable

public static java.util.Hashtable internalPrimitiveClassTable

reversePrimitiveTypes

public static java.util.Hashtable reversePrimitiveTypes

options

protected Options options
Container for the options governing the creation and run-time behavior of this evaluator and associated objects. This contains information such as the name of the default database class, the prompt, etc.

databases

protected SearchPath databases
Ordered container of databases in which omegahat variables are stored and the evaluation of expressions looks for referenced variables. The elements are arbitrary objects that implement the Database interface.

data

protected java.lang.Object data
User-specifiable data that can be retrieved by the different expressions as they are evaluated without having to supply the information as an argument. This is a short-cut for augmenting the information available to the expression objects without having to extend them, the parser or the evaluator class.

DefaultAttachIndex

protected int DefaultAttachIndex
The default position into which databases are added to the search path. This controls how variables are found in newly attached databases.

toplevelExpression

protected ExpressionInt toplevelExpression
Stores the currently active top-level task expression being evaluated.

lexer

protected antlr.Tokenizer lexer

parser

protected omegaJavaGrammar parser

output

protected ObjectDisplayFilter output

taskHistory

protected java.util.Vector taskHistory

defaultDatabase

protected Database defaultDatabase

errorHandler

protected ErrorHandler errorHandler

warningMessages

protected java.util.Vector warningMessages

class_lists

protected ClassLocatorInt class_lists

localClasses

protected LocalClassLocator localClasses

dynamicClassLoader

protected DynamicClassLoader dynamicClassLoader

manager

protected EvaluatorManager manager

stderr

protected java.io.PrintWriter stderr

stdout

protected java.io.PrintWriter stdout

currentExpression

protected ExpressionInt currentExpression
Stores the sub-expression within the expression tree that is currently being evaluated.

debugger

protected Debugger debugger
The object to use for debugging errors as they arise in the evaluation of expressions by this evaluator.

evaluationListeners

protected java.util.Vector evaluationListeners
Container for the listeners to be notified of the start of a new evaluation.

SubEvaluationListeners

protected java.util.Vector SubEvaluationListeners
Container for listeners to be notified of all evaluation events , including all sub-expression being evaluated.

evaluationEvent

protected EvaluationEvent evaluationEvent

internalFunctionTables

protected OrderedTable internalFunctionTables
Collection of elements in which we search for methods when a function-like (that is, an unqualified call or one prefixed with this) is evaluated and no corresponding function or method is found.

allowUnrestrictedAccess

protected boolean allowUnrestrictedAccess

sourceStack

protected java.util.Stack sourceStack
Constructor Detail

BasicEvaluator

public BasicEvaluator(Options opts)
Creates the evaluator with a reference to a collection of options controlling its characteristics.

BasicEvaluator

public BasicEvaluator()
Default constructor which uses the default options (usually read from the file OmegaOptions).

BasicEvaluator

public BasicEvaluator(EvaluatorManager mgr)
Creates an evaluator by attempting to copy the options from the default Evaluator available from the EvaluatorManager, and registers itself with that manager.

BasicEvaluator

protected BasicEvaluator(