|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.voytechs.jnetstream.npl.Node
com.voytechs.jnetstream.npl.OpNode
public abstract class OpNode
Base class for all operator nodes. Operators in an expression make certain operations on the operands on both left and right handside of the operator. For example "1 + 2" expression breaks down into 3 components. Operator "+", and 2 operands "1" and "2". The "1" operand is set as the left operand in operator "+", the "2" operand on the right side. You specify the left and right operands through either the constructor or using the set(), setLeft() or setRight() methods. The set() method is provided to allow overriding of previously set operands without having to specificly know if the operand being replaced is on the left or right side of the operator. This is usefull if are working with the actual operand and you use its getParent() method to get the operator object, but then you wish to replace the operand. You might not specifically know if the operand you just went through is on the left or right of the operand in the expression. Each operator carries three properties which are used in parsing of the expression.
| Field Summary | |
|---|---|
static int |
BINARY
|
protected int |
cardinality
|
static int |
FLAG_NO_OP
|
protected int |
flags
|
static int |
HIGH
|
protected Node |
left
|
static int |
LOW
|
static int |
MEDIUM
|
static int |
NORMAL
|
protected java.lang.String |
op
|
protected int |
presedence
|
protected Node |
right
|
static int |
UNARY
|
| Fields inherited from class com.voytechs.jnetstream.npl.Node |
|---|
parent, token |
| Constructor Summary | |
|---|---|
OpNode(java.lang.String op,
int presedence)
Base class for all Op nodes (Operators). |
|
OpNode(java.lang.String op,
int presedence,
int cardinality,
Node right,
Node left)
Base class for all Op nodes (Operators). |
|
OpNode(java.lang.String op,
int presedence,
Node right,
Node left)
Base class for all Op nodes (Operators). |
|
| Method Summary | |
|---|---|
boolean |
canOptimize()
Checks to see if both left and right operands can be optimized. |
java.lang.Object |
clone()
Clones the current Operator node. |
OpNode |
createOpNode(Node left)
|
OpNode |
createOpNode(Node right,
Node left)
|
OpNode |
createOpNode(java.util.Stack operands)
Creates a new node using the factory pattern. |
boolean |
equals(java.lang.Object s)
Compares the name of the Operation with the given string. |
int |
getCardinality()
|
int |
getFlags()
|
Node |
getLeft()
Returns the left handside operand. |
java.lang.String |
getOpString()
|
int |
getPresedence()
|
Node |
getRight()
Returns the right handside operand. |
static void |
main(java.lang.String[] args)
Test function for OpNode |
Node |
optimize()
If possible optimizes away its branches. |
void |
set(Node newValue,
Node oldValue)
Sets a new object for either left or right side of the Operation. |
void |
setFlag(int flag)
|
void |
setLeft(Node node)
Sets the left handside operand of this operation. |
void |
setRight(Node node)
Sets the right handside operand of this operation. |
java.lang.String |
toString()
|
boolean |
visit(Visitor visitor,
java.lang.Object user1,
java.lang.Object user2)
|
| Methods inherited from class com.voytechs.jnetstream.npl.Node |
|---|
getParent, getToken, setParent, setToken |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface com.voytechs.jnetstream.npl.IntNode |
|---|
getInt |
| Methods inherited from interface com.voytechs.jnetstream.npl.BooleanNode |
|---|
getBoolean |
| Methods inherited from interface com.voytechs.jnetstream.npl.LongNode |
|---|
getLong |
| Field Detail |
|---|
protected Node right
protected Node left
protected java.lang.String op
public static final int LOW
public static final int NORMAL
public static final int MEDIUM
public static final int HIGH
protected int presedence
public static final int UNARY
public static final int BINARY
protected int cardinality
public static final int FLAG_NO_OP
protected int flags
| Constructor Detail |
|---|
public OpNode(java.lang.String op,
int presedence)
op - The name for this operator. This is a string that represents its name.presedence - This an integer value that determines the operators presedence
when parsing expression. The lower the presedence the more important the operator. Thus
a lower level operator will have presedence with higher level operator. i.e. '+' operator
has presedence over over a '='. That is you want to do calculations first and then
the assignment. Use the predefined constant values in OpNode, such as
public OpNode(java.lang.String op,
int presedence,
Node right,
Node left)
op - The name for this operator. This is a string that represents its name.presedence - This an integer value that determines the operators presedence
when parsing expression. The lower the presedence the more important the operator. Thus
a lower level operator will have presedence with higher level operator. i.e. '+' operator
has presedence over over a '='. That is you want to do calculations first and then
the assignment. Use the predefined constant values in OpNode, such as
right - The operand on the right side of the operator.left - The operand on the left side of the operator.
public OpNode(java.lang.String op,
int presedence,
int cardinality,
Node right,
Node left)
op - The name for this operator. This is a string that represents its name.presedence - This an integer value that determines the operators presedence
when parsing expression. The lower the presedence the more important the operator. Thus
a lower level operator will have presedence with higher level operator. i.e. '+' operator
has presedence over over a '='. That is you want to do calculations first and then
the assignment. Use the predefined constant values in OpNode, such as
cardinality - Determines if the operator is binary or unary. Binary operators
have both left and right handside in an expression. Unary oparators only the left.
Use the predefine constants to set the value correctly:
right - The operand on the right side of the operator.left - The operand on the left side of the operator.| Method Detail |
|---|
public boolean visit(Visitor visitor,
java.lang.Object user1,
java.lang.Object user2)
throws NodeException
visit in interface VisitableNodeException
public OpNode createOpNode(Node right,
Node left)
public OpNode createOpNode(Node left)
public int getFlags()
public void setFlag(int flag)
public int getPresedence()
public int getCardinality()
public java.lang.Object clone()
clone in class java.lang.Objectpublic boolean canOptimize()
canOptimize in class Nodepublic Node optimize()
optimize in class Nodepublic java.lang.String getOpString()
public boolean equals(java.lang.Object s)
equals in class java.lang.Objects - Object to compare against.
public OpNode createOpNode(java.util.Stack operands)
throws OperandException,
ExpInternalException
operands - Stack containing operands.
OperandException - Throws OperandException if there aren't enough operands on the stack.
ExpInternalExceptionpublic Node getLeft()
public Node getRight()
public void setLeft(Node node)
left - Left operand for the operation.public void setRight(Node node)
right - Right operand for the operation.
public void set(Node newValue,
Node oldValue)
throws NodeException
newValue - New operand valueoldValue - Old operand value which also determines where the new
value will be set, right or left.
NodeException - If oldValue can not be found in either left
or right operand an exception is thrown. "oldValue" is used to determine
which operand, left or right, should the newValue replace.public java.lang.String toString()
toString in class java.lang.Objectpublic static void main(java.lang.String[] args)
args - command line arguments
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||