MathParser\RationalMathParser Class Reference

Convenience class for using the MathParser library. More...

Public Member Functions

 setSimplifying ($flag)
 
 parse ($text)
 Parse the given mathematical expression into an abstract syntax tree. More...
 
 getTokenList ()
 Return the token list for the last parsed expression. More...
 
 getTree ()
 Return the AST of the last parsed expression. More...
 

Private Attributes

 $lexer
 StdMathLexer $lexer instance of StdMathLexer used for tokenizing.
 
 $parser
 Parser $parser instance of Parsed used for the actual parsing.
 
 $tokens
 Token[] $tokens list of tokens generated by the Lexer.
 
 $tree
 Node $tree AST generated by the parser.
 

Detailed Description

Convenience class for using the MathParser library.

StdMathParser is a wrapper for the StdMathLexer and Parser classes, and if you do not require any tweaking, this is the most straightforward way to use the MathParser library.

Example usage:

$parser = new RationalMathParser();
$AST = $parser->parse('2x + 2y^2/sin(x)');
// Do whatever you want with the parsed expression,
// for example evaluate it.
$evaluator = new Evaluator([ 'x' => 1, 'y' => 2 ]);
$value = $AST->accept($evaluator);
// or differentiate it:
$d_dx = new Differentiator('x');
$derivative = $AST->accept($d_dx);
$valueOfDerivative = $derivative->accept($evaluator);

Member Function Documentation

MathParser\RationalMathParser::getTokenList ( )

Return the token list for the last parsed expression.

Return values
Token[]
MathParser\RationalMathParser::getTree ( )

Return the AST of the last parsed expression.

Return values
Node
MathParser\RationalMathParser::parse (   $text)

Parse the given mathematical expression into an abstract syntax tree.

Parameters
string$textInput
Return values
Node

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