in reply to Re: RFC: Module for evaluation math. expressions
in thread RFC: Module for evaluation math. expressions

Breaking The Rules II is of interest indeed.

My parser consists of a self made lexer and a recursive descending parser. The code is quite lengthy, but not really complicated.

Parsing and evaluation are different steps indeed, you can do something like

use Data::Dumper; my $m = Math::Light::Expression->new; $m->parse($expression); print Dumper $m->{ast}; for (0 .. 9) { print $val->({ a => $_ }), "\n"; # evaluate multiple times }

I experimented with a LaTeX emitting backend, but that goes against the grain of keeping modules small and doing exactly what they are meant for.

I considered a PIR emitter as well, but PIR handles precedence on its on, so there is now real need to for my parser ;-)

Replies are listed 'Best First'.
Re^3: RFC: Module for evaluation math. expressions
by tsee (Curate) on Sep 07, 2007 at 21:06 UTC

    Math::Symbolic::Custom::LaTeXDumper can dump Math::Symbolic trees to LaTeX, but while the basic transformation is trivial, generating good-looking formulas automatically is extremely hard. That aforementioned module doesn't extend a lot of cycles on being too smart, but it works okay for reasonably simple formulas.

    Cheers,
    Steffen