library expressive
A PHP textual expression parser, parses strings for mathematical expressions and returns the result
zircote/expressive
A PHP textual expression parser, parses strings for mathematical expressions and returns the result
- Tuesday, December 17, 2013
- by zircote
- Repository
- 0 Watchers
- 5 Stars
- 44 Installations
- PHP
- 0 Dependents
- 0 Suggesters
- 1 Forks
- 0 Open issues
- 1 Versions
- 7 % Grown
Expressive
, (*1)
A PHP expression parser. This tool was largely inspired by snips of code I came across
on the web while looking for some form of an expression DSL. The approach inspired me
enough to feel it deserved sharing. Unfortunately these snippets had no name associated
with them and I am therefor unable to attribute the inspirative work to its inceptor., (*2)
Use:
Inline PHP
<?php
$expression = new \Expressive\Parser('(2+2)*sqrt(4)');
echo $expression;
// 8
CLI:
this is intended more as an example use, (*3)
> bin/expr
math > (2+2)*sqrt(4)
8
math > exit
>
Supported Operations:
- + addition 2+2
- - substraction 4-2
- / division 4/2
- * multiplication 2*2
- ^ exponential 2^2
- sin sine sin(60)
- cos cosine cos(90)
- tan tangent tan(45)
- sqrt square root sqrt(4)
- exp exponent exp(12), (*4)
, (*5)
dev-master
9999999-dev
A PHP textual expression parser, parses strings for mathematical expressions and returns the result
Sources
Download