RE: [PEAR-DEV] Package Proposal: Math_RPN

From: Date: Mon, 26 May 2003 09:54:48 +0000
Subject: RE: [PEAR-DEV] Package Proposal: Math_RPN
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-16699@lists.php.net to get a copy of this message
I'm impressed. At we work we did a simple postfix to RPN converter class then a class to interpret the resulting RPN. It is used as a part of a rule engine to determine wether a rule if true or not and take specific actions upon result. But the code is not as nice ! One thing 'd love to see is to be able to specify a custom operator. I see there is getOperators, would it be possible to have a setOperator ? Thus not having to extend the class and redefine the _rules array. Added to that i think it is not necessary for you to extend from pear. Just add your own raiseError pethod which will include PEAR class when needed, thus saving overhead. Other than that +1. Arnaud. > Hi, > I wrote a class that can make and calculate a RPN (reversed polish > notation) expression. > RPN is formal logic system which allowed mathematical > expressions to be > specified without parentheses by placing the operators before > or after the > operands. > For example 2+5*7 in RPN looks 2,5,7,*,+ > > You can take a look at the source code and example here: > http://www.maciek.maribex.wizja.net.pl/rpn/ > > Sample usage: > > $expression = '(3+2)*(7-sin(30)*log(10))'; > > require_once 'Math/RPN.php'; > > $rpn = new RPN(false); > > $value = $rpn->getValue($input); // 32.5 > > Any questions, comments, or suggestions? > > Regards, > Maciek Szczytowski > admin@e-rower.pl >

« previous php.pear.dev (#16699) next »