FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Simple expression parser for PHP.
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Simple expression parser for PHP. [message #179761 is a reply to message #179759] Mon, 03 December 2012 20:30 Go to previous messageGo to previous message
Daniel Pitts is currently offline  Daniel Pitts
Messages: 68
Registered: May 2012
Karma:
Member
On 12/3/12 11:59 AM, Thomas 'PointedEars' Lahn wrote:
> Daniel Pitts wrote:
>
>> On 12/2/12 3:45 AM, Thomas 'PointedEars' Lahn wrote:
>>> Daniel Pitts wrote:
>>>> On 12/1/12 9:58 AM, Thomas 'PointedEars' Lahn wrote:
>>>> > Daniel Pitts wrote:
>>>> >> I have a requirement that I need to take an expression and evaluate
>>>> >> it.
>>>> >>
>>>> >> I'd very much like to avoid using PHP's eval(), for obvious
>>>> >> reasons.
>>>> >> I'm kind of looking for something that is similar to OGNL (a Java
>>>> >> library for expressions).
>>>> >>
>>>> >> Speed is a plus, ease of integration is a nice-to-have. Low bug
>>>> >> density and active community is also a plus.
>>>> >
>>>> > What kind of expression are you talking about?
>>>>
>>>> Things along the lines of "request['some_attribute']" or "3 * someValue"
>>>> etc... Where I can specify the objects available to act upon ('request'
>>>> in the first example, 'someValue' in the second).
>>>>
>>>> Some method of traversing object graphs would be useful as well. Like I
>>>> said, something similar to OGNL, but for PHP instead.
>>>
>>> What do you need this for?
>> A program I'm writing. What's it to you?
>
> I am someone who could help you solve this problem.
>
>> I've given the specific requirements. ;-)
>
> ISTM you want a person writing or finding that software for you without any
> real effort on your part. If so, you are wrong here; there are smart but
> starving PHP developers out there who you should *pay* for that instead.
> The smiley does not change anything.
I am, of course, trying to do this with the least amount of effort on my
part possible. A lazy engineer is an efficient engineer ;-). This is
part of a rather large project for the rather large company I work for,
so we are already paying PHP developers. I'm not asking for anyone to
create something for free, only trying to find out what is already out
there. An hour of googling didn't really turn up much, so I thought I'd
turn to the community.

>> More specifically, it is to ease configuration of my program. The
>> expressions are going to be embedded into a DSL (domain-specific
>> language) for declaring a part of the business logic.
>
> I would suggest you look more into the features of PHP instead of inventing
> another OGNL-like expression language to be parsed with PHP. Without
> knowing OGNL [1] well or having used it before, ISTM that many of the things
> that OGNL extends Java syntax with are built into PHP these days.
Perhaps.
>
> For example, accessing properties instead of calling methods is facilitated
> with the __get() and __set() magic methods. [2] PHP 5.4 even allows
> accessing the items of array return values directly, which allows for
> “$root->foo()["bar"]” or “$root->foo()[0]”. [3] (For PHP 5.3 there can be a
> fallback, line “$root->foo()->items(0)”).
Sure it can access a single value, but can you do math in that as well?
String concatenation?
For example, I may have an expression such as: $myObject['someValue'] * 3

>
> Further inspiration, which is probably going to use closures (introduced in
> PHP 5.3, improved in PHP 5.4 [3]), can be drawn from Microsoft LINQ [4];
> there is an implementation of that in PHP already [5]. Even if that is not
> useful to you, writing that parser (using PHP's PCRE support [6]) should not
> be too difficult a task.
>
>> I'm trying to avoid using "eval" or forcing someone to write a PHP
>> function and reference that function by name.
>
> I can understand that and, JFYI, I had understood that already.
>
>> Most of the time, the expressions are so simple, and only make sense in
>> the context they appear in the DSL.
>
> If you say so.
Even if I don't say so, this is a fact of my project.


In any case, thanks for all the links, I'll look through the ones I
don't know anything about for inspiration.
>
>
> PointedEars
> ___________
> [1] <http://commons.apache.org/ognl/>
> [2] <http://php.net/manual/en/language.oop5.magic.php>
> [3] <http://php.net/manual/en/migration54.new-features.php>
> [4] <http://msdn.microsoft.com/en-us/library/vstudio/bb397926.aspx>
> [5] <http://phplinq.codeplex.com/>
> [6] <http://php.net/manual/en/book.pcre.php>
>
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How to run program from php..?
Next Topic: Old version trouble with $_SERVER variables?
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Wed Nov 27 08:36:06 GMT 2024

Total time taken to generate the page: 0.09437 seconds