waughj/math-parser
Composer 安装命令:
composer require waughj/math-parser
包简介
Simple Lisp-like math parser.
README 文档
README
Simple Lisp-like math parser.
Example
use WaughJ\MathParser\MathParser;
$math = new MathParser();
echo( $math->parse( '(+ 2 2)' ) );
Prints "4".
To use a different parser:
use WaughJ\MathParser\MathParser;
$math = new MathParser( new LisphpParser( [ ',' ] ) );
echo( $math->parse( '(*,2,5)' ) );
Prints "10".
To create a new custom function:
use WaughJ\MathParser\MathParser;
use WaughJ\MathParser\MathParserExceptionInvalidFunctionCall;
$math = new MathParser();
$math->addFunction
(
'double',
function( array $args )
{
$arg_count = count( $args );
if ( $arg_count < 1 )
{
throw new MathParserExceptionInvalidFunctionCall
(
"Call to function “double” given no arguments. Needs at least 1."
);
}
return array_shift( $args ) * 2;
}
);
echo( $math->parse( '(double 222)' ) );
Prints "444".
Changelog
0.1.0
- Initial stable version.
统计信息
- 总下载量: 19
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2019-04-11