MathParser\Parsing\Nodes\Factories\AdditionNodeFactory Class Reference

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

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

Public Member Functions

 makeNode ($leftOperand, $rightOperand)
 Create a Node representing 'leftOperand + rightOperand'. More...
 

Protected Member Functions

 numericTerms ($leftOperand, $rightOperand)
 Simplify addition node when operands are numeric. 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\AdditionNodeFactory::makeNode (   $leftOperand,
  $rightOperand 
)

Create a Node representing 'leftOperand + rightOperand'.

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

Simplification rules:

  • To simplify the use of the function, convert integer or float params to NumberNodes
  • If $leftOperand and $rightOperand are both NumberNodes, return a single NumberNode containing their sum
  • If $leftOperand or $rightOperand are NumberNodes representing 0, return the other term unchanged
Parameters
Node | int$leftOperandFirst term
Node | int$rightOperandSecond term
Return values
Node

Implements MathParser\Parsing\Nodes\Interfaces\ExpressionNodeFactory.

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

Simplify addition node when operands are numeric.

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

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