Building Parsers with Java

sjm.engine
Class Evaluation

java.lang.Object
  |
  +--sjm.engine.Structure
        |
        +--sjm.engine.Gateway
              |
              +--sjm.engine.Evaluation

public class Evaluation
extends Gateway

An Evaluation unifies a term with the value of another term.

For example,

     NumberFact two = new NumberFact(2);
     ArithmeticOperator x, y;
     x = new ArithmeticOperator('*', two, two);
     y = new ArithmeticOperator('+', x, two);
     
     Variable result = new Variable("Result");
     Evaluation e = new Evaluation(result, y);
     System.out.println(e);
     System.out.println(e.canFindNextProof());
     System.out.println(result);
     
 
prints out:
     #(Result, +(*(2.0, 2.0), 2.0))
     true
     6.0
 

Since an Evaluation unifies the first term with the arithmetic value, the second term may have a value before the Evaluation proves itself. In this case, the Evaluation checks that the second term's ground value equals the arithmetic value of the first term.

The Evaluation fails if the arithmetic value is invalid for any reason.


Field Summary
protected  Unification currentUnification
           
 
Fields inherited from class sjm.engine.Gateway
open
 
Fields inherited from class sjm.engine.Structure
emptyList, functor, terms
 
Constructor Summary
Evaluation(Term term0, Term term1)
          Constructs an Evaluation that will unify the first term with the second term during proofs.
 
Method Summary
 boolean canProveOnce()
          Returns true if this Evaluation can unify its first term with the value of its second term.
protected  void cleanup()
          Insert the method's description here.
 Term copyForProof(AxiomSource ignored, Scope scope)
          Create a copy that uses the provided scope.
 void unbind()
          Releases the variable bindings that the last unification produced.
 
Methods inherited from class sjm.engine.Gateway
canFindNextProof
 
Methods inherited from class sjm.engine.Structure
arity, equals, eval, functorAndArityEquals, headAndTail, isList, list, list, list, listTailString, listTermsToString, terms, toString, unify, unify, unify, variables
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

currentUnification

protected Unification currentUnification
Constructor Detail

Evaluation

public Evaluation(Term term0,
                  Term term1)
Constructs an Evaluation that will unify the first term with the second term during proofs.
Parameters:
Term - the first term to unify
Term - the term whose value should unify with the first term
Method Detail

canProveOnce

public boolean canProveOnce()
Returns true if this Evaluation can unify its first term with the value of its second term.

If the attempt to evaluate the second term causes an exception, this method swallows it and simply fails.

Overrides:
canProveOnce in class Gateway
Returns:
true<, if this Evaluation can unify its first term with the arithmetic value of its second term

cleanup

protected void cleanup()
Description copied from class: Gateway
Insert the method's description here. Creation date: (12/7/99 11:09:44 AM)
Overrides:
cleanup in class Gateway

copyForProof

public Term copyForProof(AxiomSource ignored,
                         Scope scope)
Create a copy that uses the provided scope.
Overrides:
copyForProof in class Structure
Parameters:
AxiomSource - ignored
Scope - the scope to use for variables in the copy
Returns:
a copy that uses the provided scope

unbind

public void unbind()
Releases the variable bindings that the last unification produced.

by Steve Metsker