ubc.cs.JLog.Parser
Class pPredicateEntry

java.lang.Object
  extended by ubc.cs.JLog.Parser.pPredicateEntry
All Implemented Interfaces:
iName, iNameArity
Direct Known Subclasses:
pAnimatePredicateEntry, pCallPredicateEntry, pDBExecutePredicateEntry, pDBSelectPredicateEntry, pDCGPredicateEntry, pFSisDirPredicateEntry, pFSisFilePredicateEntry, pGenericPredicateEntry, pOrPredicateEntry

public abstract class pPredicateEntry
extends java.lang.Object
implements iNameArity

Abstract base class for entries in the pPredicateRegistry. Each predicate entry subclass represents a type of prolog predicate at the level needed for the parser (they are parse time representations). Predicate entries contain information about the corresponding predicate, such as name and arity. Predicate entries generate the corresponding real Prolog predicate objects.

Author:
Glendon Holst

Field Summary
protected  int arity
           
protected  java.lang.String library
           
protected  java.lang.String name
           
static int NARY_ARITY
           
 
Constructor Summary
pPredicateEntry(java.lang.String name, int arity)
           
 
Method Summary
 iPredicate createPredicate()
          Public interface for generating the real prolog term objects.
abstract  iPredicate createPredicate(jCompoundTerm cterm)
          The internal method for creating the iPredicate representation of this predicate representation.
 iPredicate createPredicate(ubc.cs.JLog.Parser.pToken pt, jCompoundTerm cterm)
          Public interface for generating the real prolog term objects.
 int getArity()
          Returns the arity of this instance.
 java.lang.String getLibrary()
          Get the name of the library associated with this predicate.
 java.lang.String getName()
          Returns the name of this instance.
 boolean isArity(int a)
          Tests the arity of this entry.
 boolean sameLibrary(java.lang.String lib)
           
 void setLibrary(java.lang.String lib)
          Set the name of the library associated with this predicate.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NARY_ARITY

public static final int NARY_ARITY
See Also:
Constant Field Values

name

protected java.lang.String name

arity

protected int arity

library

protected java.lang.String library
Constructor Detail

pPredicateEntry

public pPredicateEntry(java.lang.String name,
                       int arity)
Method Detail

getName

public java.lang.String getName()
Description copied from interface: iName
Returns the name of this instance.

Specified by:
getName in interface iName
Returns:
String containing name of this instance.

getArity

public int getArity()
Description copied from interface: iNameArity
Returns the arity of this instance.

Specified by:
getArity in interface iNameArity
Returns:
int whose value is the arity of this instance.

isArity

public boolean isArity(int a)
Tests the arity of this entry. Most predicates entries will only return true if there is an exact match, however, for n-ary predicates, arity should be set to NARY_ARITY, and isArity should always return true for supported arities.

Parameters:
a - The arity to test this entry for.
Returns:
boolean which is true if entry can be of this arity.

setLibrary

public void setLibrary(java.lang.String lib)
Set the name of the library associated with this predicate. Once an association is made it is an error to change it (throws InvalidLibraryEntryException in this case). Predicates default to a null valued library.

Parameters:
lib - The name of the library.

getLibrary

public java.lang.String getLibrary()
Get the name of the library associated with this predicate.

Returns:
The name of the library. May be null.

sameLibrary

public boolean sameLibrary(java.lang.String lib)

createPredicate

public iPredicate createPredicate(ubc.cs.JLog.Parser.pToken pt,
                                  jCompoundTerm cterm)
Public interface for generating the real prolog term objects. May generate syntax errors. Invokes internal createPredicate to perform actual construction of term.

Parameters:
pt - The parsing token representing the operator. Used for generating information about the location of the operator in the input stream.
cterm - A terms belonging to this predicate.
Returns:
iPredicat representing this predicate and its terms.

createPredicate

public iPredicate createPredicate()
Public interface for generating the real prolog term objects. May generate syntax errors. Invokes internal createPredicate to perform actual construction of term.

Returns:
iPredicat representing this predicate with given arity, with unamed variables for terms.

createPredicate

public abstract iPredicate createPredicate(jCompoundTerm cterm)
The internal method for creating the iPredicate representation of this predicate representation. Subclasses must override. The terms are provided, already created. The caller is responsible to ensure that arity and cterm.size match.

Parameters:
cterm - The collection of jTerms.
Returns:
iPredicate representing this predicate and its terms.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object