The best plan if you want to be really robust is to choose a parser package. Parse::RecDescent seems to be very popular. I used Parse::Lex to parse SGF files for Games::Go::SGF2misc, but it's a little tricky to get installed if things don't match up right.
| [reply] [Watch: Dir/Any] |
The first suggestion would be find out what expressions you want to support. Is it just the four basic arithmetic ops? What representations do you need of numbers (eg., base ten? Scientific notation like 8E6? Rationals? Arbitrary precision reals? Complex numbers?). Do you need precedence to work implicitly (eg., is "32 + 9/5 * x" "32 + ((9/5) * x)"? Or "((32 + 9)/5) * x"? Something else)? Do you need to allow arbitrary functions that you had defined earlier?
Depending on how simple your needs, you may be able to use a simple regular expression to do the parsing for you, or you may need something more involved. | [reply] [Watch: Dir/Any] |
Yeah, I would need to work within the set of reals, using transcendental functions as well as polynomials, rationals, etc..
| [reply] [Watch: Dir/Any] |
Then you should use a Real Parser to make sense of your expression. Parse::RecDescent was mentioned and is fine to use, if a little slow. Maybe you want to try this out in Perl 6 Rules though? You'd need Pugs for that, or perhaps stay in Perl 5 and give Pugs::Compiler::Rule a shot.
| [reply] [Watch: Dir/Any] |
| [reply] [Watch: Dir/Any] |
| [reply] [Watch: Dir/Any] |