2017-25 © Pedro Peláez
 

library php-shunting-yard

Refactored repack of https://github.com/andig/php-shunting-yard

image

andig/php-shunting-yard

Refactored repack of https://github.com/andig/php-shunting-yard

  • Wednesday, December 27, 2017
  • by andig
  • Repository
  • 1 Watchers
  • 12 Stars
  • 25,831 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 11 Forks
  • 0 Open issues
  • 5 Versions
  • 8 % Grown

The README.md

PHP Shunting Yard Implementation

Example

Simple equation parsing, (*1)

use RR\Shunt\Parser;

$equation = '3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3';
$result = Parser::parse($equation);
echo $result; //3.0001220703125

Equation with constants and functions, (*2)

use RR\Shunt\Parser;
use RR\Shunt\Context;

$ctx = new Context();
$ctx->def('abs'); // wrapper for PHP "abs" function
$ctx->def('foo', 5); // constant "foo" with value "5"
$ctx->def('bar', function($a, $b) { return $a * $b; }); // define function

$equation = '3 + bar(4, 2) / (abs(-1) - foo) ^ 2 ^ 3';
$result = Parser::parse($equation, $ctx);
echo $result; //3.0001220703125

Test a condition, (*3)

use RR\Shunt\Parser;
use RR\Shunt\Context;

$ctx = new Context();
$ctx->def('foo', 5); // constant "foo" with value "5"

$equation = '(foo > 3) & (foo < 6)';
$result = Parser::parse($equation, $ctx);
echo $result; //true

Re-run parsed expression on multiple inputs, (*4)

use RR\Shunt\Parser;
use RR\Shunt\Context;

$counter = 1;
$ctx = new Context();
$ctx->def('data', function() { global $counter; return $counter++; }); // define function
$ctx->def('bar', function($a) { return 2*$a; }); // define function

$equation = 'bar(data())';
$parser = new Parser(new Scanner($equation));

$result = $parser->reduce($this->ctx); // first result
echo $result; // 2
$result = $parser->reduce($this->ctx); // second result
echo $result; // 4

Installation

Define the following requirement in your composer.json file:, (*5)

{
    "require": {
        "andig/php-shunting-yard": "dev-master"
    }
}

Authors

Originally source code taken from https://github.com/droptable/php-shunting-yard, some changes from:, (*6)

  • https://github.com/andig/php-shunting-yard
  • https://github.com/pmishev/php-shunting-yard
  • https://github.com/falahati/php-shunting-yard

Test cases and refactoring for composer/packagist by https://github.com/sergej-kurakin/php-shunting-yard., (*7)

The Versions

27/12 2017

dev-master

9999999-dev https://github.com/andig/php-shunting-yard

Refactored repack of https://github.com/andig/php-shunting-yard

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

math shunting yard equation

27/12 2017

1.0.2

1.0.2.0 https://github.com/andig/php-shunting-yard

Refactored repack of https://github.com/andig/php-shunting-yard

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

math shunting yard equation

15/10 2017

1.0.1

1.0.1.0 https://github.com/andig/php-shunting-yard

Refactored repack of https://github.com/andig/php-shunting-yard

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

math shunting yard equation

05/10 2016

1.0

1.0.0.0 https://github.com/andig/php-shunting-yard

Refactored repack of https://github.com/andig/php-shunting-yard

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

math shunting yard equation

26/11 2014

dev-boolean

dev-boolean https://github.com/andig/php-shunting-yard

Refactored repack of https://github.com/droptable/php-shunting-yard

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

math shunting yard equation