Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

I'm looking for a module recommendation to parse an expression like:

(((A + B) x C) % D)

where the operators are not necessarily mathematical, I can handle the operators. I need to work from the inner-most parenthesis towards the outer-most. Working from inner to outer is the crucial aspect.

I couldn't come up with an RE to handle the problem. Text-Balanced didn't quite fit the bill here. Is Parse::RecDescent the way to go? It seems like overkill, is it even applicable to this type of problem? What's recommended?

thanks!

Replies are listed 'Best First'.
•Re: Parsing a Formula
by merlyn (Sage) on May 29, 2003 at 16:27 UTC
Re: Parsing a Formula
by pzbagel (Chaplain) on May 29, 2003 at 16:31 UTC

    Take a look at Math::Expr. That may be what you are looking for.

    HTH

Re: Parsing a Formula
by benn (Vicar) on May 29, 2003 at 16:30 UTC
    broquaint's suggestion here looks like the thing - Math::Expression. Haven't used it myself, but it comes highly recommended :)
    The "innermost-to-outermost" thing is how maths generally works anyway, so no problems there... :)
    Doh - read the question...thought it was about numerics... :)