Classes

  Class Description
ComponentSet
Jep uses a set of components to parse and evaluate. They are:
  • INumberFactory
  • VariableFactory
  • NodeFactory
  • VariableTable
  • FunctionTable
  • OperatorTable
  • IParser
  • IEvaluator
  • PrintVisitor
EvaluationException
Thrown when a exception is encountered during the evaluation process.
FunctionTable
A table holding details of the functions known to Jep.
JepException
Base class for all exceptions thrown by Jep
JepInstance

The Jep class is the main interface with which the user should interact. It contains all necessary methods to parse and evaluate expressions.

To evaluate an expression, simply call the Parse(String) and Evaluate methods after each other. The following code snippet shows a parsing and evaluating a simple expression with a single variable:

Examples

CopyC#
JepInstance jep = new JepInstance();
jep.AddVariable("x", 10);
try {
    jep.Parse("x+1");
    Object result = jep.Evaluate();
    System.Console.Out.WriteLine("x + 1 = " + result);
} catch (Exception e) {
    System.Console.Out.WriteLine("An error occured: " + e.getMessage());
}

The class is serializable. Please see the documentation section "Serialization" for more information on the various options for serializing.

NodeFactory
This class is used to create nodes of specified types. It can be sub-classed to change the nature of how nodes are constructed. Generally there are two methods for creating nodes, methods which take an existing node and methods which take the components.
Operator
An Operator with additional information about its commutativity etc.

Operators have a number of properties:

  • A symbol or name of the operator "+".
  • The number of arguments NO_ARGS 0, UNARY 1 (e.g. UMINUS -x), BINARY 2 (e.g. x+y), and NARY either 3 ( a>b ? a : b) or unspecified like a list [x,y,z,w].
  • The binding of the operator, LEFT 1+2+3 -> (1+2)+3 or RIGHT 1=2=3 -> 1=(2=3).
  • Whether the operator is ASSOCIATIVE or COMMUTATIVE.
  • The precedence of the operators + has a higher precedence than *.
  • For unary operators they can either be PREFIX like -x or SUFFIX like x%.
  • Comparative operators can be REFLEXIVE, SYMMETRIC, TRANSITIVE or EQUIVALENCE which has all three properties.
  • A reference to a PostfixtMathCommandI object which is used to evaluate an equation containing the operator.
Various is... and get... methods are provided to query the properties of the operator.

OperatorTable
Stores a list of operators.
ParseException
Thrown when a exception is encountered during the parse process.
PrintVisitor
Prints an expression. Prints the expression with lots of brackets. ((-1.0)/sqrt((1.0-(x^2.0)))).

Examples

To use
CopyC#
JepInstance j = ...; INode in = ...;
j.Print(in, "x");
Variable
Information about a variable. Each variable has a name, and a value.

There is a flag to indicate whether it is a constant or not (constants cannot have their value changed). There is also a flag to indicate whether the value of the variable is valid. If the variable is initialized without a value then its value is said to be invalid.

This class extends java.util.Observable allowing observers to track if the variable value has been changed. Use addObserver(Observer o) to add an observer. When the variable value is changed the Observer's update(o, arg) method is called, the first argument is the Variable object and the second is the object representing the new value.

VariableFactory
A factory class which is used to create variables.

By default this class creates variables of type Variable. This class should be sub-classed if the type of variable used needs to be changed.

This class is passed to the constructor of VariableTable which ensures that variables of the correct type are always created.

This class should only be called from the VariableTable class and not from application code.
VariableTable
A table of variables.

This class implements Observable and observers will be notified when new variables are added, or removed, but not when their values are changed. Use Variable.AddObserver() to monitor individual variables.

Interfaces

  Interface Description
IEvaluator
Basic interface for evaluators
IJepComponent
Base interface for all Jep components (parsers, evaluators etc).
INumberFactory
This interface can be implemented to create numbers of any object type. By implementing this interface and calling the setNumberFactory() method of the JEP class, the constants in an expression will be created with that class.
IParser
Basic interface for a Jep parser
IParserVisitor
Basic interface that all ParserVisitors must implement.
IPostfixMathCommand
Interface for a postfix math command.
PrintVisitor..::.IPrintRules
This interface specifies the method needed to implement a special print rule. A special rule must implement the append method, which should call pv.append to add data to the output. For example

Examples

CopyC#
pv.AddSpecialRule(Operator.OP_LIST,new PrintVisitor.IPrintRules()
{
    public void Append(INode node, PrintVisitor pv) throws ParseException
    {
        pv.Append("[");
        for(int i=0;i<node.JjtGetNumChildren();++i)
        {
            if(i>0) pv.Append(",");
            node.JjtGetChild(i).JjtAccept(pv, null);
        }
        pv.append("]");
    }});