JEP User Manual

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<
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值