Math::Expr

Math::Expr is a Perl module that parses mathematical expressions.
Download

Math::Expr Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Hakan Ardo
  • Publisher web site:
  • http://search.cpan.org/~hakanardo/DBIx-HTMLView-0.1/HTMLView.pm

Math::Expr Tags


Math::Expr Description

Math::Expr is a Perl module that parses mathematical expressions. Math::Expr is a Perl module that parses mathematical expressions.SYNOPSIS require Math::Expr; $p=new Math::Expr; $e=$p->Parse("a+4*b-d/log(s)+f(d,e)");Parses mathematical expressions into a tree structure. The expressions may contain integers, real numbers, alphanumeric variable names, alphanumeric function names and most other characters might be used as operators. The operators can even be longer than one character! The only limitation is that a variable or function name may not start on a digit, and not all chars are accepted as operations. To be exact, here is the grammatic (in perl regexp notation): < Expr > = -?< Elem >(< OpChr >< Elem >)* < Elem > = < Number >|< Var >|< Function >|(< Expr >) < Number > = < Integer >|< Float > < Integer > = d+ < Float > = d*.d+ < Var > = *(:*)? < Function > = *(< Expr >(,< Expr >)*) < OpChr > = +If the - sign is present at the beginning of an < Expr > it is parsed in the exact same structure as 0< Expr >. That is to allow constructions like "-a*b" or "b+3*(-7)".A variable consists of two parts separated by a ':'-char. The first part is the variable name, and the second optional part is its type. Default type is Real.METHODS$p = new Math::ExprThis is the constructor, it creates an object which later can be used to parse the strings.$e=$p->Parse($str)This will parse the string $str and return an expression tree, in the form of a Math::Expr::Opp object (or in simple cases only a Math::Expr::Var or Math::Expr::Num object).$p->Priority({'^'=>50, '/'=>40, '*'=>30, '-'=>20, '+'=>10})This will set the priority of ALL the operands (there is currently no way to change only one of them). The priority decides what should be constructed if several operands is listed without delimiters. Eg if a+b*c should be treated as (a+b)*c or a+(b*c). (Default is listed in header).$p->SetOppDB($db)Sets the OpperationDB to be used to $db. See Math::Expr::OpperationDB for more info. This will be passed down to all objects returned by the parser aswell.Requirements:· Perl Requirements: · Perl


Math::Expr Related Software