zircote / expressive
此包最新版本(dev-master)无可用许可证信息。
PHP文本表达式解析器,解析字符串中的数学表达式并返回结果
dev-master
2013-12-17 01:37 UTC
This package is not auto-updated.
Last update: 2024-09-14 13:18:03 UTC
README
PHP表达式解析器。这个工具很大程度上受到了我在网上搜索某种形式的表达式DSL时遇到的代码片段的启发。这种方法的灵感足够让我觉得它值得分享。不幸的是,这些片段没有名字,因此我无法将启发性的工作归功于其发起者。
用法
内联PHP
<?php $expression = new \Expressive\Parser('(2+2)*sqrt(4)'); echo $expression; // 8
命令行界面(CLI)
这是一个示例用法
> bin/expr
math > (2+2)*sqrt(4)
8
math > exit
>
支持的操作
+
加法2+2
-
减法4-2
/
除法4/2
*
乘法2*2
^
指数2^2
sin
正弦sin(60)
cos
余弦cos(90)
tan
正切tan(45)
sqrt
平方根sqrt(4)
exp
指数exp(12)