unsw.cse.framescript
Class Term

java.lang.Object
  extended by unsw.cse.framescript.Term
Direct Known Subclasses:
Alternatives, Atom, Compound, Domain, ExprList, Frame, FSList, FSNumber, FSString, Pattern, RDR, Sequence, Subr, Variable

public abstract class Term
extends java.lang.Object

This abstract class provides a list of methods and default implemetations that all types available in FrameScript require.

Author:
mmcgill

Constructor Summary
Term()
           
 
Method Summary
 Term assign(Instance currentObject, Term arg, StackFrame frame)
          Assigns a value to a Term.
 java.lang.String asString(int indentLevel, boolean inPattern)
          Turns the Term into a string.
abstract  boolean equals(Term t)
          Compares two Terms for equality.
abstract  Term eval(Instance currentObject, StackFrame frame)
          Evaluates a Term.
 boolean fullMatch(unsw.cse.framescript.InputPattern input, Instance current, StackFrame frame)
          Matches the Term to the current position in an input pattern.
static java.lang.String indents(int level)
          Privides a standard method for generating indentation.
 Term mapVars(FSList vars)
          Maps atoms to variables from the list of variables.
 boolean match(unsw.cse.framescript.InputPattern input, Instance current, StackFrame frame)
          Matches the Term to the current position in an input pattern.
abstract  java.lang.String toString()
          Turns the Term into a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Term

public Term()
Method Detail

eval

public abstract Term eval(Instance currentObject,
                          StackFrame frame)
                   throws FSException
Evaluates a Term. For many Terms the result is to return itself.

Parameters:
currentObject - the enclosing instance frame for the code being evaluated
frame - StackFrame that holds the values for any variables
Returns:
the result of the evaluation
Throws:
FSException - if any errors occur in performing the evaluation

assign

public Term assign(Instance currentObject,
                   Term arg,
                   StackFrame frame)
            throws FSException
Assigns a value to a Term. Most Terms cannot be assigned values so the default is to throw an error.

Parameters:
currentObject - the enclosing instance frame for the code being evaluated that is performing the assignment
arg - the unevaluated value to be assigned to the Term
frame - StackFrame that holds the values for any variables
Returns:
the valuse assigned to the Term
Throws:
FSException - if assignment cannot be performed

mapVars

public Term mapVars(FSList vars)
             throws SyntaxError
Maps atoms to variables from the list of variables.

Parameters:
vars - a list of variables to be mapped
Returns:
a clone of the Term where all the variables have been mapped
Throws:
SyntaxError - if in performing the mapping it finds an invalid variable name

equals

public abstract boolean equals(Term t)
Compares two Terms for equality.

Parameters:
t - Term to be compared to
Returns:
true if the Terms are equal, false otherwise

match

public boolean match(unsw.cse.framescript.InputPattern input,
                     Instance current,
                     StackFrame frame)
              throws FSException
Matches the Term to the current position in an input pattern.

Parameters:
input - the input the Term is being matched against
current - the enclosing instance frame for the code being evaluated
frame - StackFrame that holds the values for any variables
Returns:
true if it matches else false
Throws:
FSException - if any errors occur during the match process

fullMatch

public boolean fullMatch(unsw.cse.framescript.InputPattern input,
                         Instance current,
                         StackFrame frame)
                  throws FSException
Matches the Term to the current position in an input pattern.

Parameters:
input - the input the Term is being matched against
current - the enclosing instance frame for the code being evaluated
frame - StackFrame that holds the values for any variables
Returns:
true if it matches else false
Throws:
FSException - if any errors occur during the match process

toString

public abstract java.lang.String toString()
Turns the Term into a string.

Overrides:
toString in class java.lang.Object

asString

public java.lang.String asString(int indentLevel,
                                 boolean inPattern)
Turns the Term into a string.

Parameters:
indentLevel - indentation level to uses for any subsequent lines in the string
inPattern - whether or not to format the string as though it is inside a pattern
Returns:
a string representing the Term

indents

public static java.lang.String indents(int level)
Privides a standard method for generating indentation.

Parameters:
level - number of indents to generate
Returns:
the leading indentation for a line