Re: Simple expression parser for PHP. [message #179781 is a reply to message #179776] |
Tue, 04 December 2012 18:20 |
Daniel Pitts
Messages: 68 Registered: May 2012
Karma:
|
Member |
|
|
On 12/4/12 4:49 AM, Anders Wegge Keller wrote:
> Daniel Pitts <newsgroup(dot)nospam(at)virtualinfinity(dot)net> writes:
>
>> My trouble here is not that I'm trying to look smarter, but that I'm
>> trying to minimize exposing proprietary information of my employer.
>
> You are not going to get any real help, until you present an example
> of what you need to parse. Or at least something close enough to the
> real thing, as to make sense.
>
> I understand you desire to keep proprietary information private, but
> as long as you are only able to provide vague generalities, you're not
> going to get anything but vague generalities for answers.
>
> One general answer is to look at
> http://pear.php.net/package/PHP_ParserGenerator and see if that is
> suitable for you, even though it's unmaintained.
>
I actually did find that pear package. I was hoping to avoid creating
my own grammar. The goal was to see if there was something we could use
out-of-the-box.
If I'm going to go through the trouble of creating my own grammar, I'd
probably write it in C instead of PHP, and just plug that in.
My "vague generalities" I've given are real use-cases. Perhaps I didn't
explain them enough...
Given objects (or associative arrays) Foo and Bar. I'd like to have
some call such as:
$expression = "foo['somePropertyOfFoo'] * 3";
$context = initContext(array("foo"=>$Foo, "bar"=>$Bar); // or whatever.
$result = $expressionEvaluator->evaluate($expression, $context);
This particular snippet would result in the same value as
$Foo['somePropertyOfFoo'] * 3.
where $expression is actually read from a configuration parameter somewhere.
I also need some sort of basic function calling support, even it that
requires setting up the available functions before hand.
Hopefully that makes the most sense.
|
|
|