PHPackages                             mariopereira/php-shunting-yard - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mariopereira/php-shunting-yard

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mariopereira/php-shunting-yard
==============================

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

01PHP

Since Jan 18Pushed 3y agoCompare

[ Source](https://github.com/mariopereira/php-shunting-yard)[ Packagist](https://packagist.org/packages/mariopereira/php-shunting-yard)[ RSS](/packages/mariopereira-php-shunting-yard/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHP Shunting Yard Implementation
--------------------------------

[](#php-shunting-yard-implementation)

### Example

[](#example)

Simple equation parsing

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

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

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

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

[](#installation)

Define the following requirement in your composer.json file:

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

### Authors

[](#authors)

Forked from .

Originally source code taken from , some changes from:

-
-
-

Test cases and refactoring for composer/packagist by .

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity1

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity23

Early-stage or recently created project

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/e8a6d7c5ff5c49b147d9dde17b5d5ad97bdaf763ac57ed216d9d943e36b78cb1?d=identicon)[mariopereira](/maintainers/mariopereira)

---

Top Contributors

[![andig](https://avatars.githubusercontent.com/u/184815?v=4)](https://github.com/andig "andig (25 commits)")[![sergej-kurakin](https://avatars.githubusercontent.com/u/196096?v=4)](https://github.com/sergej-kurakin "sergej-kurakin (15 commits)")[![pmishev](https://avatars.githubusercontent.com/u/5188763?v=4)](https://github.com/pmishev "pmishev (14 commits)")[![falahati](https://avatars.githubusercontent.com/u/2479372?v=4)](https://github.com/falahati "falahati (10 commits)")[![dmromanov](https://avatars.githubusercontent.com/u/299059?v=4)](https://github.com/dmromanov "dmromanov (1 commits)")

### Embed Badge

![Health badge](/badges/mariopereira-php-shunting-yard/health.svg)

```
[![Health](https://phpackages.com/badges/mariopereira-php-shunting-yard/health.svg)](https://phpackages.com/packages/mariopereira-php-shunting-yard)
```

###  Alternatives

[felixnagel/t3extblog

A record based blog extension for TYPO3 CMS. Easy to use and packed with features (incl. comments, subscriptions for comments and posts, Wordpress like subscription manager, reasonable email sending in FE and BE, GDPR ready, BE modules, Dashboard widgets, RSS, Sitemap, ...). Flexible and powerful!

3421.6k](/packages/felixnagel-t3extblog)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
