dbeurive/shuntingyard
Composer 安装命令:
composer require dbeurive/shuntingyard
包简介
This is an implementation of the shunting yard algorithm.
关键字:
README 文档
README
This repository contains an implementation of the Shunting Yard algorithm.
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
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('/(<>|~|%|\\+|\\-|\\*|\\/|\\^|>=|<=|>|<|=|&)/', TYPE_OPERATOR), array('/\\s+/', TYPE_SPACE, function(array $m) { return null; }) ); $precedences = array( '%' => 4, '~' => 4, '^' => 4, '&' => 3, '*' => 3, '/' => 3, '+' => 2, '-' => 2, '>' => 1, '<' => 1, '>=' => 1, '<=' => 1, '=' => 1, '<>' => 1 ); $associativities = array( '~' => ShuntingYard::ASSOC_RIGHT, '%' => ShuntingYard::ASSOC_RIGHT, '^' => ShuntingYard::ASSOC_RIGHT, '&' => ShuntingYard::ASSOC_LEFT, '*' => ShuntingYard::ASSOC_LEFT, '/' => ShuntingYard::ASSOC_LEFT, '+' => ShuntingYard::ASSOC_LEFT, '-' => ShuntingYard::ASSOC_LEFT, '>' => ShuntingYard::ASSOC_LEFT, '<' => ShuntingYard::ASSOC_LEFT, '>=' => ShuntingYard::ASSOC_LEFT, '<=' => ShuntingYard::ASSOC_LEFT, '=' => ShuntingYard::ASSOC_LEFT, '<>' => ShuntingYard::ASSOC_LEFT ); $sy = new ShuntingYard( $tokens, $precedences, $associativities, array(TYPE_VARIABLE, TYPE_STRING, TYPE_NUMERIC), array(TYPE_FUNCTION), array(TYPE_OPERATOR), TYPE_PARAM_SEPARATOR, TYPE_OPEN_BRACKET, TYPE_CLOSE_BRACKET ); $text = '"azerty" / V1 + V2 * sin(10)'; $tokens = $sy->convert($text, $error); print "$text:\n\n" . $sy->dumpRpn($tokens) . "\n\n";
The result:
"azerty" / V1 + V2 * sin(10):
STRING "azerty"
VARIABLE V1
OPERATOR /
VARIABLE V2
NUMERIC 10
FUNCTION sin
OPERATOR *
OPERATOR +
Configuration
The algorithm is configured by:
- The list of tokens (see the documentation for the class dbeurive\Lexer\Lexer).
- The operators' precedencies.
- The operators' associativities.
- The list of tokens' types that represents variables.
- The list of tokens' types that represents functions.
- The list of tokens' types that represents operators.
- The token's type that represents the parameters separator.
- The token's type that represents the start of a list of parameters (typically "(").
- The token's type that represents the end of a list of parameters (typically ")").
WARNING
Make sure to double all characters "
\" within the regular expressions that define the tokens. That is:'/\s/'becomes'/\\s/'.
Be aware that the order of declarations of the tokens is important (see the documentation for the class dbeurive\Lexer\Lexer)).
The synopsis should be clear enough. You can also consult the example.
dbeurive/shuntingyard 适用场景与选型建议
dbeurive/shuntingyard 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 98 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 11 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「infix」 「RPN」 「shunting-yard」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dbeurive/shuntingyard 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dbeurive/shuntingyard 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dbeurive/shuntingyard 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Simple mathematical expression/equation parser and calculator.
An extensible mathematical expression parser and evaluator.
Simple mathematical expression parser and calculator.
Reverse Polish Notation
Simple mathematical expression parser and calculator.
Library to transform a Doctrine lexer into a RPN expression and solve it
统计信息
- 总下载量: 98
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-11-23