in reply to RFC: Module for evaluation math. expressions

moritz,
I know there are some modules like that no CPAN

s/no/on/

You may find Breaking The Rules II of moderate interest. I would kind of like to see the parsing and the evaluation as different steps. That way, someone could come along and use it as a way to teach order of operations to a school kid. You hand them the parse tree and they can step through the evaluation.

Cheers - L~R

  • Comment on Re: RFC: Module for evaluation math. expressions

Replies are listed 'Best First'.
Re^2: RFC: Module for evaluation math. expressions
by moritz (Cardinal) on Sep 07, 2007 at 15:35 UTC
    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 ;-)

      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