MathParser\Parsing\Nodes\Node Class Reference

Abstract base class for nodes in the abstract syntax tree generated by the Parser (and some AST transformers). More...

Inheritance diagram for MathParser\Parsing\Nodes\Node:
MathParser\Interpreting\Visitors\Visitable MathParser\Parsing\Nodes\ConstantNode MathParser\Parsing\Nodes\ExpressionNode MathParser\Parsing\Nodes\FunctionNode MathParser\Parsing\Nodes\IntegerNode MathParser\Parsing\Nodes\NumberNode MathParser\Parsing\Nodes\PostfixOperatorNode MathParser\Parsing\Nodes\RationalNode MathParser\Parsing\Nodes\SubExpressionNode MathParser\Parsing\Nodes\VariableNode

Public Member Functions

 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 Member Functions inherited from MathParser\Interpreting\Visitors\Visitable
 accept (Visitor $visitor)
 Single function in the Visitable interface. More...
 

Static Public Member Functions

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...
 

Public Attributes

const NumericInteger = 1
 
const NumericRational = 2
 
const NumericFloat = 3
 

Detailed Description

Abstract base class for nodes in the abstract syntax tree generated by the Parser (and some AST transformers).

Member Function Documentation

MathParser\Parsing\Nodes\Node::compareTo (   $other)
abstract

Helper function, comparing two ASTs.

Useful for testing and also for some AST transformers.

Parameters
Node | null$otherCompare to this tree
Return values
boolean
MathParser\Parsing\Nodes\Node::complexity ( )

Rough estimate of the complexity of the AST.

Gives a rough measure of the complexity of an AST. This can be useful to choose between different simplification rules or how to print a tree ("e^{...}" or ("\exp(...)") for example.

More precisely, the complexity is computed as the sum of the complexity of all nodes of the AST, and

  • NumberNodes, VariableNodes and ConstantNodes have complexity 1,
  • FunctionNodes have complexity 5 (plus the complexity of its operand),
  • ExpressionNodes have complexity 2 (for +, -, *), 4 (for /), or 8 (for ^)
MathParser\Parsing\Nodes\Node::evaluate (   $variables)

Convenience function for evaluating a tree, using the Evaluator class.

Example usage:

$parser = new StdMathParser();
$node = $parser->parse('sin(x)cos(y)');
$functionValue = $node->evaluate( array( 'x' => 1.3, 'y' => 1.4 ) );
Parameters
array$variableskey-value array of variable values
Return values
floatval
static MathParser\Parsing\Nodes\Node::factory ( Token  $token)
static

Node factory, creating an appropriate Node from a Token.

Based on the provided Token, returns a TerminalNode if the token type is PosInt, Integer, RealNumber, Identifier or Constant otherwise returns null.

Parameters
Token$tokenProvided token
Return values
Node|null
MathParser\Parsing\Nodes\Node::isTerminal ( )

Returns true if the node is a terminal node, i.e.

a NumerNode, VariableNode or ConstantNode.

Return values
boolean
static MathParser\Parsing\Nodes\Node::rationalFactory ( Token  $token)
static

Node factory, creating an appropriate Node from a Token.

Based on the provided Token, returns a TerminalNode if the token type is PosInt, Integer, RealNumber, Identifier or Constant otherwise returns null.

Parameters
Token$tokenProvided token
Return values
Node|null

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