ua.gradsoft.termware.jj
Class NodeTerm

java.lang.Object
  extended by ua.gradsoft.termware.Term
      extended by ua.gradsoft.termware.jj.NodeTerm
All Implemented Interfaces:
Serializable, Cloneable, Attributed, INode

public class NodeTerm
extends Term
implements INode, Attributed

Term which can be instance of JJTree node. If you want to use this term, you must define own SimpleNode interface as extension of NodeTerm and delegate all work in jjt* methods in SimpleNode to appropriative jjt*Internal methods of NodeTerm.

Author:
Ruslan Shevchenko
See Also:
Serialized Form

Constructor Summary
NodeTerm(INode node)
          create NodeTerm based on existing node.
NodeTerm(int id, String name)
          create NodeTerm with given id and name
NodeTerm(Term t)
          credte NodeTerm from normal term.
 
Method Summary
 boolean boundEquals(Term x)
          equality, when propositional variables are already bounded.
 boolean boundUnify(Term t, Substitution s)
          unification when we already have s and when same propositional variables means same things
 PartialOrderingResult concreteOrder(Term x, Substitution s)
          compare for 'more concrete' relation.
 Term createSame(Term[] newBody)
          create term, with same name but new body.
 boolean emptyFv()
          true, if term does not contains free propositional variables.
 int findSubtermIndexBoundEqualsTo(Term x)
           
 boolean freeEquals(Term x)
          Equality when all propositional variables are equal
 boolean freeUnify(Term t, Substitution s)
          do unification of this and t and store in s substitution.
 int getArity()
          get arity (i.
 Term getAttribute(String attribute)
          get attribute with name name .
 Map<String,Term> getAttributes()
          return map, where keys are attribute names, value - values of attributes.
 BigDecimal getBigDecimal()
          get BigDecimal value, if this term represent BigDecimal, otherwise throw UnsupportedOperationException
 BigInteger getBigInteger()
          get BigDecimal value, if this term represent BigInteger, otherwise throw UnsupportedOperationException
 boolean getBoolean()
          get boolean value, if this term represent boolean, otherwise throw UnsupportedOperationException
 byte getByte()
          get byte value, if this term represent byte, otherwise throw UnsupportedOperationException
 char getChar()
          get char value, if this term represent char, otherwise throw UnsupportedOperationException
 double getDouble()
          get double value, if this term represent double, otherwise throw UnsupportedOperationException Note, that this method does not provide conversion of other numeric types to double.
 float getFloat()
          get float value, if this term represent float, otherwise throw UnsupportedOperationException.
 int getInt()
          get integer value, if this term represent integer, otherwise throw UnsupportedOperationException
 Object getJavaObject()
           
 long getLong()
          get long value, if this term represent long, otherwise throw UnsupportedOperationException Note, that this method does not provide conversion of other numeric types to long.
 String getName()
          get name of functional symbol.
 Object getNameIndex()
          get index of name in instance symbol table.
 Number getNumber()
          get numeric value, if this term represent number, otherwise throw UnsupportedOperationException
 int getPrimaryType0()
          return code of level-0 primary type
 short getShort()
          get short value, if this term represent short, otherwise throw UnsupportedOperationException Note, that this method does not provide conversion of other numeric types to short.
 String getString()
          get string value, if this term represent string, otherwise throw InvalidPrimitiveTypeException
 Term getSubtermAt(int i)
          get subterm of current term.
 Term getTerm()
          get term.
 int getXIndex()
          if this variable is a propositional variable, return index of one.
 boolean isAtom()
          is term is atom ?
 boolean isBigDecimal()
          true, if this term is BigDecimal
 boolean isBigInteger()
          true, if this term is BigInteger
 boolean isBoolean()
          is term is booleam ?
 boolean isByte()
          true, if this term is Byte
 boolean isChar()
          is term is char ?
 boolean isComplexTerm()
          true, if this term have subterms
 boolean isDouble()
          is Term is double ?
 boolean isFloat()
          is Term is float ?
 boolean isInt()
          is term is Int ?
 boolean isJavaObject()
          if this term is Java Object ?
 boolean isLong()
          is Term is long ?
 boolean isNil()
          is term is nil ?
 boolean isNumber()
          is term is Number ?
 boolean isShort()
          is Term is short ?
 boolean isString()
          is Term is string ?
 boolean isX()
          true if this term is propositional variable.
 void jjtAddChildInternal(INode n, int i)
          add child at given place.
 void jjtClose()
          This method is called after all the child nodes have been added.
 INode jjtGetChildInternal(int i)
          This method returns a child node.
 int jjtGetNumChildren()
          Return the number of children the node has.
 INode jjtGetParentInternal()
           
 void jjtInsertChildInternal(INode n, int i)
          Insert node at index i If arity of existing term is less than i -- add NIL subterms as emty trees, otherwise -- insert n at index i, moving next elements up at one index.
 void jjtOpen()
          This method is called after the node has been made the current node.
 void jjtSetChildInternal(INode n, int i)
          set child at given place, replcing existing.
 void jjtSetParentInternal(INode n)
          This pair of methods are used to inform the node of its parent.
 int maxFv()
          get maximum index of free propositional variable in term
 int minFv()
          get minimal index of free propositional variable in term.
 void print(PrintWriter out)
          print term on out
 void setAttribute(String attribute, String value)
           
 void setAttribute(String attribute, Term value)
          set attribute with name name and value value .
 void setSubtermAt(int i, Term t)
          set i-th subterm to t when i < arity then throw IndexOutOfBoundsException
 void shiftFv(int newMinFv)
          renumerate propositional variables in such case, that minFv(shiftFv(t))==newMinFv
 Term subst(Substitution s)
          receive new term, which is sibstution of current term and s
 boolean substInside(Substitution s)
          apply substitution s to current term.
 Term termClone()
          deep clone of term.
 int termCompare(Term x)
          compare functions.
 
Methods inherited from class ua.gradsoft.termware.Term
containsSubtermBoundEqualsTo, getAsBigDecimal, getAsBigInteger, getAsBoolean, getAsByte, getAsChar, getAsDouble, getAsFloat, getAsInt, getAsJavaObject, getAsLong, getAsNumber, getAsShort, getAsString, getPatternName, getPatternNameIndex, getPrimaryType1, print, println, println
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NodeTerm

public NodeTerm(INode node)
create NodeTerm based on existing node.


NodeTerm

public NodeTerm(Term t)
credte NodeTerm from normal term. id_ is set to -1.


NodeTerm

public NodeTerm(int id,
                String name)
create NodeTerm with given id and name

Method Detail

jjtAddChildInternal

public void jjtAddChildInternal(INode n,
                                int i)
add child at given place. If arity of existing term is less than i -- add NIL subterms as emty trees, otherwise -- replace existing subterm. Implementator can delegate functionality of jjtAddChild of own node interface in JJTree SimpleNode. add is bad name (this in not add in strice sence), but this is semantics of JJTree node interface

Specified by:
jjtAddChildInternal in interface INode

jjtSetChildInternal

public void jjtSetChildInternal(INode n,
                                int i)
set child at given place, replcing existing. Implementator can use this in JJTree actions.


jjtInsertChildInternal

public void jjtInsertChildInternal(INode n,
                                   int i)
Insert node at index i If arity of existing term is less than i -- add NIL subterms as emty trees, otherwise -- insert n at index i, moving next elements up at one index. (this is difference from jjtAddInternal). Implementator can use this in JJTree actions for adding extra custom subterms from actions to parse tree.


jjtClose

public void jjtClose()
Description copied from interface: INode
This method is called after all the child nodes have been added.

Specified by:
jjtClose in interface INode

jjtGetChildInternal

public INode jjtGetChildInternal(int i)
Description copied from interface: INode
This method returns a child node. The children are numbered from zero, left to right.

Specified by:
jjtGetChildInternal in interface INode

jjtGetNumChildren

public int jjtGetNumChildren()
Description copied from interface: INode
Return the number of children the node has.

Specified by:
jjtGetNumChildren in interface INode

jjtGetParentInternal

public INode jjtGetParentInternal()
Specified by:
jjtGetParentInternal in interface INode

jjtOpen

public void jjtOpen()
Description copied from interface: INode
This method is called after the node has been made the current node. It indicates that child nodes can now be added to it.

Specified by:
jjtOpen in interface INode

jjtSetParentInternal

public void jjtSetParentInternal(INode n)
Description copied from interface: INode
This pair of methods are used to inform the node of its parent.

Specified by:
jjtSetParentInternal in interface INode

boundEquals

public boolean boundEquals(Term x)
                    throws TermWareException
Description copied from class: Term
equality, when propositional variables are already bounded.

Specified by:
boundEquals in class Term
Parameters:
x - - term to compare.
Returns:
true, if terms are bound-equals.
Throws:
TermWareException

boundUnify

public boolean boundUnify(Term t,
                          Substitution s)
                   throws TermWareException
Description copied from class: Term
unification when we already have s and when same propositional variables means same things

Specified by:
boundUnify in class Term
Throws:
TermWareException

createSame

public Term createSame(Term[] newBody)
                throws TermWareException
Description copied from class: Term
create term, with same name but new body. If this term have arity 0, or other than original - throws exception.

Specified by:
createSame in class Term
Throws:
TermWareException

emptyFv

public boolean emptyFv()
Description copied from class: Term
true, if term does not contains free propositional variables. (fv-set for this term is empty.)

Specified by:
emptyFv in class Term
Returns:
true, if fv_set does not contains free proporsitional variables.

findSubtermIndexBoundEqualsTo

public int findSubtermIndexBoundEqualsTo(Term x)
                                  throws TermWareException
Specified by:
findSubtermIndexBoundEqualsTo in class Term
Throws:
TermWareException

freeEquals

public boolean freeEquals(Term x)
                   throws TermWareException
Description copied from class: Term
Equality when all propositional variables are equal

Specified by:
freeEquals in class Term
Parameters:
x - - term to compare.
Returns:
true, if terms are free-equals.
Throws:
TermWareException

freeUnify

public boolean freeUnify(Term t,
                         Substitution s)
                  throws TermWareException
Description copied from class: Term
do unification of this and t and store in s substitution.

Specified by:
freeUnify in class Term
Returns:
true, if unification was succesfull.
Throws:
TermWareException

getArity

public int getArity()
Description copied from class: Term
get arity (i. e. number of subterms)

Specified by:
getArity in class Term
Returns:
arity of term.

getBigDecimal

public BigDecimal getBigDecimal()
                         throws UnsupportedOperationException
Description copied from class: Term
get BigDecimal value, if this term represent BigDecimal, otherwise throw UnsupportedOperationException

Specified by:
getBigDecimal in class Term
Returns:
number value
Throws:
UnsupportedOperationException - raised if this term does not represent BigDecimal value.

getBigInteger

public BigInteger getBigInteger()
                         throws UnsupportedOperationException
Description copied from class: Term
get BigDecimal value, if this term represent BigInteger, otherwise throw UnsupportedOperationException

Specified by:
getBigInteger in class Term
Returns:
value
Throws:
UnsupportedOperationException - raised if this term does not represent BigInteger value.

getBoolean

public boolean getBoolean()
Description copied from class: Term
get boolean value, if this term represent boolean, otherwise throw UnsupportedOperationException

Specified by:
getBoolean in class Term
Returns:
boolean value

getByte

public byte getByte()
Description copied from class: Term
get byte value, if this term represent byte, otherwise throw UnsupportedOperationException

Specified by:
getByte in class Term
Returns:
value

getChar

public char getChar()
Description copied from class: Term
get char value, if this term represent char, otherwise throw UnsupportedOperationException

Specified by:
getChar in class Term
Returns:
char value

getDouble

public double getDouble()
                 throws UnsupportedOperationException
Description copied from class: Term
get double value, if this term represent double, otherwise throw UnsupportedOperationException Note, that this method does not provide conversion of other numeric types to double.

Specified by:
getDouble in class Term
Returns:
double value
Throws:
UnsupportedOperationException - raised if this term does not represent double value.

getFloat

public float getFloat()
               throws UnsupportedOperationException
Description copied from class: Term
get float value, if this term represent float, otherwise throw UnsupportedOperationException. Note, that getFloat does not provide conversion of other numeric types (such as double) to float. For this use getAsFloat(ITerm t);

Specified by:
getFloat in class Term
Returns:
float value
Throws:
UnsupportedOperationException - raised if this term does not represent double value.

getInt

public int getInt()
           throws UnsupportedOperationException
Description copied from class: Term
get integer value, if this term represent integer, otherwise throw UnsupportedOperationException

Specified by:
getInt in class Term
Returns:
int value
Throws:
UnsupportedOperationException

getJavaObject

public Object getJavaObject()
Specified by:
getJavaObject in class Term
Returns:
Java Object, if this term holds opaque Java Object, otherwise throw UnsupportedOperationException

getLong

public long getLong()
             throws UnsupportedOperationException
Description copied from class: Term
get long value, if this term represent long, otherwise throw UnsupportedOperationException Note, that this method does not provide conversion of other numeric types to long. Use getAsLong(TermWareInstance instance) for this purpose.

Specified by:
getLong in class Term
Returns:
short value
Throws:
UnsupportedOperationException - raised if this term does not represent double value.

getName

public String getName()
Description copied from class: Term
get name of functional symbol.

Specified by:
getName in interface INode
Specified by:
getName in class Term
Returns:
name

getNameIndex

public Object getNameIndex()
Description copied from class: Term
get index of name in instance symbol table. If name is not inde (during unifications names are compared by indexes. This allows to speedup unification process)

Specified by:
getNameIndex in class Term

getNumber

public Number getNumber()
Description copied from class: Term
get numeric value, if this term represent number, otherwise throw UnsupportedOperationException

Specified by:
getNumber in class Term
Returns:
number value

getPrimaryType0

public int getPrimaryType0()
Description copied from class: Term
return code of level-0 primary type

Specified by:
getPrimaryType0 in class Term
Returns:
code of primary type
See Also:
PrimaryTypes

getShort

public short getShort()
               throws UnsupportedOperationException
Description copied from class: Term
get short value, if this term represent short, otherwise throw UnsupportedOperationException Note, that this method does not provide conversion of other numeric types to short. Use ITermHelper.getAsShort(ITerm t, TermWareInstance instance) for this purpose.

Specified by:
getShort in class Term
Returns:
short value
Throws:
UnsupportedOperationException - raised if this term does not represent double value.

getString

public String getString()
Description copied from class: Term
get string value, if this term represent string, otherwise throw InvalidPrimitiveTypeException

Specified by:
getString in class Term
Returns:
string value

getSubtermAt

public Term getSubtermAt(int i)
Description copied from class: Term
get subterm of current term. when i < arity then throw TermIndexOutOfBoundsException

Specified by:
getSubtermAt in class Term
Parameters:
i - - index of subterm, starting from 0
Returns:
i-th subterm of current term.

getTerm

public Term getTerm()
Description copied from class: Term
get term. Semantics is "return this term". Non-trivial implementations are used for deallocating proxy terms.

Specified by:
getTerm in class Term

getXIndex

public int getXIndex()
Description copied from class: Term
if this variable is a propositional variable, return index of one. Otherwise throw UnsupportedOperationException

Specified by:
getXIndex in class Term

isAtom

public boolean isAtom()
Description copied from class: Term
is term is atom ?

Specified by:
isAtom in class Term
Returns:
true if this term is atom

isBigDecimal

public boolean isBigDecimal()
Description copied from class: Term
true, if this term is BigDecimal

Specified by:
isBigDecimal in class Term

isBigInteger

public boolean isBigInteger()
Description copied from class: Term
true, if this term is BigInteger

Specified by:
isBigInteger in class Term

isBoolean

public boolean isBoolean()
Description copied from class: Term
is term is booleam ?

Specified by:
isBoolean in class Term
Returns:
true if this term is boolean

isByte

public boolean isByte()
Description copied from class: Term
true, if this term is Byte

Specified by:
isByte in class Term

isChar

public boolean isChar()
Description copied from class: Term
is term is char ?

Specified by:
isChar in class Term
Returns:
true if this term is char

isComplexTerm

public boolean isComplexTerm()
Description copied from class: Term
true, if this term have subterms

Specified by:
isComplexTerm in class Term
Returns:
true if this term have subterms.

isDouble

public boolean isDouble()
Description copied from class: Term
is Term is double ?

Specified by:
isDouble in class Term
Returns:
true if term represents double value.

isFloat

public boolean isFloat()
Description copied from class: Term
is Term is float ?

Specified by:
isFloat in class Term
Returns:
true if term represents float value.

isInt

public boolean isInt()
Description copied from class: Term
is term is Int ?

Specified by:
isInt in class Term
Returns:
true if term represents integer value.

isJavaObject

public boolean isJavaObject()
Description copied from class: Term
if this term is Java Object ?

Specified by:
isJavaObject in class Term

isLong

public boolean isLong()
Description copied from class: Term
is Term is long ?

Specified by:
isLong in class Term
Returns:
true if term represents long value.

isNil

public boolean isNil()
Description copied from class: Term
is term is nil ?

Specified by:
isNil in class Term
Returns:
true if this term is Nil

isNumber

public boolean isNumber()
Description copied from class: Term
is term is Number ?

Specified by:
isNumber in class Term
Returns:
true if term represents number value.

isShort

public boolean isShort()
Description copied from class: Term
is Term is short ?

Specified by:
isShort in class Term
Returns:
true if term represents short value.

isString

public boolean isString()
Description copied from class: Term
is Term is string ?

Specified by:
isString in class Term
Returns:
true if term represents string value.

isX

public boolean isX()
Description copied from class: Term
true if this term is propositional variable.

Specified by:
isX in class Term
Returns:
true if this term is propositional variable

maxFv

public int maxFv()
          throws TermWareException
Description copied from class: Term
get maximum index of free propositional variable in term

Specified by:
maxFv in class Term
Returns:
index of propositional variable with maximal index.
Throws:
TermWareException

minFv

public int minFv()
          throws TermWareException
Description copied from class: Term
get minimal index of free propositional variable in term.

Specified by:
minFv in class Term
Returns:
index of propositional variable with minimal index.
Throws:
TermWareException

print

public void print(PrintWriter out)
Description copied from class: Term
print term on out

Specified by:
print in class Term
Parameters:
out - - PrintWriter, where to print term.

setSubtermAt

public void setSubtermAt(int i,
                         Term t)
                  throws TermWareException
Description copied from class: Term
set i-th subterm to t when i < arity then throw IndexOutOfBoundsException

Specified by:
setSubtermAt in class Term
Parameters:
i - - index of subterm to set.
t - - subterm to set.
Throws:
TermWareException

shiftFv

public void shiftFv(int newMinFv)
             throws TermWareException
Description copied from class: Term
renumerate propositional variables in such case, that minFv(shiftFv(t))==newMinFv

Specified by:
shiftFv in class Term
Throws:
TermWareException

subst

public Term subst(Substitution s)
           throws TermWareException
Description copied from class: Term
receive new term, which is sibstution of current term and s

Specified by:
subst in class Term
Throws:
TermWareException

substInside

public boolean substInside(Substitution s)
                    throws TermWareException
Description copied from class: Term
apply substitution s to current term.

Specified by:
substInside in class Term
Throws:
TermWareException

termClone

public Term termClone()
               throws TermWareException
Description copied from class: Term
deep clone of term. (only immunitable terms are not cloned)

Specified by:
termClone in class Term
Throws:
TermWareException

termCompare

public int termCompare(Term x)
Description copied from class: Term
compare functions. define ordering on set of terms. Note, that ordering is not the same as Java build-in compare.

Specified by:
termCompare in class Term
Parameters:
x - - term to compare

concreteOrder

public PartialOrderingResult concreteOrder(Term x,
                                           Substitution s)
                                    throws TermWareException
Description copied from class: Term
compare for 'more concrete' relation. i. e. x.<(concrete)<(y) means, that for each substitution of free variables sx exists substituion sy : x[sx] = y[sy] .
Substitution s store previously matched variables.

Specified by:
concreteOrder in class Term
Throws:
TermWareException

getAttribute

public Term getAttribute(String attribute)
Description copied from interface: Attributed
get attribute with name name . When such attribute does not exists -- return NIL.

Specified by:
getAttribute in interface Attributed

getAttributes

public Map<String,Term> getAttributes()
Description copied from interface: Attributed
return map, where keys are attribute names, value - values of attributes.

Specified by:
getAttributes in interface Attributed

setAttribute

public void setAttribute(String attribute,
                         Term value)
Description copied from interface: Attributed
set attribute with name name and value value . If value is NIL, then attribute is erased from set.

Specified by:
setAttribute in interface Attributed

setAttribute

public void setAttribute(String attribute,
                         String value)