[Israel.pm] embedding perl or not
jason.elbaum at gmail.com
Wed Feb 7 12:11:41 PST 2007
> Our current code knows how to support such simple conditions. But if we
> want to use complicated conditions like:
> (Example 2)
> COND:(cond1 || cond2) && cond3 (- and this is the simplest among
> Or to have in VALUE simple arithmetics (for example, VALUE: MAX_INT-1)
> then I need much more complicated parser.
Actually, I don't think the parser needs to be that much more
complicated. Parsing of boolean and arithmetic expressions is a
well-understood and frequently-implemented task. Any basic compiler or
parsing textbook will have some examples. Even the bison user's manual
Perl is a large and complex software system. Embedding Perl in C/C++
code is generally not trivial. Doing so just to support expression
parsing seems like overkill to me. I would only consider embedding
Perl if I planned to use more of Perl's power than that.
Also, keep in mind that Perl's expression syntax is probably far
richer than what you want to support in your init files. Do you want
your users to be able to insert arbitrary Perl expressions in those
files? (If so, great! If not, you'll need to roll your own expression
parser in Perl anyway.)
As Omer mentioned, other scripting languages are easier to embed, but
you still have to consider whether they support the syntax you want to
use for your config files. (You might look at Pawn; it has a C-style
If you're looking for a C++ library that supports parsing, I'd
recommend looking at Spirit (though it may also be overkill for this
task). If you're looking for a ready-made expression parser, I'm not
familiar with one but it might exist.
Personally, I'd just write the expression parser in yacc (bison) or Spirit.
More information about the Perl