MathParser\Parsing\Nodes\Factories\SubtractionNodeFactory Class Reference

Factory for creating an ExpressionNode representing '-'. More...

Inheritance diagram for MathParser\Parsing\Nodes\Factories\SubtractionNodeFactory:
MathParser\Parsing\Nodes\Interfaces\ExpressionNodeFactory

Public Member Functions

 makeNode ($leftOperand, $rightOperand)
 Create a Node representing 'leftOperand - rightOperand'. More...
 
 createUnaryMinusNode ($operand)
 Create a Node representing '-$operand'. More...
 

Protected Member Functions

 numericTerms ($leftOperand, $rightOperand)
 Simplify subtraction nodes for numeric operands. More...
 

Detailed Description

Factory for creating an ExpressionNode representing '-'.

Some basic simplification is applied to the resulting Node.

Member Function Documentation

MathParser\Parsing\Nodes\Factories\SubtractionNodeFactory::createUnaryMinusNode (   $operand)

Create a Node representing '-$operand'.

Using some simplification rules, create a NumberNode or ExpressionNode giving an AST correctly representing '-$operand'.

Simplification rules:

  • To simplify the use of the function, convert integer params to NumberNodes
  • If $operand is a NumberNodes, return a single NumberNode containing its negative
  • If $operand already is a unary minus, 'x=-y', return y
Parameters
Node | int$operandOperand
Return values
Node
MathParser\Parsing\Nodes\Factories\SubtractionNodeFactory::makeNode (   $leftOperand,
  $rightOperand 
)

Create a Node representing 'leftOperand - rightOperand'.

Using some simplification rules, create a NumberNode or ExpressionNode giving an AST correctly representing 'rightOperand - leftOperand'.

Simplification rules:

  • To simplify the use of the function, convert integer params to NumberNodes
  • If $rightOperand is null, return a unary minus node '-x' instead
  • If $leftOperand and $rightOperand are both NumberNodes, return a single NumberNode containing their difference
  • If $rightOperand is a NumberNode representing 0, return $leftOperand unchanged
  • If $leftOperand and $rightOperand are equal, return '0'
Parameters
Node | int | float$leftOperandMinuend
Node | int | float$rightOperandSubtrahend
Return values
Node

Implements MathParser\Parsing\Nodes\Interfaces\ExpressionNodeFactory.

MathParser\Parsing\Nodes\Factories\SubtractionNodeFactory::numericTerms (   $leftOperand,
  $rightOperand 
)
protected

Simplify subtraction nodes for numeric operands.

Parameters
Node$leftOperand
Node$rightOperand
Return values
Node|null

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