net.scheinerman.phoenix.interpreter.parser.operators
Class OperatorNode

java.lang.Object
  extended by net.scheinerman.phoenix.interpreter.parser.operators.OperatorNode
All Implemented Interfaces:
ParserTreeNode
Direct Known Subclasses:
AddOperatorNode, AndOperatorNode, AssignAddOperatorNode, AssignDivideOperatorNode, AssignExpOperatorNode, AssignModOperatorNode, AssignMultiplyOperatorNode, AssignOperatorNode, AssignRoundOperatorNode, AssignSubtractOperatorNode, DivideOperatorNode, EqualOperatorNode, ExpOperatorNode, FunctionOperatorNode, FunctionReferenceOperatorNode, GreaterEqualOperatorNode, GreaterOperatorNode, LessEqualOperatorNode, LessOperatorNode, ModOperatorNode, MultiplyOperatorNode, NegationOperatorNode, NotEqualOperatorNode, NotOperatorNode, OrOperatorNode, PostfixDecrementOperatorNode, PostfixIncrementOperatorNode, PrefixDecrementOperatorNode, PrefixIncrementOperatorNode, RoundOperatorNode, SubscriptSliceOperatorNode, SubtractOperatorNode, XOrOperatorNode

public abstract class OperatorNode
extends java.lang.Object
implements ParserTreeNode

Represents an operator that is being parsed in an expression tree in Phoenix. This class is to be subclasssed to provide specific implementation of operator capabilities in Phoenix. For example the AddOperatorNode class provides implementation of the + operator.

Since:
1.5
Version:
1.0
Author:
Jonah Scheinerman

Field Summary
private  ParserTreeNode left
          The left-hand operand of this operator.
private  boolean parenthesized
          Whether or not this node is encapsulated by parentheses.
private  ParserTreeNode right
          The right-hand operand of this operator.
 
Constructor Summary
OperatorNode(ParserTreeNode left, ParserTreeNode right)
          Creates a new operator node with left and right-hand operands.
 
Method Summary
abstract  int getPrecedence()
          Returns the precedence of the node in the order of operations, when it should be evaluated in the tree.
 boolean isLeftOperandUnary()
          Determines if, for a unary operator the operand is on the right or the left.
 boolean isParenthesized()
          Returns true or false based on whether or not this node was encapsulated by parentheses.
 boolean isUnary()
          Returns whether or not this operator is unary, meaning that it only accepts one operand on the right or the left.
 ParserTreeNode left()
          Returns the left-hand operand of this operator.
 void left(ParserTreeNode left)
          Sets the left-hand operand of this operator.
 Variable operate()
          Parses this operator, by operating on the left and right hand arguments and then combining the results in some implementation specific manner.
abstract  java.lang.String operator()
          Returns the string representation of this operator.
 ParserTreeNode right()
          Returns the left-hand operand of this operator.
 void right(ParserTreeNode right)
          Sets the right-hand operand of this operator.
 void setParenthesized(boolean parenthesized)
          Sets whether or not this node is encapsulated by parentheses.
 java.lang.String toString()
          Returns a string in the form: "(" + left().toString() + operator() + right().toString() + ")".
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

parenthesized

private boolean parenthesized
Whether or not this node is encapsulated by parentheses.


left

private ParserTreeNode left
The left-hand operand of this operator.


right

private ParserTreeNode right
The right-hand operand of this operator.

Constructor Detail

OperatorNode

public OperatorNode(ParserTreeNode left,
                    ParserTreeNode right)
Creates a new operator node with left and right-hand operands.

Parameters:
left - - The new left-hand operand.
right - - The new left-hand operand.
Method Detail

isParenthesized

public boolean isParenthesized()
Description copied from interface: ParserTreeNode
Returns true or false based on whether or not this node was encapsulated by parentheses.

Specified by:
isParenthesized in interface ParserTreeNode
Returns:
Whether or not this node was encapsulated by parentheses.

setParenthesized

public void setParenthesized(boolean parenthesized)
Description copied from interface: ParserTreeNode
Sets whether or not this node is encapsulated by parentheses.

Specified by:
setParenthesized in interface ParserTreeNode
Parameters:
parenthesized - - true if this node is surrounded by parentheses, false if not.

left

public final ParserTreeNode left()
Returns the left-hand operand of this operator.

Specified by:
left in interface ParserTreeNode
Returns:
The left-hand operand.

left

public final void left(ParserTreeNode left)
Sets the left-hand operand of this operator.

Parameters:
left - - The new left-hand operand.

right

public final ParserTreeNode right()
Returns the left-hand operand of this operator.

Specified by:
right in interface ParserTreeNode
Returns:
The left-hand operand.

right

public final void right(ParserTreeNode right)
Sets the right-hand operand of this operator.

Parameters:
left - - The new right-hand operand.

operate

public Variable operate()
Parses this operator, by operating on the left and right hand arguments and then combining the results in some implementation specific manner.

Specified by:
operate in interface ParserTreeNode
Returns:
The variable result of the operation.

operator

public abstract java.lang.String operator()
Returns the string representation of this operator. For example, in the case of the add operator, the string "+" is returned.

Returns:
A string representation of this operator symbol.

toString

public java.lang.String toString()
Returns a string in the form: "(" + left().toString() + operator() + right().toString() + ")".

Overrides:
toString in class java.lang.Object
Returns:
A string form of this section of the parsing tree.

getPrecedence

public abstract int getPrecedence()
Description copied from interface: ParserTreeNode
Returns the precedence of the node in the order of operations, when it should be evaluated in the tree. The precedence is an integer, the higher the integer, the higher the precedence, meaning that this node will be evaluated sooner than those of lower precedence.

Specified by:
getPrecedence in interface ParserTreeNode
Returns:
A number representing the precedence of this node.

isUnary

public boolean isUnary()
Returns whether or not this operator is unary, meaning that it only accepts one operand on the right or the left. To specify what operand it takes, the isLeftOperandUnary() method is used. By default, this method returns false.

Returns:
true if it is unary, false if not.

isLeftOperandUnary

public boolean isLeftOperandUnary()
Determines if, for a unary operator the operand is on the right or the left. If this method returns true, then the operator has a left-hand operand, if false, the operator has a right-hand operand.

Returns:
true if this operator has a left-hand, false if it has a right-hand operand.