gridripper::math::expr::Expr Class Reference

Evaluates mathematical expressions or functions. More...

Inheritance diagram for gridripper::math::expr::Expr:

gridripper::math::expr::StkFunc gridripper::math::expr::StkOp

List of all members.

Public Member Functions

 Expr (String s) throws Error
 Construct a mathematical expression containing numbers only.
 Expr (String s, List< StkOp > f, StkOpRepository funcRep) throws Error
 Construct a function from the specified string and variables.
String getString ()
 Gets the expression as a string.
String getProgramListString ()
 Gets the "program" as a printable string.
double eval ()
 Evaluate the expression.
boolean isConstant ()
 Returns true if the expression is determined to be a constant.
boolean dependsOn (StkOp f)
 Returns true if the expression contains the specified function.
boolean dependsOnVariables ()
 Returns true if the expression uses external variables.
void replaceVar (String name, StkVar var)
 Replaces all occurances of a variable with another one in the program.
void evalStack (StkPointer sp0)
 Evaluates the stack.
StkOp[] getInternalProgram ()
 Gets the "program".
String getClassName ()
 Gets the class name.

Static Public Member Functions

static int findExprEnd (String str, int i)
 Finds end of subexpression starting at the specified character.

Classes

class  Error
 Exception thrown by the Expr constructor in case of syntax error.


Detailed Description

Evaluates mathematical expressions or functions.

Example:

f(x) = x^0.5*atan(1)/sqrt(pi)

<blockquote>

    StkOp vX = new StkVar("x");           // define variable
    List<StkOp> funcs = new ArrayList<StkOp>();
    funcs.add(vX);
    funcs.add(new StkConst("pi", Math.PI)); // define a constant
    try {
        Expr expr = new Expr("x^0.5*atan(1)/sqrt(pi)", funcs); // create Expr
        vX.value = 5; // set value of variable
        System.out.println("f(5) = " + expr.eval());  // calculate f(5)
    } catch(Expr.Error ex) {
        ex.printStackTrace();
    }
 
</blockquote>

Version:
GridRipper 0.5, 06/13/2009
Since:
GROMIT 0.2 (2001)
Author:
Peter Csizmadia

Constructor & Destructor Documentation

gridripper::math::expr::Expr::Expr ( String  s  )  throws Error [inline]

Construct a mathematical expression containing numbers only.

Parameters:
s the expression

gridripper::math::expr::Expr::Expr ( String  s,
List< StkOp f,
StkOpRepository  funcRep 
) throws Error [inline]

Construct a function from the specified string and variables.

Parameters:
s the expression
f extra functions and variables
funcRep function repository


Member Function Documentation

String gridripper::math::expr::Expr::getString (  )  [inline]

Gets the expression as a string.

Returns:
the expression

String gridripper::math::expr::Expr::getProgramListString (  )  [inline]

Gets the "program" as a printable string.

Useful for debugging.

Returns:
the program list

double gridripper::math::expr::Expr::eval (  )  [inline]

Evaluate the expression.

boolean gridripper::math::expr::Expr::dependsOn ( StkOp  f  )  [inline, virtual]

Returns true if the expression contains the specified function.

Subexpressions are also checked, recursively.

Reimplemented from gridripper::math::expr::StkFunc.

boolean gridripper::math::expr::Expr::dependsOnVariables (  )  [inline]

Returns true if the expression uses external variables.

void gridripper::math::expr::Expr::replaceVar ( String  name,
StkVar  var 
) [inline]

Replaces all occurances of a variable with another one in the program.

Parameters:
name the variable name
var the new variable

void gridripper::math::expr::Expr::evalStack ( StkPointer  sp0  )  [inline, virtual]

Evaluates the stack.

Parameters:
p the stack pointer

Implements gridripper::math::expr::StkFunc.

StkOp [] gridripper::math::expr::Expr::getInternalProgram (  )  [inline]

Gets the "program".

Returns:
the array of stack operations

String gridripper::math::expr::Expr::getClassName (  )  [inline, virtual]

Gets the class name.

Returns:
the class name

Reimplemented from gridripper::math::expr::StkFunc.


The documentation for this class was generated from the following file:

Generated on Wed Jun 17 18:47:29 2009 for GridRipper by  doxygen 1.5.6