A powerful mathematical expression parser and evaluator for PHP featuring variable substitution, user-defined constants, functions, deterministic functions, macros, operators, and compiler optimizations.
GPL-3.0 License
Bot releases are visible (Hide)
Published by Muqsit 3 months ago
<=>
) cannot be stringified (73fe866fa26cf8605073d56363e2ec0074d9769d)Published by Muqsit 3 months ago
>
>=
<
<=
<=>
==
!=
===
!==
) (#9) (https://github.com/Muqsit/arithmexp/commit/427e2f4bc45b66ba4bcdee002808b5a41e777ed6)!
&&
||
and
or
xor
) (#9) (https://github.com/Muqsit/arithmexp/commit/77f988c1c90e6dff2130c816c61aec5fb9d4e16b)is_bool
is_float
is_finite
is_infinite
is_nan
boolval
intval
floatval
) (https://github.com/Muqsit/arithmexp/commit/fdcb6cebf83a2cf11ab27a27a9af7651d9904a37)Published by Muqsit almost 2 years ago
(a % n) % n
=> a % n
) (bca7b1719618c4fd316cb5bc380069ea4616a747, 98535479ae9a4b6e74dbe448d33ab74bf77b8657)rand()
and getrandmax()
(these functions exist in PHP only for backward compatibility) (ce8dfb3dc46e2cc7ee30a13febb7e802994301d9)mt_rand()
now accepts zero parameters (in addition to accepting two parameters) (8194bf3c279e4699df95457996dc482e6bc9a9bd, f73be6140e42007a4ed9fe7d423dfc113ebab758)round()
(HALF_UP
, HALF_DOWN
, HALF_EVEN
, HALF_ODD
) (c21ce74f35dde4b3af8fe383cf9d48fa68198882, 90c0f5df57f4c53ccd39514898541d1926ece790)FunctionRegistry::register()
to FunctionRegistry::registerFunction()
(ad076413b326ded9bd3a5f43ff83544d941aa9f5)ConstantRegistry::register()
to ConstantRegistry::registerLabel()
(1b0d2d575c0a636476eb85ccbce7fd029e6b289a)FunctionRegistry::registerMacro()
to MacroRegistry::registerFunction()
(0d0889fdcaefb5d1e443c8aee1b492dcaa087f75)MacroRegistry::registerObject()
(34e5ad71836b74a686130acfd2a720abcce01679)Published by Muqsit almost 2 years ago
Published by Muqsit almost 2 years ago
Parser::getOperatorManager()
(4ff725f3b958a2372668729195193438880b73e1)
Parser::getBinaryOperatorRegistry()
with Parser::getOperatorManager()->getBinaryRegistry()
Parser::getUnaryOperatorRegistry()
with Parser::getOperatorManager()->getUnaryRegistry()
0 / 0
returning int(0)
with optimizations (167297038be3529e90d554abe6027fbbf6be18ef)Published by Muqsit almost 2 years ago
Published by Muqsit about 2 years ago
[]
and curly brackets {}
are now considered as valid in expressions) (#13, thanks @NhanAZ!)Published by Muqsit about 2 years ago
FunctionRegistry::register()
(d003841c373b003f3fa2c2e15f25dad23e321460)lvalue=0
resulted in rvalue
instead of -rvalue
(#11, 4f4aaea17a350385b2637fed9d5eaf645f2de745, 029e47001543ab3928ad19662d2b0de90fcb03a4) (thanks @sylvrs!)Published by Muqsit about 2 years ago
a ** m / a ** n =
a ** (m - n)`) in strength reduction optimization (757e7b05ea6cf2e4fa5517f293db92a32f485cdc)min(pi())
) (4d334144960ca02c92aaa0c82ce8a04c774f93e6)Published by Muqsit about 2 years ago
Expression::getVariables()
has been renamed to Expression::findVariables()
2
with itself resulted expression executing indefinitelyPublished by Muqsit about 2 years ago
Published by Muqsit about 2 years ago
min
and max
no longer throw an error when only 1 parameter is suppliedPublished by Muqsit about 2 years ago
ParseException
during parsingPublished by Muqsit about 2 years ago
BinaryOperator
s can now be checked for commutativity through BinaryOperator::isCommutative()
Published by Muqsit about 2 years ago
x - x
to 0
1 ** x
to 1
Parser::parseRawExpression()
Parser::createUnoptimized()->parse()
may be used insteadPublished by Muqsit about 2 years ago
Published by Muqsit about 2 years ago
RuntimeException
during parsingPublished by Muqsit about 2 years ago
ParseException
now highlights the problematic substring within the expression along with displaying the exception message
Fatal error: Uncaught muqsit\arithmexp\ParseException: Cannot resolve function call at "mt_rand(3, 4, 5)" (34:50) in "x + min(mt_rand(1, 3), mt_rand(2, mt_rand(3, 4, 5)), 7) * y": Too many parameters supplied to function call: Expected 2 parameters, got 3 parameters
Fatal error: Uncaught muqsit\arithmexp\ParseException: Cannot resolve function call at "mt_rand(3, 4, 5)" (34:50) in "x + min(mt_rand(1, 3), mt_rand(2, mt_rand(3, 4, 5)), 7) * y": Too many parameters supplied to function call: Expected 2 parameters, got 3 parameters
| x + min(mt_rand(1, 3), mt_rand(2, mt_rand(3, 4, 5)), 7) * y
| ^^^^^^^^^^^^^^^^
muqsit@*********:~/arithmexp/tests$ php test3.php "x + min(mt_rand(1, 3), mt_rand(2, mt_rand(3, 4, 5)), 7) * y"
Fatal error: Uncaught muqsit\arithmexp\ParseException: Cannot resolve function call at "mt_rand(3, 4, 5)" (34:50) in "x + min(mt_rand(1, 3), mt_rand(2, mt_rand(3, 4, 5)), 7) * y": Too many parameters supplied to function call: Expected 2 parameters, got 3 parameters
| x + min(mt_rand(1, 3), mt_rand(2, mt_rand(3, 4, 5)), 7) * y
| ^^^^^^^^^^^^^^^^ in /home/muqsit/arithmexp/tests/vendor/muqsit/arithmexp/src/muqsit/arithmexp/ParseException.php:32
Stack trace:
#0 /home/muqsit/arithmexp/tests/vendor/muqsit/arithmexp/src/muqsit/arithmexp/ParseException.php(144): muqsit\arithmexp\ParseException::generateWithHighlightedSubstring(Object(muqsit\arithmexp\ParseException))
#1 /home/muqsit/arithmexp/tests/vendor/muqsit/arithmexp/src/muqsit/arithmexp/Parser.php(352): muqsit\arithmexp\ParseException::unresolvableFcallTooManyParams('x + min(mt_rand...', Object(muqsit\arithmexp\token\FunctionCallToken), Object(muqsit\arithmexp\function\FunctionInfo), 3)
#2 /home/muqsit/arithmexp/tests/vendor/muqsit/arithmexp/src/muqsit/arithmexp/Parser.php(283): muqsit\arithmexp\Parser->transformFunctionCallTokens('x + min(mt_rand...', Array)
#3 /home/muqsit/arithmexp/tests/vendor/muqsit/arithmexp/src/muqsit/arithmexp/Parser.php(283): muqsit\arithmexp\Parser->transformFunctionCallTokens('x + min(mt_rand...', Array)
#4 /home/muqsit/arithmexp/tests/vendor/muqsit/arithmexp/src/muqsit/arithmexp/Parser.php(283): muqsit\arithmexp\Parser->transformFunctionCallTokens('x + min(mt_rand...', Array)
#5 /home/muqsit/arithmexp/tests/vendor/muqsit/arithmexp/src/muqsit/arithmexp/Parser.php(283): muqsit\arithmexp\Parser->transformFunctionCallTokens('x + min(mt_rand...', Array)
#6 /home/muqsit/arithmexp/tests/vendor/muqsit/arithmexp/src/muqsit/arithmexp/Parser.php(283): muqsit\arithmexp\Parser->transformFunctionCallTokens('x + min(mt_rand...', Array)
#7 /home/muqsit/arithmexp/tests/vendor/muqsit/arithmexp/src/muqsit/arithmexp/Parser.php(283): muqsit\arithmexp\Parser->transformFunctionCallTokens('x + min(mt_rand...', Array)
#8 /home/muqsit/arithmexp/tests/vendor/muqsit/arithmexp/src/muqsit/arithmexp/Parser.php(283): muqsit\arithmexp\Parser->transformFunctionCallTokens('x + min(mt_rand...', Array)
#9 /home/muqsit/arithmexp/tests/vendor/muqsit/arithmexp/src/muqsit/arithmexp/Parser.php(143): muqsit\arithmexp\Parser->transformFunctionCallTokens('x + min(mt_rand...', Array)
#10 /home/muqsit/arithmexp/tests/vendor/muqsit/arithmexp/src/muqsit/arithmexp/Parser.php(97): muqsit\arithmexp\Parser->processTokens('x + min(mt_rand...', Array)
#11 /home/muqsit/arithmexp/tests/test3.php(13): muqsit\arithmexp\Parser->parseExpression('x + min(mt_rand...')
#12 {main}
thrown in /home/muqsit/arithmexp/tests/vendor/muqsit/arithmexp/src/muqsit/arithmexp/ParseException.php on line 32
muqsit@*********:~/arithmexp/tests$ php test3.php "x + min(mt_rand(1, 3), mt_rand(2, mt_rand(3, 4, 5)), 7) * y"
Fatal error: Uncaught muqsit\arithmexp\ParseException: Cannot resolve function call at "mt_rand(3, 4, 5)" (34:50) in "x + min(mt_rand(1, 3), mt_rand(2, mt_rand(3, 4, 5)), 7) * y": Too many parameters supplied to function call: Expected 2 parameters, got 3 parameters
| x + min(mt_rand(1, 3), mt_rand(2, mt_rand(3, 4, 5)), 7) * y
| ^^^^^^^^^^^^^^^^ in /home/muqsit/arithmexp/tests/vendor/muqsit/arithmexp/src/muqsit/arithmexp/ParseException.php:32
Stack trace:
#0 /home/muqsit/arithmexp/tests/vendor/muqsit/arithmexp/src/muqsit/arithmexp/ParseException.php(144): muqsit\arithmexp\ParseException::generateWithHighlightedSubstring(Object(muqsit\arithmexp\ParseException))
#1 /home/muqsit/arithmexp/tests/vendor/muqsit/arithmexp/src/muqsit/arithmexp/Parser.php(337): muqsit\arithmexp\ParseException::unresolvableFcallTooManyParams('x + min(mt_rand...', Object(muqsit\arithmexp\token\FunctionCallToken), Object(muqsit\arithmexp\function\FunctionInfo), 3)
#2 /home/muqsit/arithmexp/tests/vendor/muqsit/arithmexp/src/muqsit/arithmexp/Parser.php(143): muqsit\arithmexp\Parser->transformFunctionCallTokens('x + min(mt_rand...', Array)
#3 /home/muqsit/arithmexp/tests/vendor/muqsit/arithmexp/src/muqsit/arithmexp/Parser.php(97): muqsit\arithmexp\Parser->processTokens('x + min(mt_rand...', Array)
#4 /home/muqsit/arithmexp/tests/test3.php(13): muqsit\arithmexp\Parser->parseExpression('x + min(mt_rand...')
#5 {main}
thrown in /home/muqsit/arithmexp/tests/vendor/muqsit/arithmexp/src/muqsit/arithmexp/ParseException.php on line 32