andig/php-shunting-yard 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

andig/php-shunting-yard

最新稳定版本:1.0.2

Composer 安装命令:

composer require andig/php-shunting-yard

包简介

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

README 文档

README

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

Define the following requirement in your composer.json file:

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

Authors

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

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

统计信息

  • 总下载量: 212.93k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 26
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 26
  • Watchers: 0
  • Forks: 17
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固