PHPackages                             dbeurive/shuntingyard - 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. dbeurive/shuntingyard

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

dbeurive/shuntingyard
=====================

This is an implementation of the shunting yard algorithm.

1.0.3(9y ago)0481[1 PRs](https://github.com/dbeurive/shuntingyard/pulls)MITPHP

Since Nov 23Pushed 9y ago1 watchersCompare

[ Source](https://github.com/dbeurive/shuntingyard)[ Packagist](https://packagist.org/packages/dbeurive/shuntingyard)[ RSS](/packages/dbeurive-shuntingyard/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (3)Versions (5)Used By (0)

Introduction
============

[](#introduction)

This repository contains an implementation of the [Shunting Yard algorithm](https://en.wikipedia.org/wiki/Shunting-yard_algorithm).

Installation
============

[](#installation)

From the command line:

```
composer require dbeurive\shuntingyard

```

If you want to include this package to your project, then edit your file `composer.json` and add the following entry:

```
"require": {
	"dbeurive/shuntingyard": "*"
}

```

Synopsis
========

[](#synopsis)

```
	use dbeurive\Shuntingyard\ShuntingYard;

	define('TYPE_STRING',          'STRING');
	define('TYPE_VARIABLE',        'VARIABLE');
	define('TYPE_FUNCTION',        'FUNCTION');
	define('TYPE_NUMERIC',         'NUMERIC');
	define('TYPE_PARAM_SEPARATOR', 'PARAM_SEPARATOR');
	define('TYPE_OPEN_BRACKET',    'OPEN_BRACKET');
	define('TYPE_CLOSE_BRACKET',   'CLOSE_BRACKET');
	define('TYPE_OPERATOR',        'OPERATOR');
	define('TYPE_SPACE',           'SPACE');

	$tokens = array(
    	array('/"(?:[^"\\\\]|\\\\["\\\\])+"/',                TYPE_STRING),
    	array('/V\\d+/',                                      TYPE_VARIABLE),
    	array('/[a-z_]+[0-9]*/',                              TYPE_FUNCTION),
    	array('/\\d+/',                                       TYPE_NUMERIC),
    	array('/,/',                                          TYPE_PARAM_SEPARATOR),
    	array('/\\(/',                                        TYPE_OPEN_BRACKET),
    	array('/\\)/',                                        TYPE_CLOSE_BRACKET),
    	array('/(|~|%|\\+|\\-|\\*|\\/|\\^|>=||'     => 1,
    	'='    => 1,
    	''     => ShuntingYard::ASSOC_LEFT,
    	'='    => ShuntingYard::ASSOC_LEFT,
    	'
