Home  |  About Us  |  Link To Us  |  FAQ  |  Contact

# Math::Expr 0.2

Date Added: March 18, 2010  |  Visits: 572

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 > = [a-zA-Z][a-zA-Z0-9]*(:[a-zA-Z][a-zA-Z0-9]*)? < Function > = [a-zA-Z][a-zA-Z0-9]*(< Expr >(,< Expr >)*) < OpChr > = [^a-zA-Z0-9(),.:]+ 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::Expr This 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: No special requirements Platforms: Linux Keyword: Expr,  Libraries,  Mathematical,  Mathexpr,  Parse,  Parses,  Perl,  Perl Module,  Programming,  Variable Users rating: 0/10