MathParser\Parsing\Nodes\ExpressionNode Class Reference

AST node representing a binary operator. More...

Inheritance diagram for MathParser\Parsing\Nodes\ExpressionNode:
MathParser\Parsing\Nodes\Node MathParser\Interpreting\Visitors\Visitable

Public Member Functions

 __construct ($left, $operator=null, $right=null)
 Constructor. More...
 
 getLeft ()
 Return the first (left) operand. More...
 
 setLeft ($operand)
 Set the left operand. More...
 
 getOperator ()
 Return the operator. More...
 
 setOperator ($operator)
 Set the operator. More...
 
 getRight ()
 Return the second (right) operand. More...
 
 setRight ($operand)
 Set the right operand. More...
 
 getPrecedence ()
 Return the precedence of the ExpressionNode. More...
 
 accept (Visitor $visitor)
 Implementing the Visitable interface.
 
 canBeUnary ()
 Returns true if the node can represent a unary operator, i.e. More...
 
 lowerPrecedenceThan ($other)
 Returns true if the current Node has lower precedence than the one we compare with. More...
 
 strictlyLowerPrecedenceThan ($other)
 
 compareTo ($other)
 Implementing the compareTo abstract method. More...
 
- Public Member Functions inherited from MathParser\Parsing\Nodes\Node
 compareTo ($other)
 Helper function, comparing two ASTs. More...
 
 evaluate ($variables)
 Convenience function for evaluating a tree, using the Evaluator class. More...
 
 complexity ()
 Rough estimate of the complexity of the AST. More...
 
 isTerminal ()
 Returns true if the node is a terminal node, i.e. More...
 
 getOperator ()
 
 __toString ()
 

Public Attributes

const LEFT_ASSOC = 1
 integer constant representing left associatve operators
 
const RIGHT_ASSOC = 2
 integer constant representing left associatve operators
 
- Public Attributes inherited from MathParser\Parsing\Nodes\Node
const NumericInteger = 1
 
const NumericRational = 2
 
const NumericFloat = 3
 

Private Attributes

 $left
 Node $left Left operand.
 
 $operator
 string $operator Operator, e.g. More...
 
 $right
 Node $right Right operand.
 
 $precedence
 int $precedence Precedence. More...
 
 $associativity
 LEFT_ASSOC | RIGHT_ASSOC $associativity Associativity of operator. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from MathParser\Parsing\Nodes\Node
static rationalFactory (Token $token)
 Node factory, creating an appropriate Node from a Token. More...
 
static factory (Token $token)
 Node factory, creating an appropriate Node from a Token. More...
 

Detailed Description

AST node representing a binary operator.

Constructor & Destructor Documentation

MathParser\Parsing\Nodes\ExpressionNode::__construct (   $left,
  $operator = null,
  $right = null 
)

Constructor.

Construct a binary operator node from (one or) two operands and an operator.

For convenience, the constructor accept int or float as operands, automatically converting these to NumberNodes

Example

$node = new ExpressionNode(1,'+',2);
Parameters
Node | null | int | float$leftFirst operand
string$operatorName of operator
Node | null | int | float$rightSecond operand

Member Function Documentation

MathParser\Parsing\Nodes\ExpressionNode::canBeUnary ( )

Returns true if the node can represent a unary operator, i.e.

if the operator is '+' or '-'-

Return values
boolean
MathParser\Parsing\Nodes\ExpressionNode::compareTo (   $other)

Implementing the compareTo abstract method.

MathParser\Parsing\Nodes\ExpressionNode::getLeft ( )

Return the first (left) operand.

Return values
Node|null
MathParser\Parsing\Nodes\ExpressionNode::getOperator ( )

Return the operator.

Return values
string
MathParser\Parsing\Nodes\ExpressionNode::getPrecedence ( )

Return the precedence of the ExpressionNode.

Return values
intprecedence
MathParser\Parsing\Nodes\ExpressionNode::getRight ( )

Return the second (right) operand.

Return values
Node|null
MathParser\Parsing\Nodes\ExpressionNode::lowerPrecedenceThan (   $other)

Returns true if the current Node has lower precedence than the one we compare with.

In case of a tie, we also consider the associativity. (Left associative operators are lower precedence in this context.)

Parameters
Node$otherNode to compare to.
Return values
boolean
MathParser\Parsing\Nodes\ExpressionNode::setLeft (   $operand)

Set the left operand.

Return values
void
MathParser\Parsing\Nodes\ExpressionNode::setOperator (   $operator)

Set the operator.

Return values
void
MathParser\Parsing\Nodes\ExpressionNode::setRight (   $operand)

Set the right operand.

Return values
void

Member Data Documentation

MathParser\Parsing\Nodes\ExpressionNode::$associativity
private

LEFT_ASSOC | RIGHT_ASSOC $associativity Associativity of operator.

MathParser\Parsing\Nodes\ExpressionNode::$operator
private

string $operator Operator, e.g.

'+', '-', '*', '/' or '^'

MathParser\Parsing\Nodes\ExpressionNode::$precedence
private

int $precedence Precedence.

Operators with higher prcedence bind harder


The documentation for this class was generated from the following file: