Class Interpreter

This class represents an interpreter. The interpreter object can be obtained from a knowledge base by the iterable() method. The knowledge base associated with an interpreter can be retrieved and set via the methods getKnowledgebase() and setKnowledgebase().

The knowledge base associated with an interpreter can be retrieved via the method getKnowledgebase(). The controller associated with an interpreter can be retrieved via the method getController(). If multiple interactors are needed a further interpreter object can be forked from an existing interpreter object by the iterable() method. Multiple interactors share the same controller.

To consistently compare variables their serial numbers are used. Serial numbers are allocated and maintained similar to variable bindings in the interpreter. Lexical comparison is therefore defined as a method compare() of the class Interpreter. This method corresponds to the Prolog predicate compare/3. The existence of this method is marked by the implemented interface Comparator.

The interpreter further carries choice points and tail recursion barriers. They are used when solving a goal. An interactor for a solution set can be obtained via the method iterator() methods. The interactor can be controlled via the different methods of the interactor itself. For more details see the CallIn class.

All Prolog flags can be accessed via the methods getProperty() and setProperty(). The set of available Prolog flags depends on the initialized capabilities and on the used toolkit. For properties that represent streams the following Java classes are used:

Table 5: Java Class ISO Stream Mapping
ISO Mode ISO Type Java Class
Read Text Stream Reader
Binary Stream InputStream
Write Text Stream Writer
Binary Stream OutputStream

The toString() methods convert a term to a string. The unparseTerm() methods convert a term to a string or stream. The following flags are recognized. The method with an option term recognizes all options from the write_term/2 predicate. The following flags are available:

    FLAG_QUOTED: Quote atoms when necessary.
    FLAG_NUMBERVARS: Write $VAR(n) as a variable name.
    FLAG_IGNORE_OPS: Ignore operator definitions.
    FLAG_IGNORE_MOD: Ignore module prefixes.

The parseTerm() methods convert a string or stream to a term. The method that takes a string doesn't require that the term is terminated by a period and returns null when an empty string has been supplied. The method with an option term recognizes all options from the read_term/2 predicate and returns null when the option unification fails.

package jekpro.tools.call;

public final class Interpreter implements Comparator<Object> {
public static final int FLAG_QUOTED = 1;
public static final int FLAG_NUMBERVARS = 2;
public static final int FLAG_IGNORE_OPS = 4;
public static final int FLAG_IGNORE_MOD = 8;

public Interpreter(Knowledgebase k, Controller c);

    public Knowledgebase getKnowledgebase();
public void setKnowledgebase(Knowledgebase k);
 public Controller getController();

public Interpreter iterable();
 public CallIn iterator();
 public CallIn iterator(Object goal);

public int compare(Object t1, Object t2)
throws ArithmeticException;

public ArrayList<String> getProperties();
public Object getProperty(String flag);
public void setProperty(String prop, Object val)
throws InterpreterMessage;

public String unparseTerm(AbstractTerm t, Object opt)
throws InterpreterMessage, InterpreterException;
 public void unparseTerm(Writer wr, Object opt, AbstractTerm t)
throws InterpreterMessage, InterpreterException;

public AbstractTerm parseTerm(String s, Object opt)
throws InterpreterMessage, InterpreterException;
public AbstractTerm parseTerm(Reader lr, Object opt)
throws InterpreterException, InterpreterMessage;
}

Comments