2017 © Pedro Peláez
 

library math-expression-parser

A component to parse all kind of numerical expressions and solve them

image

josefelipetto/math-expression-parser

A component to parse all kind of numerical expressions and solve them

  • Friday, June 29, 2018
  • by josefelipetto
  • Repository
  • 1 Watchers
  • 1 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

math-expression-parser

A Math expression parser built in PHP., (*1)

Requirements

  • PHP 7.1

Installation

You can install the component by using composer., (*2)

composer require josefelipetto/math-expression-parser, (*3)

How to use

You can use in two ways:, (*4)

  • Using the ExpressionParser facade that already mount the dependecies of the Evaluator class and returns the result, like this:
use Parser\Facades\ExpressionParser;

$result = ExpressionParser::parse('(2+2)^(2*2)/1+3+5');

assert($result === 264); 
  • Or you can actually use you own implementation of a Lexer and/or AST by providing the dependencies to the classes, like this:
use Parser\Evaluator;
use Parser\Lexer; // Or your Lexer
use Parser\Syntactic; // Or your AST

$evaluator = new Evaluator(new Syntactic(new Lexer('(2+2)^(2*2)/1+3+5')));

assert($evaluator->parse() === 264);

Grammar

The parser accepts the following operators: + ; - ; . ; * ; / ; ^ ; ( ; ), (*5)

The Versions

29/06 2018

dev-master

9999999-dev

A component to parse all kind of numerical expressions and solve them

  Sources   Download

MIT

The Requires

  • php ^7.0

 

parser math expression