org.jscience.ml.sbml.jep
Class JEP

java.lang.Object
  extended by org.jscience.ml.sbml.jep.JEP

public class JEP
extends java.lang.Object

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

The most important methods are parseExpression(String), for parsing the mathematical expression, and getValue() for obtaining the value of the expression.

Visit http://jep.sourceforge.net/ for the newest version of JEP, and complete documentation. This is an edited and enhanced version not aligned with the sourceforge project.


Field Summary
protected  java.util.Vector errorList
          Error List
protected  FunctionTable funTab
          Function Table
protected  boolean implicitMul
          Implicit multiplication option
protected  java.util.Hashtable symTab
          Symbol Table
 
Constructor Summary
JEP()
          Creates a new JEP instance with the default settings.
JEP(boolean traverse_in, boolean allowUndeclared_in, boolean implicitMul_in, NumberFactory numberFactory_in)
          Creates a new JEP instance with custom settings.
 
Method Summary
 void addFunction(java.lang.String functionName, PostfixMathCommandI function)
          Adds a new function to the parser.
 void addStandardFunctions()
          Adds the standard functions to the parser.
 java.lang.String getErrorInfo()
          Reports information on the errors that occured during the most recent action.
 NumberFactory getNumberFactory()
          Returns the number factory.
 java.lang.String getSBMLString(java.lang.String expression_in)
           
 Node getTopNode()
          Returns the top node of the expression tree.
 java.util.Enumeration getVariables()
           
 java.util.Enumeration getVariablesInExpression(java.lang.String eq)
          Gets the variables in the given equation.
 boolean hasError()
          Returns true if an error occured during the most recent action (parsing or evaluation).
 void initFunTab()
          Creates a new FunctionTable object as funTab.
 boolean isFunction(java.lang.String s)
           
static boolean isMathMLFunction(java.lang.String s)
           
 void parseExpression(java.lang.String expression_in)
          Parses the expression.
 java.lang.Object removeFunction(java.lang.String name)
          Removes a function from the parser.
 void setImplicitMul(boolean value)
          Sets the value of the implicit multiplication option.
 void setTraverse(boolean value)
          Sets the value of the traverse option. setTraverse is useful for debugging purposes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

implicitMul

protected boolean implicitMul
Implicit multiplication option


funTab

protected FunctionTable funTab
Function Table


symTab

protected java.util.Hashtable symTab
Symbol Table


errorList

protected java.util.Vector errorList
Error List

Constructor Detail

JEP

public JEP()
Creates a new JEP instance with the default settings.

Traverse = false
Implicit multiplication = false
Number Factory = DoubleNumberFactory


JEP

public JEP(boolean traverse_in,
           boolean allowUndeclared_in,
           boolean implicitMul_in,
           NumberFactory numberFactory_in)
Creates a new JEP instance with custom settings. If the numberFactory_in is null, the default number factory is used.

Parameters:
traverse_in - The traverse option.
implicitMul_in - The implicit multiplication option.
numberFactory_in - The number factory to be used.
Method Detail

isMathMLFunction

public static boolean isMathMLFunction(java.lang.String s)

addFunction

public void addFunction(java.lang.String functionName,
                        PostfixMathCommandI function)
Adds a new function to the parser. This must be done before parsing an expression so the parser is aware that the new function may be contained in the expression.

Parameters:
functionName - The name of the function
function - The function object that is used for evaluating the function

addStandardFunctions

public void addStandardFunctions()
Adds the standard functions to the parser. If this function is not called before parsing an expression, functions such as sin() or cos() would produce an "Unrecognized function..." error. In most cases, this method should be called immediately after the JEP object is created.


getErrorInfo

public java.lang.String getErrorInfo()
Reports information on the errors that occured during the most recent action.

Returns:
A string containing information on the errors, each separated by a newline character; null if no error has occured

getNumberFactory

public NumberFactory getNumberFactory()
Returns the number factory.


getSBMLString

public java.lang.String getSBMLString(java.lang.String expression_in)

getTopNode

public Node getTopNode()
Returns the top node of the expression tree. Because all nodes are pointed to either directly or indirectly, the entire expression tree can be accessed through this node. It may be used to manipulate the expression, and subsequently evaluate it manually.

Returns:
The top node of the expression tree

getVariables

public java.util.Enumeration getVariables()

getVariablesInExpression

public java.util.Enumeration getVariablesInExpression(java.lang.String eq)
Gets the variables in the given equation.

Parameters:
eq - The equation.
Returns:
An Enumeration of the variables.

hasError

public boolean hasError()
Returns true if an error occured during the most recent action (parsing or evaluation).

Returns:
Returns true if an error occured during the most recent action (parsing or evaluation).

initFunTab

public void initFunTab()
Creates a new FunctionTable object as funTab.


isFunction

public boolean isFunction(java.lang.String s)

parseExpression

public void parseExpression(java.lang.String expression_in)
Parses the expression. If there are errors in the expression, they are added to the errorList member.

Parameters:
expression_in - The input expression string

removeFunction

public java.lang.Object removeFunction(java.lang.String name)
Removes a function from the parser.

Returns:
If the function was added earlier, the function class instance is returned. If the function was not present, null is returned.

setImplicitMul

public void setImplicitMul(boolean value)
Sets the value of the implicit multiplication option. If this option is set to true before parsing, implicit multiplication will be allowed. That means that an expression such as
"1 2"
is valid and is interpreted as
"1*2"
.

The default value is false.

Parameters:
value - The boolean implicit multiplication option.

setTraverse

public void setTraverse(boolean value)
Sets the value of the traverse option. setTraverse is useful for debugging purposes. When traverse is set to true, the parse-tree will be dumped to the standard ouput device.

The default value is false.

Parameters:
value - The boolean traversal option.