JUMContent
-
- JEP User Manual
-
- Add dependency
- Import
- Using JEP
-
- Create
- Creates a new JEP instance with the default settings.
- Creates a new JEP instance with custom settings. If the numberFactory_in is null, the default number factory is used.
- Creates a JEP instance copy.
- addStandardFunctions
- addFunction
- addStandardConstants
- addConstant
- addComplex
- addVariable
- parseExpression
- parse
- evaluate
- SymbolTable
- FunctionTable
- errorList
- Parser
- TopNode
- EvaluatorVisitor
- NumberFactory
- VariableFactory
- OperatorSet
JEP User Manual
Add dependency
<!-- https://mvnrepository.com/artifact/org.scijava/jep -->
<dependency>
<groupId>org.scijava</groupId>
<artifactId>jep</artifactId>
<version>2.4.2</version>
</dependency>
Import
import org.nfunk.jep.JEP();
Using JEP
Create
Creates a new JEP instance with the default settings.
JEP jep = new JEP();
public JEP(){
topNode = null;
traverse = false;
allowUndeclared = false;
allowAssignment = false;
implicitMul = false;
numberFactory = new DoubleNumberFactory();
opSet = new OperatorSet();
initSymTab();
initFunTab();
errorList = new Vector();
ev = new EvaluatorVisitor();
parser = new Parser(new StringReader(""));
}
initSymTab
Creates a new SymbolTable object with a new VariableFactory as symTab.
initFunTab
Creates a new FunctionTable object as funTab.
Creates a new JEP instance with custom settings. If the numberFactory_in is null, the default number factory is used.
JEP jep = new JEP();
public JEP(boolean traverse_in, boolean allowUndeclared_in, boolean implicitMul_in,
NumberFactory numberFactory_in){
topNode = null;
traverse = traverse_in;
allowUndeclared = allowUndeclared_in;
implicitMul = implicitMul_in;
if (numberFactory_in == null) {
numberFactory = new DoubleNumberFactory();
} else {
numberFactory = numberFactory_in;
}
opSet = new OperatorSet();
initSymTab();
initFunTab();
errorList = new Vector();
ev = new EvaluatorVisitor();
parser = new Parser(new StringReader(""));
//Ensure errors are reported for the initial expression
//e.g. No expression entered
parseExpression("");
}
traverse
/**
* 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 output device.
* <p>
* The default value is false.
* @param value The boolean traversal option.
*/
/** Traverse option */
private boolean traverse;
allowUndeclared
/**
* Sets the value for the undeclared variables option. If this option
* is set to true, expressions containing variables that were not
* previously added to JEP will not produce an "Unrecognized Symbol"
* error. The new variables will automatically be added while parsing,
* and initialized to 0.
* <p>
* If this option is set to false, variables that were not previously
* added to JEP will produce an error while parsing.
* <p>
* The default value is false.
* /
/** Allow undeclared variables option */
protected boolean allowUndeclared;
implicitMul
/**
* 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
* <pre>"1 2"</pre> is valid and is interpreted as <pre>"1*2"</pre>.
* <p>
* The default value is false.
* @param value The boolean implicit multiplication option.
*/
/** Implicit multiplication option */
protected boolean implicitMul;
numberFactory
/**
* 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.
*/
/** Number factory */
protected NumberFactory numberFactory;
allowAssignment
/**
* Sets whether assignment equations like <tt>y=x+1</tt> are allowed.
* @since 2.3.0 alpha
*/
/** Allow undeclared variables option */
protected boolean allowAssignment;
Creates a JEP instance copy.
protected JEP(JEP j){
this.topNode = null;
this.traverse = j.traverse;
this.allowUndeclared = j.allowUndeclared;
this.allowAssignment = j.allowAssignment;
this.implicitMul = j.implicitMul;
this.ev = j.ev;
this.funTab = j.funTab;
this.opSet = j.opSet;
this.numberFactory = j.numberFactory;
this.parser = j.parser;
this.symTab = j.symTab;
this.errorList = j.errorList;
}
addStandardFunctions
add functions to Function Table
funTab.put("sin", new Sine());
funTab.put("cos", new Cosine());
funTab.put("tan", new Tangent());
funTab.put("asin", new ArcSine());
funTab.put("acos", new ArcCosine());
funTab.put("atan", new ArcTangent());
funTab.put("atan2", new ArcTangent2());
funTab.put("sinh", new SineH());
funTab.put("cosh", new CosineH());
funTab.put("tanh", new TanH());
funTab.put("asinh", new ArcSineH());
funTab.put("acosh", new ArcCosineH());
funTab.put("atanh", new ArcTanH());
funTab.put("log", new Logarithm());
funTab.put("ln", new NaturalLogarithm());
funTab.put("exp", new Exp());
funTab.put("pow", new Power());
funTab.put("sqrt",new SquareRoot());
funTab.put("abs", new Abs());
funTab.put("mod", new Modulus());
funTab.put("sum", new Sum());
funTab.put("rand", new org.nfunk.jep.function.Random());
// rjm additions
funTab.put("if", new If());
funTab.put("str", new Str());
// rjm 13/2/05
funTab.put<