Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #7716
| Newsgroups | comp.lang.php |
|---|---|
| Subject | Re: Simple expression parser for PHP. |
| References | (4 earlier) <Wi5vs.31351$Sm5.28145@newsfe25.iad> <k9j2ms$kp8$1@news.albasani.net> <d0bvs.3$Id.0@newsfe24.iad> <87a9tu2d9i.fsf@huddi.jernurt.dk> <T9rvs.6982$TH3.4844@newsfe12.iad> |
| From | Anders Wegge Keller <wegge@wegge.dk> |
| Date | 2012-12-04 19:52 +0100 |
| Message-ID | <87624h3b0f.fsf@huddi.jernurt.dk> (permalink) |
| Organization | SunSITE.dk - Supporting Open source |
Daniel Pitts <newsgroup.nospam@virtualinfinity.net> writes:
> On 12/4/12 4:49 AM, Anders Wegge Keller wrote:
> > Daniel Pitts <newsgroup.nospam@virtualinfinity.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...
I miss at least one thing: How complex expressions do you need to
handle? If you can impose a limitation to very simple expressions, you
might be able to handle them with a set of regular expressions instead
of a tokenizer. But the complexity of that will grow exponentially, so
you'd pretty soon want to do something else.
> 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.
Apart from the complexity of the expressions, I'd say build your own
lexer and parser. *OR* if you have your own choice of DSL, see if you
can use Lua. <http://php.net/manual/en/book.lua.php>
By using lua, you can isolate your DSL from the rest of the
application, which I guess is one concern, since you started by asking
for a way to avoid eval().
--
/Wegge
Leder efter redundant peering af dk.*,linux.debian.*
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Simple expression parser for PHP. Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-11-30 15:56 -0800
Re: Simple expression parser for PHP. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-01 18:58 +0100
Re: Simple expression parser for PHP. Allodoxaphobia <knock_yourself_out@example.net> - 2012-12-01 18:09 +0000
Re: Simple expression parser for PHP. Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-12-01 11:06 -0800
Re: Simple expression parser for PHP. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-02 12:45 +0100
Re: Simple expression parser for PHP. Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-12-03 09:28 -0800
Re: Simple expression parser for PHP. Shake <QUITAESTO@QUITAESTO.NOES> - 2012-12-03 18:44 +0100
Re: Simple expression parser for PHP. Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-12-03 10:06 -0800
Re: Simple expression parser for PHP. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-03 21:04 +0100
Re: Simple expression parser for PHP. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-03 20:59 +0100
Re: Simple expression parser for PHP. Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-12-03 12:30 -0800
Re: Simple expression parser for PHP. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-03 23:09 +0100
Re: Simple expression parser for PHP. The Natural Philosopher <tnp@invalid.invalid> - 2012-12-03 20:39 +0000
Re: Simple expression parser for PHP. Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-12-03 15:58 -0800
Re: Simple expression parser for PHP. Jerry Stuckle <jstucklex@attglobal.net> - 2012-12-03 20:50 -0500
Re: Simple expression parser for PHP. Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-12-03 18:40 -0800
Re: Simple expression parser for PHP. "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-12-04 09:49 +0100
Re: Simple expression parser for PHP. The Natural Philosopher <tnp@invalid.invalid> - 2012-12-04 09:34 +0000
Re: Simple expression parser for PHP. Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-12-04 10:09 -0800
Re: Simple expression parser for PHP. The Natural Philosopher <tnp@invalid.invalid> - 2012-12-04 03:52 +0000
Re: Simple expression parser for PHP. Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-12-03 22:24 -0800
Re: Simple expression parser for PHP. Anders Wegge Keller <wegge@wegge.dk> - 2012-12-04 13:49 +0100
Re: Simple expression parser for PHP. Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-12-04 10:20 -0800
Re: Simple expression parser for PHP. Anders Wegge Keller <wegge@wegge.dk> - 2012-12-04 19:52 +0100
Re: Simple expression parser for PHP. Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-12-03 17:18 -0800
Re: Simple expression parser for PHP. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-04 11:55 +0100
Re: Simple expression parser for PHP. Tim Streater <timstreater@greenbee.net> - 2012-12-04 10:58 +0000
Re: Simple expression parser for PHP. Scott Johnson <noonehome@chalupasworld.com> - 2012-12-04 05:54 -0800
Re: Simple expression parser for PHP. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-04 15:29 +0100
Re: Simple expression parser for PHP. Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-12-04 10:25 -0800
Re: Simple expression parser for PHP. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-12-04 23:23 +0100
Re: Simple expression parser for PHP. Scott Johnson <noonehome@chalupasworld.com> - 2012-12-04 23:58 -0800
Re: Simple expression parser for PHP. Jerry Stuckle <jstucklex@attglobal.net> - 2012-12-04 10:36 -0500
Re: Simple expression parser for PHP. The Natural Philosopher <tnp@invalid.invalid> - 2012-12-05 09:24 +0000
Re: Simple expression parser for PHP. Scott Johnson <noonehome@chalupasworld.com> - 2012-12-06 16:53 -0800
Re: Simple expression parser for PHP. Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2012-12-10 09:40 -0800
csiph-web