All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.lsmp.djep.xjep.Eval Maven / Gradle / Ivy

Go to download

JEP is a Java library for parsing and evaluating mathematical expressions.

The newest version!
/* @author rich
 * Created on 18-Jun-2003
 */
package org.lsmp.djep.xjep;
import org.nfunk.jep.function.PostfixMathCommand;
import org.nfunk.jep.*;
import java.util.*;

/**
 * Symbolic eval(x^3,x,2) operator.  
 * @author R Morris.
 * Created on 18-Jun-2003
 */
public class Eval extends PostfixMathCommand implements CommandVisitorI
{
	/**
	 * Create a function that evaluates the lhs with values given on rhs.
	 * e.g. eval(f,x,1,y,2) sets variable x to 1, y to 2 and evaluates f.
	 */
	public Eval()
	{
		super();
		numberOfParameters = -1;
	}
	//TODO probably broken
	public Node process(Node node,Node children[],XJep xjep) throws ParseException
	{
		Vector errorList = new Vector();
		int nchild = children.length;
		if(nchild %2 == 0)
			throw new ParseException("Number of parameters must be odd");
		XSymbolTable localSymTab = (XSymbolTable) ((XSymbolTable) xjep.getSymbolTable()).newInstance();
		XJep localJep = xjep.newInstance(localSymTab);

		for(Enumeration en = xjep.getSymbolTable().keys();en.hasMoreElements();)
		{
			String key = (String) en.nextElement();
			Object val = xjep.getSymbolTable().getValue(key);
			localSymTab.addVariable(key,val);
		}
		/** first evaluate the arguments **/
		for(int i=1;i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy