ubc.cs.JLog.Parser
Class pOperatorEntry

java.lang.Object
  extended by ubc.cs.JLog.Parser.pOperatorEntry
Direct Known Subclasses:
pCommandOperatorEntry, pConsOperatorEntry, pDCGOperatorEntry, pGenericOperatorEntry, pIfOperatorEntry, pIfThenOperatorEntry, pNotOperatorEntry, pOrOperatorEntry, pPredicateOperatorEntry

public abstract class pOperatorEntry
extends java.lang.Object

Abstract base class for entries in the pOperatorRegistry. Each operator entry subclass represents a type of prolog operator predicate at the level needed for the parser (they are parse time representations). Operator entries contain information about the corresponding operator, such as associativity, precedence, and type. Each instance of the operator entry is bound to parser representations of its operands. Operator entries generate the corresponding real Prolog operator objects and their real Prolog operand jTerms.

Author:
Glendon Holst

Field Summary
static int FX
           
static int FY
           
static int LEFT_ASSOCIATIVE
           
protected  java.lang.String library
           
protected  java.lang.String name
           
static int NON_ASSOCIATIVE
           
protected  int priority
           
static int RIGHT_ASSOCIATIVE
           
protected  int type
           
static int XF
           
static int XFX
           
static int XFY
           
static int YF
           
static int YFX
           
 
Constructor Summary
pOperatorEntry(java.lang.String name, int type, int priority)
           
 
Method Summary
abstract  jTerm createOperator(jTerm l, jTerm r)
          The internal method for creating the jTerm representation of this operator representation.
 jTerm createOperator(ubc.cs.JLog.Parser.pToken pt, ubc.cs.JLog.Parser.pPacket lhs, ubc.cs.JLog.Parser.pPacket rhs, pVariableRegistry vars, pTermToPacketHashtable phash)
          Public interface for generating the real prolog term objects.
 int getAssociativity()
           
 java.lang.String getLibrary()
          Get the name of the library associated with this operator.
 java.lang.String getName()
           
 int getPriority()
           
 int getType()
           
 boolean hasLHS()
           
 boolean hasRHS()
           
 boolean isAtomPermitted()
          Determine if an unbound operator is not an error, or if it could be an atom
 boolean isNonAssociativeLeft()
           
 boolean isNonAssociativeRight()
           
 boolean isValidType()
           
 boolean sameLibrary(java.lang.String lib)
           
 void setLibrary(java.lang.String lib)
          Set the name of the library associated with this operator.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

FX

public static final int FX
See Also:
Constant Field Values

FY

public static final int FY
See Also:
Constant Field Values

XFX

public static final int XFX
See Also:
Constant Field Values

XFY

public static final int XFY
See Also:
Constant Field Values

YFX

public static final int YFX
See Also:
Constant Field Values

XF

public static final int XF
See Also:
Constant Field Values

YF

public static final int YF
See Also:
Constant Field Values

NON_ASSOCIATIVE

public static final int NON_ASSOCIATIVE
See Also:
Constant Field Values

LEFT_ASSOCIATIVE

public static final int LEFT_ASSOCIATIVE
See Also:
Constant Field Values

RIGHT_ASSOCIATIVE

public static final int RIGHT_ASSOCIATIVE
See Also:
Constant Field Values

name

protected java.lang.String name

type

protected int type

priority

protected int priority

library

protected java.lang.String library
Constructor Detail

pOperatorEntry

public pOperatorEntry(java.lang.String name,
                      int type,
                      int priority)
Method Detail

getName

public java.lang.String getName()

hasLHS

public boolean hasLHS()

hasRHS

public boolean hasRHS()

isAtomPermitted

public boolean isAtomPermitted()
Determine if an unbound operator is not an error, or if it could be an atom

Returns:
true if this operator could also be an atom if it is unbound.

getType

public int getType()

getPriority

public int getPriority()

getAssociativity

public int getAssociativity()

isNonAssociativeLeft

public boolean isNonAssociativeLeft()

isNonAssociativeRight

public boolean isNonAssociativeRight()

isValidType

public boolean isValidType()

setLibrary

public void setLibrary(java.lang.String lib)
Set the name of the library associated with this operator. Once an association is made it is an error to change it (throws InvalidLibraryEntryException in this case). Operators 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 operator.

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

sameLibrary

public boolean sameLibrary(java.lang.String lib)

createOperator

public jTerm createOperator(ubc.cs.JLog.Parser.pToken pt,
                            ubc.cs.JLog.Parser.pPacket lhs,
                            ubc.cs.JLog.Parser.pPacket rhs,
                            pVariableRegistry vars,
                            pTermToPacketHashtable phash)
Public interface for generating the real prolog term objects. May generate syntax errors. Invokes internal createOperator 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.
lhs - A parsing packet (possibly null) representing the left operand. Used to generate the left hand jTerm.
rhs - A parsing packet (possibly null) representing the right operand. Used to generate the right hand jTerm.
vars - A registery of named variables (ensures that variables of the same name are the same instance). This should be the variable registry of the rule or command containing this operator.
phash - A registery of terms and their corresponding parsing tokens.
Returns:
jTerm representing this operator and its operands.

createOperator

public abstract jTerm createOperator(jTerm l,
                                     jTerm r)
The internal method for creating the jTerm representation of this operator representation. Subclasses must override. The operands are provided, already created.

Parameters:
l - The left hand jTerm.
r - The right hand jTerm.
Returns:
jTerm representing this operator and its operands.

toString

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