ls-a/arithmetic-ast
Composer 安装命令:
composer require ls-a/arithmetic-ast
包简介
Implements the Shunting Yard Algorithm and creates an Abstract Syntax Tree with arithmetic operations
README 文档
README
This documentation is also available in these languages:
This library provides a implementation of Abstract Syntax Tree for arithmetic operations.
For more information, see these links:
- https://en.wikipedia.org/wiki/Abstract_syntax_tree
- https://en.wikipedia.org/wiki/Reverse_Polish_notation
- https://en.wikipedia.org/wiki/Shunting_yard_algorithm
Code sample:
<?php $tokens = [ TokenParser::parse('1 + 2 * 3'), TokenParser::parse('1 + (2 * 3 % 5 - (2 + 3 + 4) + (5 / 2)) + (3 * 4)'), TokenParser::parse('(mock(1, 2) + 2.6) / 2'), TokenParser::parse('mock-with-dashes(mock-with-dashes(mock-with-dashes(2)))') ];
Features
This library includes :
- Support for following operators :
+,-,*,/,% - Allowance to create new operators, with custom symbols, whether single character or string
- Unary operator managament
- Functions support
- Function string parameters
- Variadic function parameters
- Support for following units:
mm,cm,pt,pc,in,%and related converters, plus support to create your own
For every operation, you can use evaluate method to get its result.
Why?
First, because why not? We could not find an arithmetic abstract syntax tree on composer and felt it was missing.
Next, for a little background, this package is used in XSL-Core package, to handle various XML function calls in attributes.
Installation
This library is available on Composer. Install it with:
composer require ls-a/arithmetic-ast
Changelog
Please refer to the CHANGELOG file to see the latest changes.
Support
We put our heart into delivering high-quality products that are accessible to everyone. If you like our work, don’t hesitate to reach out to us for your next project!
Contributing
Contributions are governed by the CONTRIBUTING file.
Security
If you’ve found a bug or vulnerability, please contact us by email at contact@ls-a.fr instead of opening an issue, in order to protect the security of other users.
Credits
- Renaud Berthier
License
The MIT License (MIT). Please see License File for more information.
ls-a/arithmetic-ast 适用场景与选型建议
ls-a/arithmetic-ast 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 65 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 11 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「math」 「utils」 「ast」 「arithmetic」 「comparison」 「operation」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ls-a/arithmetic-ast 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ls-a/arithmetic-ast 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ls-a/arithmetic-ast 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
LaTeX formula to PNG
Editable JSON AST with visitor traversal and formatting-preserving printing.
Parse Handlebars templates to a spec-compliant AST with PHP.
n2n test utils
A collection of enhancements and utilities for the Silverstripe UserForms module
统计信息
- 总下载量: 65
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2025-11-11