mossadal/math-parser

View on GitHub
src/MathParser/ComplexMathParser.php

Summary

Maintainability
A
1 hr
Test Coverage
<?php 

namespace MathParser;

/*
* @package     Parsing
* @author      Frank Wikström <frank@mossadal.se>
* @copyright   2015 Frank Wikström
* @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
*
*/



use MathParser\Parsing\Parser;
use MathParser\Lexing\ComplexLexer;

class ComplexMathParser extends AbstractMathParser
{

    public function __construct()
    {
        $this->lexer = new ComplexLexer();
        $this->parser = new Parser();
        $this->parser->setRationalFactory(true);

    }

    /**
     * Parse the given mathematical expression into an abstract syntax tree.
     *
     * @param string $text Input
     * @return Node
     */
    public function parse($text)
    {
        $this->tokens = $this->lexer->tokenize($text);
        $this->tree = $this->parser->parse($this->tokens);

        return $this->tree;
    }
    
}