first commit
This commit is contained in:
29
hrmsEjb/org/nfunk/jep/ASTConstant.java
Normal file
29
hrmsEjb/org/nfunk/jep/ASTConstant.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package org.nfunk.jep;
|
||||
|
||||
public class ASTConstant extends SimpleNode {
|
||||
private Object value;
|
||||
|
||||
public ASTConstant(int paramInt) {
|
||||
super(paramInt);
|
||||
}
|
||||
|
||||
public ASTConstant(Parser paramParser, int paramInt) {
|
||||
super(paramParser, paramInt);
|
||||
}
|
||||
|
||||
public void setValue(Object paramObject) {
|
||||
this.value = paramObject;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public Object jjtAccept(ParserVisitor paramParserVisitor, Object paramObject) throws ParseException {
|
||||
return paramParserVisitor.visit(this, paramObject);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Constant: " + this.value;
|
||||
}
|
||||
}
|
54
hrmsEjb/org/nfunk/jep/ASTFunNode.java
Normal file
54
hrmsEjb/org/nfunk/jep/ASTFunNode.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package org.nfunk.jep;
|
||||
|
||||
import org.nfunk.jep.function.PostfixMathCommandI;
|
||||
|
||||
public class ASTFunNode extends SimpleNode {
|
||||
private PostfixMathCommandI pfmc;
|
||||
|
||||
private String name;
|
||||
|
||||
private Operator opID = null;
|
||||
|
||||
public ASTFunNode(int paramInt) {
|
||||
super(paramInt);
|
||||
}
|
||||
|
||||
public ASTFunNode(Parser paramParser, int paramInt) {
|
||||
super(paramParser, paramInt);
|
||||
}
|
||||
|
||||
public Object jjtAccept(ParserVisitor paramParserVisitor, Object paramObject) throws ParseException {
|
||||
return paramParserVisitor.visit(this, paramObject);
|
||||
}
|
||||
|
||||
public void setFunction(String paramString, PostfixMathCommandI paramPostfixMathCommandI) {
|
||||
this.name = paramString;
|
||||
this.pfmc = paramPostfixMathCommandI;
|
||||
}
|
||||
|
||||
public void setOperator(Operator paramOperator) {
|
||||
this.opID = paramOperator;
|
||||
this.pfmc = paramOperator.getPFMC();
|
||||
this.name = paramOperator.getName();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Function \"" + this.name + "\"";
|
||||
}
|
||||
|
||||
public PostfixMathCommandI getPFMC() {
|
||||
return this.pfmc;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public Operator getOperator() {
|
||||
return this.opID;
|
||||
}
|
||||
|
||||
public boolean isOperator() {
|
||||
return (this.opID != null);
|
||||
}
|
||||
}
|
15
hrmsEjb/org/nfunk/jep/ASTStart.java
Normal file
15
hrmsEjb/org/nfunk/jep/ASTStart.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package org.nfunk.jep;
|
||||
|
||||
public class ASTStart extends SimpleNode {
|
||||
public ASTStart(int paramInt) {
|
||||
super(paramInt);
|
||||
}
|
||||
|
||||
public ASTStart(Parser paramParser, int paramInt) {
|
||||
super(paramParser, paramInt);
|
||||
}
|
||||
|
||||
public Object jjtAccept(ParserVisitor paramParserVisitor, Object paramObject) throws ParseException {
|
||||
return paramParserVisitor.visit(this, paramObject);
|
||||
}
|
||||
}
|
34
hrmsEjb/org/nfunk/jep/ASTVarNode.java
Normal file
34
hrmsEjb/org/nfunk/jep/ASTVarNode.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package org.nfunk.jep;
|
||||
|
||||
public class ASTVarNode extends SimpleNode {
|
||||
private Variable var;
|
||||
|
||||
public ASTVarNode(int paramInt) {
|
||||
super(paramInt);
|
||||
this.var = null;
|
||||
}
|
||||
|
||||
public ASTVarNode(Parser paramParser, int paramInt) {
|
||||
super(paramParser, paramInt);
|
||||
}
|
||||
|
||||
public Object jjtAccept(ParserVisitor paramParserVisitor, Object paramObject) throws ParseException {
|
||||
return paramParserVisitor.visit(this, paramObject);
|
||||
}
|
||||
|
||||
public void setVar(Variable paramVariable) {
|
||||
this.var = paramVariable;
|
||||
}
|
||||
|
||||
public Variable getVar() {
|
||||
return this.var;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.var.getName();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Variable: \"" + getName() + "\"";
|
||||
}
|
||||
}
|
84
hrmsEjb/org/nfunk/jep/EvaluatorVisitor.java
Normal file
84
hrmsEjb/org/nfunk/jep/EvaluatorVisitor.java
Normal file
@@ -0,0 +1,84 @@
|
||||
package org.nfunk.jep;
|
||||
|
||||
import java.util.Stack;
|
||||
import java.util.Vector;
|
||||
import org.nfunk.jep.function.PostfixMathCommandI;
|
||||
import org.nfunk.jep.function.SpecialEvaluationI;
|
||||
|
||||
public class EvaluatorVisitor implements ParserVisitor {
|
||||
protected Stack stack = new Stack();
|
||||
|
||||
protected Vector errorList = null;
|
||||
|
||||
protected SymbolTable symTab = null;
|
||||
|
||||
protected boolean errorFlag;
|
||||
|
||||
private static final boolean debug = false;
|
||||
|
||||
protected void addToErrorList(String paramString) {
|
||||
if (this.errorList != null)
|
||||
this.errorList.addElement(paramString);
|
||||
}
|
||||
|
||||
public Object getValue(Node paramNode, Vector paramVector, SymbolTable paramSymbolTable) throws Exception {
|
||||
if (paramNode == null)
|
||||
throw new IllegalArgumentException("topNode parameter is null");
|
||||
this.errorList = paramVector;
|
||||
this.symTab = paramSymbolTable;
|
||||
this.errorFlag = false;
|
||||
this.stack.removeAllElements();
|
||||
try {
|
||||
paramNode.jjtAccept(this, null);
|
||||
} catch (ParseException parseException) {
|
||||
addToErrorList(parseException.getMessage());
|
||||
throw parseException;
|
||||
}
|
||||
if (this.errorFlag || this.stack.size() != 1)
|
||||
throw new Exception("EvaluatorVisitor.getValue(): Error during evaluation");
|
||||
return this.stack.pop();
|
||||
}
|
||||
|
||||
public Object visit(SimpleNode paramSimpleNode, Object paramObject) throws ParseException {
|
||||
throw new ParseException("No visit method for " + paramSimpleNode.getClass().toString());
|
||||
}
|
||||
|
||||
public Object visit(ASTStart paramASTStart, Object paramObject) throws ParseException {
|
||||
throw new ParseException("Start node encountered during evaluation");
|
||||
}
|
||||
|
||||
public Object visit(ASTFunNode paramASTFunNode, Object paramObject) throws ParseException {
|
||||
if (paramASTFunNode == null)
|
||||
return null;
|
||||
PostfixMathCommandI postfixMathCommandI = paramASTFunNode.getPFMC();
|
||||
if (postfixMathCommandI == null)
|
||||
throw new ParseException("No function class associated with " + paramASTFunNode.getName());
|
||||
if (postfixMathCommandI instanceof SpecialEvaluationI)
|
||||
return ((SpecialEvaluationI)paramASTFunNode.getPFMC()).evaluate(paramASTFunNode, paramObject, this, this.stack);
|
||||
paramObject = paramASTFunNode.childrenAccept(this, paramObject);
|
||||
if (postfixMathCommandI.getNumberOfParameters() == -1)
|
||||
postfixMathCommandI.setCurNumberOfParameters(paramASTFunNode.jjtGetNumChildren());
|
||||
postfixMathCommandI.run(this.stack);
|
||||
return paramObject;
|
||||
}
|
||||
|
||||
public Object visit(ASTVarNode paramASTVarNode, Object paramObject) throws ParseException {
|
||||
Variable variable = paramASTVarNode.getVar();
|
||||
if (variable == null) {
|
||||
String str = "Could not evaluate " + paramASTVarNode.getName() + ": ";
|
||||
throw new ParseException(str + " variable not set");
|
||||
}
|
||||
Object object = variable.getValue();
|
||||
if (object == null) {
|
||||
String str = "Could not evaluate " + paramASTVarNode.getName() + ": ";
|
||||
throw new ParseException(str + "the variable was not found in the symbol table");
|
||||
}
|
||||
this.stack.push(object);
|
||||
return paramObject;
|
||||
}
|
||||
|
||||
public Object visit(ASTConstant paramASTConstant, Object paramObject) {
|
||||
this.stack.push(paramASTConstant.getValue());
|
||||
return paramObject;
|
||||
}
|
||||
}
|
22
hrmsEjb/org/nfunk/jep/FunctionTable.java
Normal file
22
hrmsEjb/org/nfunk/jep/FunctionTable.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package org.nfunk.jep;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import org.nfunk.jep.function.PostfixMathCommandI;
|
||||
|
||||
public class FunctionTable extends Hashtable {
|
||||
public Object put(String paramString, PostfixMathCommandI paramPostfixMathCommandI) {
|
||||
return super.put(paramString, paramPostfixMathCommandI);
|
||||
}
|
||||
|
||||
public Object put(Object paramObject1, Object paramObject2) {
|
||||
return put((String)paramObject1, (PostfixMathCommandI)paramObject2);
|
||||
}
|
||||
|
||||
public PostfixMathCommandI get(String paramString) {
|
||||
return super.get(paramString);
|
||||
}
|
||||
|
||||
public Object get(Object paramObject) {
|
||||
return get((String)paramObject);
|
||||
}
|
||||
}
|
327
hrmsEjb/org/nfunk/jep/JEP.java
Normal file
327
hrmsEjb/org/nfunk/jep/JEP.java
Normal file
@@ -0,0 +1,327 @@
|
||||
package org.nfunk.jep;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.util.Vector;
|
||||
import org.nfunk.jep.function.Abs;
|
||||
import org.nfunk.jep.function.ArcCosine;
|
||||
import org.nfunk.jep.function.ArcCosineH;
|
||||
import org.nfunk.jep.function.ArcSine;
|
||||
import org.nfunk.jep.function.ArcSineH;
|
||||
import org.nfunk.jep.function.ArcTanH;
|
||||
import org.nfunk.jep.function.ArcTangent;
|
||||
import org.nfunk.jep.function.ArcTangent2;
|
||||
import org.nfunk.jep.function.Arg;
|
||||
import org.nfunk.jep.function.ComplexPFMC;
|
||||
import org.nfunk.jep.function.Cosine;
|
||||
import org.nfunk.jep.function.CosineH;
|
||||
import org.nfunk.jep.function.Exp;
|
||||
import org.nfunk.jep.function.If;
|
||||
import org.nfunk.jep.function.Imaginary;
|
||||
import org.nfunk.jep.function.Logarithm;
|
||||
import org.nfunk.jep.function.Modulus;
|
||||
import org.nfunk.jep.function.NaturalLogarithm;
|
||||
import org.nfunk.jep.function.Polar;
|
||||
import org.nfunk.jep.function.PostfixMathCommandI;
|
||||
import org.nfunk.jep.function.Random;
|
||||
import org.nfunk.jep.function.Real;
|
||||
import org.nfunk.jep.function.Sine;
|
||||
import org.nfunk.jep.function.SineH;
|
||||
import org.nfunk.jep.function.SquareRoot;
|
||||
import org.nfunk.jep.function.Str;
|
||||
import org.nfunk.jep.function.Sum;
|
||||
import org.nfunk.jep.function.TanH;
|
||||
import org.nfunk.jep.function.Tangent;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
import org.nfunk.jep.type.DoubleNumberFactory;
|
||||
import org.nfunk.jep.type.NumberFactory;
|
||||
|
||||
public class JEP {
|
||||
private static final boolean debug = false;
|
||||
|
||||
private boolean traverse = false;
|
||||
|
||||
protected boolean allowUndeclared = false;
|
||||
|
||||
protected boolean allowAssignment;
|
||||
|
||||
protected boolean implicitMul;
|
||||
|
||||
protected SymbolTable symTab;
|
||||
|
||||
protected FunctionTable funTab;
|
||||
|
||||
protected Vector errorList;
|
||||
|
||||
protected Parser parser;
|
||||
|
||||
private Node topNode = null;
|
||||
|
||||
protected EvaluatorVisitor ev;
|
||||
|
||||
protected NumberFactory numberFactory;
|
||||
|
||||
protected OperatorSet opSet;
|
||||
|
||||
public JEP() {
|
||||
this.allowAssignment = false;
|
||||
this.implicitMul = false;
|
||||
this.numberFactory = (NumberFactory)new DoubleNumberFactory();
|
||||
this.opSet = new OperatorSet();
|
||||
initSymTab();
|
||||
initFunTab();
|
||||
this.errorList = new Vector();
|
||||
this.ev = new EvaluatorVisitor();
|
||||
this.parser = new Parser(new StringReader(""));
|
||||
}
|
||||
|
||||
public JEP(boolean paramBoolean1, boolean paramBoolean2, boolean paramBoolean3, NumberFactory paramNumberFactory) {
|
||||
this.implicitMul = paramBoolean3;
|
||||
if (paramNumberFactory == null) {
|
||||
this.numberFactory = (NumberFactory)new DoubleNumberFactory();
|
||||
} else {
|
||||
this.numberFactory = paramNumberFactory;
|
||||
}
|
||||
initSymTab();
|
||||
initFunTab();
|
||||
this.errorList = new Vector();
|
||||
this.ev = new EvaluatorVisitor();
|
||||
this.parser = new Parser(new StringReader(""));
|
||||
parseExpression("");
|
||||
}
|
||||
|
||||
protected JEP(JEP paramJEP) {
|
||||
this.allowAssignment = paramJEP.allowAssignment;
|
||||
this.implicitMul = paramJEP.implicitMul;
|
||||
this.ev = paramJEP.ev;
|
||||
this.funTab = paramJEP.funTab;
|
||||
this.numberFactory = paramJEP.numberFactory;
|
||||
this.parser = paramJEP.parser;
|
||||
this.symTab = paramJEP.symTab;
|
||||
this.errorList = paramJEP.errorList;
|
||||
}
|
||||
|
||||
public void initSymTab() {
|
||||
this.symTab = new SymbolTable(new VariableFactory());
|
||||
}
|
||||
|
||||
public void initFunTab() {
|
||||
this.funTab = new FunctionTable();
|
||||
}
|
||||
|
||||
public void addStandardFunctions() {
|
||||
this.funTab.put("sin", (PostfixMathCommandI)new Sine());
|
||||
this.funTab.put("cos", (PostfixMathCommandI)new Cosine());
|
||||
this.funTab.put("tan", (PostfixMathCommandI)new Tangent());
|
||||
this.funTab.put("asin", (PostfixMathCommandI)new ArcSine());
|
||||
this.funTab.put("acos", (PostfixMathCommandI)new ArcCosine());
|
||||
this.funTab.put("atan", (PostfixMathCommandI)new ArcTangent());
|
||||
this.funTab.put("atan2", (PostfixMathCommandI)new ArcTangent2());
|
||||
this.funTab.put("sinh", (PostfixMathCommandI)new SineH());
|
||||
this.funTab.put("cosh", (PostfixMathCommandI)new CosineH());
|
||||
this.funTab.put("tanh", (PostfixMathCommandI)new TanH());
|
||||
this.funTab.put("asinh", (PostfixMathCommandI)new ArcSineH());
|
||||
this.funTab.put("acosh", (PostfixMathCommandI)new ArcCosineH());
|
||||
this.funTab.put("atanh", (PostfixMathCommandI)new ArcTanH());
|
||||
this.funTab.put("log", (PostfixMathCommandI)new Logarithm());
|
||||
this.funTab.put("ln", (PostfixMathCommandI)new NaturalLogarithm());
|
||||
this.funTab.put("exp", (PostfixMathCommandI)new Exp());
|
||||
this.funTab.put("sqrt", (PostfixMathCommandI)new SquareRoot());
|
||||
this.funTab.put("abs", (PostfixMathCommandI)new Abs());
|
||||
this.funTab.put("mod", (PostfixMathCommandI)new Modulus());
|
||||
this.funTab.put("sum", (PostfixMathCommandI)new Sum());
|
||||
this.funTab.put("rand", (PostfixMathCommandI)new Random());
|
||||
this.funTab.put("if", (PostfixMathCommandI)new If());
|
||||
this.funTab.put("str", (PostfixMathCommandI)new Str());
|
||||
}
|
||||
|
||||
public void addStandardConstants() {
|
||||
this.symTab.addConstant("pi", new Double(Math.PI));
|
||||
this.symTab.addConstant("e", new Double(Math.E));
|
||||
}
|
||||
|
||||
public void addComplex() {
|
||||
this.symTab.addConstant("i", new Complex(0.0D, 1.0D));
|
||||
this.funTab.put("re", (PostfixMathCommandI)new Real());
|
||||
this.funTab.put("im", (PostfixMathCommandI)new Imaginary());
|
||||
this.funTab.put("arg", (PostfixMathCommandI)new Arg());
|
||||
this.funTab.put("cmod", (PostfixMathCommandI)new Abs());
|
||||
this.funTab.put("complex", (PostfixMathCommandI)new ComplexPFMC());
|
||||
this.funTab.put("polar", (PostfixMathCommandI)new Polar());
|
||||
}
|
||||
|
||||
public void addFunction(String paramString, PostfixMathCommandI paramPostfixMathCommandI) {
|
||||
this.funTab.put(paramString, paramPostfixMathCommandI);
|
||||
}
|
||||
|
||||
public Double addVariable(String paramString, double paramDouble) {
|
||||
Double double_ = new Double(paramDouble);
|
||||
this.symTab.makeVarIfNeeded(paramString, double_);
|
||||
return double_;
|
||||
}
|
||||
|
||||
public void addConstant(String paramString, Object paramObject) {
|
||||
this.symTab.addConstant(paramString, paramObject);
|
||||
}
|
||||
|
||||
public Complex addVariable(String paramString, double paramDouble1, double paramDouble2) {
|
||||
Complex complex = new Complex(paramDouble1, paramDouble2);
|
||||
this.symTab.makeVarIfNeeded(paramString, complex);
|
||||
return complex;
|
||||
}
|
||||
|
||||
public void addVariable(String paramString, Object paramObject) {
|
||||
this.symTab.makeVarIfNeeded(paramString, paramObject);
|
||||
}
|
||||
|
||||
public Object removeVariable(String paramString) {
|
||||
return this.symTab.remove(paramString);
|
||||
}
|
||||
|
||||
public Object getVarValue(String paramString) {
|
||||
return this.symTab.getVar(paramString).getValue();
|
||||
}
|
||||
|
||||
public boolean setVarValue(String paramString, Object paramObject) {
|
||||
return this.symTab.setVarValue(paramString, paramObject);
|
||||
}
|
||||
|
||||
public Variable getVar(String paramString) {
|
||||
return this.symTab.getVar(paramString);
|
||||
}
|
||||
|
||||
public Object removeFunction(String paramString) {
|
||||
return this.funTab.remove(paramString);
|
||||
}
|
||||
|
||||
public void setTraverse(boolean paramBoolean) {
|
||||
this.traverse = paramBoolean;
|
||||
}
|
||||
|
||||
public boolean getTraverse() {
|
||||
return this.traverse;
|
||||
}
|
||||
|
||||
public void setImplicitMul(boolean paramBoolean) {
|
||||
this.implicitMul = paramBoolean;
|
||||
}
|
||||
|
||||
public boolean getImplicitMul() {
|
||||
return this.implicitMul;
|
||||
}
|
||||
|
||||
public void setAllowUndeclared(boolean paramBoolean) {
|
||||
this.allowUndeclared = paramBoolean;
|
||||
}
|
||||
|
||||
public boolean getAllowUndeclared() {
|
||||
return this.allowUndeclared;
|
||||
}
|
||||
|
||||
public void setAllowAssignment(boolean paramBoolean) {
|
||||
this.allowAssignment = paramBoolean;
|
||||
}
|
||||
|
||||
public boolean getAllowAssignment() {
|
||||
return this.allowAssignment;
|
||||
}
|
||||
|
||||
public void parseExpression(String paramString) {
|
||||
StringReader stringReader = new StringReader(paramString);
|
||||
try {
|
||||
this.errorList.removeAllElements();
|
||||
this.topNode = this.parser.parseStream(stringReader, this);
|
||||
} catch (Throwable throwable) {
|
||||
this.topNode = null;
|
||||
if (throwable instanceof ParseException) {
|
||||
this.errorList.addElement(((ParseException)throwable).getMessage());
|
||||
} else {
|
||||
this.errorList.addElement("Syntax error");
|
||||
}
|
||||
}
|
||||
if (this.traverse && !hasError()) {
|
||||
ParserDumpVisitor parserDumpVisitor = new ParserDumpVisitor();
|
||||
try {
|
||||
this.topNode.jjtAccept(parserDumpVisitor, null);
|
||||
} catch (ParseException parseException) {
|
||||
this.errorList.addElement(parseException.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Node parse(String paramString) throws ParseException {
|
||||
StringReader stringReader = new StringReader(paramString);
|
||||
return this.parser.parseStream(stringReader, this);
|
||||
}
|
||||
|
||||
public Object evaluate(Node paramNode) throws Exception {
|
||||
return this.ev.getValue(paramNode, new Vector(), this.symTab);
|
||||
}
|
||||
|
||||
public double getValue() {
|
||||
Object object = getValueAsObject();
|
||||
if (object == null)
|
||||
return Double.NaN;
|
||||
if (object instanceof Complex) {
|
||||
Complex complex = (Complex)object;
|
||||
return (complex.im() != 0.0D) ? Double.NaN : complex.re();
|
||||
}
|
||||
return (object != null && object instanceof Number) ? ((Number)object).doubleValue() : Double.NaN;
|
||||
}
|
||||
|
||||
public Complex getComplexValue() {
|
||||
Object object = getValueAsObject();
|
||||
return (object == null) ? null : ((object instanceof Complex) ? (Complex)object : ((object instanceof Number) ? new Complex(((Number)object).doubleValue(), 0.0D) : null));
|
||||
}
|
||||
|
||||
public Object getValueAsObject() {
|
||||
if (this.topNode != null && !hasError()) {
|
||||
Object object;
|
||||
try {
|
||||
object = this.ev.getValue(this.topNode, this.errorList, this.symTab);
|
||||
} catch (Exception exception) {
|
||||
this.errorList.addElement("Error during evaluation");
|
||||
return null;
|
||||
}
|
||||
return object;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasError() {
|
||||
return !this.errorList.isEmpty();
|
||||
}
|
||||
|
||||
public String getErrorInfo() {
|
||||
if (hasError()) {
|
||||
String str = "";
|
||||
for (byte b = 0; b < this.errorList.size(); b++)
|
||||
str = str + this.errorList.elementAt(b) + "\n";
|
||||
return str;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Node getTopNode() {
|
||||
return this.topNode;
|
||||
}
|
||||
|
||||
public SymbolTable getSymbolTable() {
|
||||
return this.symTab;
|
||||
}
|
||||
|
||||
public FunctionTable getFunctionTable() {
|
||||
return this.funTab;
|
||||
}
|
||||
|
||||
public NumberFactory getNumberFactory() {
|
||||
return this.numberFactory;
|
||||
}
|
||||
|
||||
public OperatorSet getOperatorSet() {
|
||||
return this.opSet;
|
||||
}
|
||||
|
||||
public Parser getParser() {
|
||||
return this.parser;
|
||||
}
|
||||
}
|
91
hrmsEjb/org/nfunk/jep/JJTParserState.java
Normal file
91
hrmsEjb/org/nfunk/jep/JJTParserState.java
Normal file
@@ -0,0 +1,91 @@
|
||||
package org.nfunk.jep;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
class JJTParserState {
|
||||
private Stack nodes = new Stack();
|
||||
|
||||
private Stack marks = new Stack();
|
||||
|
||||
private int sp = 0;
|
||||
|
||||
private int mk = 0;
|
||||
|
||||
private boolean node_created;
|
||||
|
||||
boolean nodeCreated() {
|
||||
return this.node_created;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
this.nodes.removeAllElements();
|
||||
this.marks.removeAllElements();
|
||||
this.sp = 0;
|
||||
this.mk = 0;
|
||||
}
|
||||
|
||||
Node rootNode() {
|
||||
return this.nodes.elementAt(0);
|
||||
}
|
||||
|
||||
void pushNode(Node paramNode) {
|
||||
this.nodes.push(paramNode);
|
||||
this.sp++;
|
||||
}
|
||||
|
||||
Node popNode() {
|
||||
if (--this.sp < this.mk)
|
||||
this.mk = ((Integer)this.marks.pop()).intValue();
|
||||
return this.nodes.pop();
|
||||
}
|
||||
|
||||
Node peekNode() {
|
||||
return this.nodes.peek();
|
||||
}
|
||||
|
||||
int nodeArity() {
|
||||
return this.sp - this.mk;
|
||||
}
|
||||
|
||||
void clearNodeScope(Node paramNode) {
|
||||
while (this.sp > this.mk)
|
||||
popNode();
|
||||
this.mk = ((Integer)this.marks.pop()).intValue();
|
||||
}
|
||||
|
||||
void openNodeScope(Node paramNode) {
|
||||
this.marks.push(new Integer(this.mk));
|
||||
this.mk = this.sp;
|
||||
paramNode.jjtOpen();
|
||||
}
|
||||
|
||||
void closeNodeScope(Node paramNode, int paramInt) {
|
||||
this.mk = ((Integer)this.marks.pop()).intValue();
|
||||
while (paramInt-- > 0) {
|
||||
Node node = popNode();
|
||||
node.jjtSetParent(paramNode);
|
||||
paramNode.jjtAddChild(node, paramInt);
|
||||
}
|
||||
paramNode.jjtClose();
|
||||
pushNode(paramNode);
|
||||
this.node_created = true;
|
||||
}
|
||||
|
||||
void closeNodeScope(Node paramNode, boolean paramBoolean) {
|
||||
if (paramBoolean) {
|
||||
int i = nodeArity();
|
||||
this.mk = ((Integer)this.marks.pop()).intValue();
|
||||
while (i-- > 0) {
|
||||
Node node = popNode();
|
||||
node.jjtSetParent(paramNode);
|
||||
paramNode.jjtAddChild(node, i);
|
||||
}
|
||||
paramNode.jjtClose();
|
||||
pushNode(paramNode);
|
||||
this.node_created = true;
|
||||
} else {
|
||||
this.mk = ((Integer)this.marks.pop()).intValue();
|
||||
this.node_created = false;
|
||||
}
|
||||
}
|
||||
}
|
418
hrmsEjb/org/nfunk/jep/JavaCharStream.java
Normal file
418
hrmsEjb/org/nfunk/jep/JavaCharStream.java
Normal file
@@ -0,0 +1,418 @@
|
||||
package org.nfunk.jep;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
|
||||
public class JavaCharStream {
|
||||
public static final boolean staticFlag = false;
|
||||
|
||||
public int bufpos = -1;
|
||||
|
||||
int bufsize;
|
||||
|
||||
int available;
|
||||
|
||||
int tokenBegin;
|
||||
|
||||
protected int[] bufline;
|
||||
|
||||
protected int[] bufcolumn;
|
||||
|
||||
protected int column = 0;
|
||||
|
||||
protected int line = 1;
|
||||
|
||||
protected boolean prevCharIsCR = false;
|
||||
|
||||
protected boolean prevCharIsLF = false;
|
||||
|
||||
protected Reader inputStream;
|
||||
|
||||
protected char[] nextCharBuf;
|
||||
|
||||
protected char[] buffer;
|
||||
|
||||
protected int maxNextCharInd = 0;
|
||||
|
||||
protected int nextCharInd = -1;
|
||||
|
||||
protected int inBuf = 0;
|
||||
|
||||
static final int hexval(char paramChar) throws IOException {
|
||||
switch (paramChar) {
|
||||
case '0':
|
||||
return 0;
|
||||
case '1':
|
||||
return 1;
|
||||
case '2':
|
||||
return 2;
|
||||
case '3':
|
||||
return 3;
|
||||
case '4':
|
||||
return 4;
|
||||
case '5':
|
||||
return 5;
|
||||
case '6':
|
||||
return 6;
|
||||
case '7':
|
||||
return 7;
|
||||
case '8':
|
||||
return 8;
|
||||
case '9':
|
||||
return 9;
|
||||
case 'A':
|
||||
case 'a':
|
||||
return 10;
|
||||
case 'B':
|
||||
case 'b':
|
||||
return 11;
|
||||
case 'C':
|
||||
case 'c':
|
||||
return 12;
|
||||
case 'D':
|
||||
case 'd':
|
||||
return 13;
|
||||
case 'E':
|
||||
case 'e':
|
||||
return 14;
|
||||
case 'F':
|
||||
case 'f':
|
||||
return 15;
|
||||
}
|
||||
throw new IOException();
|
||||
}
|
||||
|
||||
protected void ExpandBuff(boolean paramBoolean) {
|
||||
char[] arrayOfChar = new char[this.bufsize + 2048];
|
||||
int[] arrayOfInt1 = new int[this.bufsize + 2048];
|
||||
int[] arrayOfInt2 = new int[this.bufsize + 2048];
|
||||
try {
|
||||
if (paramBoolean) {
|
||||
System.arraycopy(this.buffer, this.tokenBegin, arrayOfChar, 0, this.bufsize - this.tokenBegin);
|
||||
System.arraycopy(this.buffer, 0, arrayOfChar, this.bufsize - this.tokenBegin, this.bufpos);
|
||||
this.buffer = arrayOfChar;
|
||||
System.arraycopy(this.bufline, this.tokenBegin, arrayOfInt1, 0, this.bufsize - this.tokenBegin);
|
||||
System.arraycopy(this.bufline, 0, arrayOfInt1, this.bufsize - this.tokenBegin, this.bufpos);
|
||||
this.bufline = arrayOfInt1;
|
||||
System.arraycopy(this.bufcolumn, this.tokenBegin, arrayOfInt2, 0, this.bufsize - this.tokenBegin);
|
||||
System.arraycopy(this.bufcolumn, 0, arrayOfInt2, this.bufsize - this.tokenBegin, this.bufpos);
|
||||
this.bufcolumn = arrayOfInt2;
|
||||
this.bufpos += this.bufsize - this.tokenBegin;
|
||||
} else {
|
||||
System.arraycopy(this.buffer, this.tokenBegin, arrayOfChar, 0, this.bufsize - this.tokenBegin);
|
||||
this.buffer = arrayOfChar;
|
||||
System.arraycopy(this.bufline, this.tokenBegin, arrayOfInt1, 0, this.bufsize - this.tokenBegin);
|
||||
this.bufline = arrayOfInt1;
|
||||
System.arraycopy(this.bufcolumn, this.tokenBegin, arrayOfInt2, 0, this.bufsize - this.tokenBegin);
|
||||
this.bufcolumn = arrayOfInt2;
|
||||
this.bufpos -= this.tokenBegin;
|
||||
}
|
||||
} catch (Throwable throwable) {
|
||||
throw new Error(throwable.getMessage());
|
||||
}
|
||||
this.available = this.bufsize += 2048;
|
||||
this.tokenBegin = 0;
|
||||
}
|
||||
|
||||
protected void FillBuff() throws IOException {
|
||||
if (this.maxNextCharInd == 4096)
|
||||
this.maxNextCharInd = this.nextCharInd = 0;
|
||||
try {
|
||||
int i;
|
||||
if ((i = this.inputStream.read(this.nextCharBuf, this.maxNextCharInd, 4096 - this.maxNextCharInd)) == -1) {
|
||||
this.inputStream.close();
|
||||
throw new IOException();
|
||||
}
|
||||
this.maxNextCharInd += i;
|
||||
return;
|
||||
} catch (IOException iOException) {
|
||||
if (this.bufpos != 0) {
|
||||
this.bufpos--;
|
||||
backup(0);
|
||||
} else {
|
||||
this.bufline[this.bufpos] = this.line;
|
||||
this.bufcolumn[this.bufpos] = this.column;
|
||||
}
|
||||
throw iOException;
|
||||
}
|
||||
}
|
||||
|
||||
protected char ReadByte() throws IOException {
|
||||
if (++this.nextCharInd >= this.maxNextCharInd)
|
||||
FillBuff();
|
||||
return this.nextCharBuf[this.nextCharInd];
|
||||
}
|
||||
|
||||
public char BeginToken() throws IOException {
|
||||
if (this.inBuf > 0) {
|
||||
this.inBuf--;
|
||||
if (++this.bufpos == this.bufsize)
|
||||
this.bufpos = 0;
|
||||
this.tokenBegin = this.bufpos;
|
||||
return this.buffer[this.bufpos];
|
||||
}
|
||||
this.tokenBegin = 0;
|
||||
this.bufpos = -1;
|
||||
return readChar();
|
||||
}
|
||||
|
||||
protected void AdjustBuffSize() {
|
||||
if (this.available == this.bufsize) {
|
||||
if (this.tokenBegin > 2048) {
|
||||
this.bufpos = 0;
|
||||
this.available = this.tokenBegin;
|
||||
} else {
|
||||
ExpandBuff(false);
|
||||
}
|
||||
} else if (this.available > this.tokenBegin) {
|
||||
this.available = this.bufsize;
|
||||
} else if (this.tokenBegin - this.available < 2048) {
|
||||
ExpandBuff(true);
|
||||
} else {
|
||||
this.available = this.tokenBegin;
|
||||
}
|
||||
}
|
||||
|
||||
protected void UpdateLineColumn(char paramChar) {
|
||||
this.column++;
|
||||
if (this.prevCharIsLF) {
|
||||
this.prevCharIsLF = false;
|
||||
this.line += this.column = 1;
|
||||
} else if (this.prevCharIsCR) {
|
||||
this.prevCharIsCR = false;
|
||||
if (paramChar == '\n') {
|
||||
this.prevCharIsLF = true;
|
||||
} else {
|
||||
this.line += this.column = 1;
|
||||
}
|
||||
}
|
||||
switch (paramChar) {
|
||||
case '\r':
|
||||
this.prevCharIsCR = true;
|
||||
break;
|
||||
case '\n':
|
||||
this.prevCharIsLF = true;
|
||||
break;
|
||||
case '\t':
|
||||
this.column--;
|
||||
this.column += 8 - (this.column & 0x7);
|
||||
break;
|
||||
}
|
||||
this.bufline[this.bufpos] = this.line;
|
||||
this.bufcolumn[this.bufpos] = this.column;
|
||||
}
|
||||
|
||||
public char readChar() throws IOException {
|
||||
if (this.inBuf > 0) {
|
||||
this.inBuf--;
|
||||
if (++this.bufpos == this.bufsize)
|
||||
this.bufpos = 0;
|
||||
return this.buffer[this.bufpos];
|
||||
}
|
||||
if (++this.bufpos == this.available)
|
||||
AdjustBuffSize();
|
||||
char c = ReadByte();
|
||||
if ((c = ReadByte()) == '\\') {
|
||||
UpdateLineColumn(c);
|
||||
byte b = 1;
|
||||
while (true) {
|
||||
if (++this.bufpos == this.available)
|
||||
AdjustBuffSize();
|
||||
try {
|
||||
this.buffer[this.bufpos] = c = ReadByte();
|
||||
if ((c = ReadByte()) != '\\') {
|
||||
UpdateLineColumn(c);
|
||||
if (c == 'u' && (b & 0x1) == 1) {
|
||||
if (--this.bufpos < 0) {
|
||||
this.bufpos = this.bufsize - 1;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
backup(b);
|
||||
return '\\';
|
||||
}
|
||||
} else {
|
||||
UpdateLineColumn(c);
|
||||
b++;
|
||||
continue;
|
||||
}
|
||||
} catch (IOException iOException) {
|
||||
if (b > 1)
|
||||
backup(b);
|
||||
return '\\';
|
||||
}
|
||||
try {
|
||||
break;
|
||||
} catch (IOException iOException) {
|
||||
throw new Error("Invalid escape character at line " + this.line + " column " + this.column + ".");
|
||||
}
|
||||
}
|
||||
while ((c = ReadByte()) == 'u')
|
||||
this.column++;
|
||||
this.buffer[this.bufpos] = c = (char)(hexval(c) << 12 | hexval(ReadByte()) << 8 | hexval(ReadByte()) << 4 | hexval(ReadByte()));
|
||||
this.column += 4;
|
||||
if (b == 1)
|
||||
return c;
|
||||
backup(b - 1);
|
||||
return '\\';
|
||||
}
|
||||
UpdateLineColumn(c);
|
||||
return c;
|
||||
}
|
||||
|
||||
public int getColumn() {
|
||||
return this.bufcolumn[this.bufpos];
|
||||
}
|
||||
|
||||
public int getLine() {
|
||||
return this.bufline[this.bufpos];
|
||||
}
|
||||
|
||||
public int getEndColumn() {
|
||||
return this.bufcolumn[this.bufpos];
|
||||
}
|
||||
|
||||
public int getEndLine() {
|
||||
return this.bufline[this.bufpos];
|
||||
}
|
||||
|
||||
public int getBeginColumn() {
|
||||
return this.bufcolumn[this.tokenBegin];
|
||||
}
|
||||
|
||||
public int getBeginLine() {
|
||||
return this.bufline[this.tokenBegin];
|
||||
}
|
||||
|
||||
public void backup(int paramInt) {
|
||||
this.inBuf += paramInt;
|
||||
if ((this.bufpos -= paramInt) < 0)
|
||||
this.bufpos += this.bufsize;
|
||||
}
|
||||
|
||||
public JavaCharStream(Reader paramReader, int paramInt1, int paramInt2, int paramInt3) {
|
||||
this.inputStream = paramReader;
|
||||
this.line = paramInt1;
|
||||
this.column = paramInt2 - 1;
|
||||
this.available = this.bufsize = paramInt3;
|
||||
this.buffer = new char[paramInt3];
|
||||
this.bufline = new int[paramInt3];
|
||||
this.bufcolumn = new int[paramInt3];
|
||||
this.nextCharBuf = new char[4096];
|
||||
}
|
||||
|
||||
public JavaCharStream(Reader paramReader, int paramInt1, int paramInt2) {
|
||||
this(paramReader, paramInt1, paramInt2, 4096);
|
||||
}
|
||||
|
||||
public JavaCharStream(Reader paramReader) {
|
||||
this(paramReader, 1, 1, 4096);
|
||||
}
|
||||
|
||||
public void ReInit(Reader paramReader, int paramInt1, int paramInt2, int paramInt3) {
|
||||
this.inputStream = paramReader;
|
||||
this.line = paramInt1;
|
||||
this.column = paramInt2 - 1;
|
||||
if (this.buffer == null || paramInt3 != this.buffer.length) {
|
||||
this.available = this.bufsize = paramInt3;
|
||||
this.buffer = new char[paramInt3];
|
||||
this.bufline = new int[paramInt3];
|
||||
this.bufcolumn = new int[paramInt3];
|
||||
this.nextCharBuf = new char[4096];
|
||||
}
|
||||
this.prevCharIsLF = this.prevCharIsCR = false;
|
||||
this.tokenBegin = this.inBuf = this.maxNextCharInd = 0;
|
||||
this.nextCharInd = this.bufpos = -1;
|
||||
}
|
||||
|
||||
public void ReInit(Reader paramReader, int paramInt1, int paramInt2) {
|
||||
ReInit(paramReader, paramInt1, paramInt2, 4096);
|
||||
}
|
||||
|
||||
public void ReInit(Reader paramReader) {
|
||||
ReInit(paramReader, 1, 1, 4096);
|
||||
}
|
||||
|
||||
public JavaCharStream(InputStream paramInputStream, int paramInt1, int paramInt2, int paramInt3) {
|
||||
this(new InputStreamReader(paramInputStream), paramInt1, paramInt2, 4096);
|
||||
}
|
||||
|
||||
public JavaCharStream(InputStream paramInputStream, int paramInt1, int paramInt2) {
|
||||
this(paramInputStream, paramInt1, paramInt2, 4096);
|
||||
}
|
||||
|
||||
public JavaCharStream(InputStream paramInputStream) {
|
||||
this(paramInputStream, 1, 1, 4096);
|
||||
}
|
||||
|
||||
public void ReInit(InputStream paramInputStream, int paramInt1, int paramInt2, int paramInt3) {
|
||||
ReInit(new InputStreamReader(paramInputStream), paramInt1, paramInt2, 4096);
|
||||
}
|
||||
|
||||
public void ReInit(InputStream paramInputStream, int paramInt1, int paramInt2) {
|
||||
ReInit(paramInputStream, paramInt1, paramInt2, 4096);
|
||||
}
|
||||
|
||||
public void ReInit(InputStream paramInputStream) {
|
||||
ReInit(paramInputStream, 1, 1, 4096);
|
||||
}
|
||||
|
||||
public String GetImage() {
|
||||
return (this.bufpos >= this.tokenBegin) ? new String(this.buffer, this.tokenBegin, this.bufpos - this.tokenBegin + 1) : (new String(this.buffer, this.tokenBegin, this.bufsize - this.tokenBegin) + new String(this.buffer, 0, this.bufpos + 1));
|
||||
}
|
||||
|
||||
public char[] GetSuffix(int paramInt) {
|
||||
char[] arrayOfChar = new char[paramInt];
|
||||
if (this.bufpos + 1 >= paramInt) {
|
||||
System.arraycopy(this.buffer, this.bufpos - paramInt + 1, arrayOfChar, 0, paramInt);
|
||||
} else {
|
||||
System.arraycopy(this.buffer, this.bufsize - paramInt - this.bufpos - 1, arrayOfChar, 0, paramInt - this.bufpos - 1);
|
||||
System.arraycopy(this.buffer, 0, arrayOfChar, paramInt - this.bufpos - 1, this.bufpos + 1);
|
||||
}
|
||||
return arrayOfChar;
|
||||
}
|
||||
|
||||
public void Done() {
|
||||
this.nextCharBuf = null;
|
||||
this.buffer = null;
|
||||
this.bufline = null;
|
||||
this.bufcolumn = null;
|
||||
}
|
||||
|
||||
public void adjustBeginLineColumn(int paramInt1, int paramInt2) {
|
||||
int j;
|
||||
int i = this.tokenBegin;
|
||||
if (this.bufpos >= this.tokenBegin) {
|
||||
j = this.bufpos - this.tokenBegin + this.inBuf + 1;
|
||||
} else {
|
||||
j = this.bufsize - this.tokenBegin + this.bufpos + 1 + this.inBuf;
|
||||
}
|
||||
byte b = 0;
|
||||
int k = 0;
|
||||
int m = 0;
|
||||
int n = 0;
|
||||
int i1 = 0;
|
||||
while (b < j && this.bufline[k = i % this.bufsize] == this.bufline[m = ++i % this.bufsize]) {
|
||||
this.bufline[k] = paramInt1;
|
||||
n = i1 + this.bufcolumn[m] - this.bufcolumn[k];
|
||||
this.bufcolumn[k] = paramInt2 + i1;
|
||||
i1 = n;
|
||||
b++;
|
||||
}
|
||||
if (b < j) {
|
||||
this.bufline[k] = paramInt1++;
|
||||
this.bufcolumn[k] = paramInt2 + i1;
|
||||
while (b++ < j) {
|
||||
if (this.bufline[k = i % this.bufsize] != this.bufline[++i % this.bufsize]) {
|
||||
this.bufline[k] = paramInt1++;
|
||||
continue;
|
||||
}
|
||||
this.bufline[k] = paramInt1;
|
||||
}
|
||||
}
|
||||
this.line = this.bufline[k];
|
||||
this.column = this.bufcolumn[k];
|
||||
}
|
||||
}
|
19
hrmsEjb/org/nfunk/jep/Node.java
Normal file
19
hrmsEjb/org/nfunk/jep/Node.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package org.nfunk.jep;
|
||||
|
||||
public interface Node {
|
||||
void jjtOpen();
|
||||
|
||||
void jjtClose();
|
||||
|
||||
void jjtSetParent(Node paramNode);
|
||||
|
||||
Node jjtGetParent();
|
||||
|
||||
void jjtAddChild(Node paramNode, int paramInt);
|
||||
|
||||
Node jjtGetChild(int paramInt);
|
||||
|
||||
int jjtGetNumChildren();
|
||||
|
||||
Object jjtAccept(ParserVisitor paramParserVisitor, Object paramObject) throws ParseException;
|
||||
}
|
47
hrmsEjb/org/nfunk/jep/Operator.java
Normal file
47
hrmsEjb/org/nfunk/jep/Operator.java
Normal file
@@ -0,0 +1,47 @@
|
||||
package org.nfunk.jep;
|
||||
|
||||
import org.nfunk.jep.function.PostfixMathCommandI;
|
||||
|
||||
public class Operator {
|
||||
private String name;
|
||||
|
||||
private String symbol;
|
||||
|
||||
private PostfixMathCommandI pfmc;
|
||||
|
||||
private Operator() {}
|
||||
|
||||
public Operator(String paramString, PostfixMathCommandI paramPostfixMathCommandI) {
|
||||
this();
|
||||
this.name = paramString;
|
||||
this.pfmc = paramPostfixMathCommandI;
|
||||
this.symbol = paramString;
|
||||
}
|
||||
|
||||
public Operator(String paramString1, String paramString2, PostfixMathCommandI paramPostfixMathCommandI) {
|
||||
this();
|
||||
this.name = paramString1;
|
||||
this.pfmc = paramPostfixMathCommandI;
|
||||
this.symbol = paramString2;
|
||||
}
|
||||
|
||||
public final String getSymbol() {
|
||||
return this.symbol;
|
||||
}
|
||||
|
||||
public final String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public final PostfixMathCommandI getPFMC() {
|
||||
return this.pfmc;
|
||||
}
|
||||
|
||||
public final void setPFMC(PostfixMathCommandI paramPostfixMathCommandI) {
|
||||
this.pfmc = paramPostfixMathCommandI;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Operator: \"" + this.name + "\"";
|
||||
}
|
||||
}
|
153
hrmsEjb/org/nfunk/jep/OperatorSet.java
Normal file
153
hrmsEjb/org/nfunk/jep/OperatorSet.java
Normal file
@@ -0,0 +1,153 @@
|
||||
package org.nfunk.jep;
|
||||
|
||||
import org.nfunk.jep.function.Add;
|
||||
import org.nfunk.jep.function.Assign;
|
||||
import org.nfunk.jep.function.Comparative;
|
||||
import org.nfunk.jep.function.Cross;
|
||||
import org.nfunk.jep.function.Divide;
|
||||
import org.nfunk.jep.function.Dot;
|
||||
import org.nfunk.jep.function.List;
|
||||
import org.nfunk.jep.function.Logical;
|
||||
import org.nfunk.jep.function.Modulus;
|
||||
import org.nfunk.jep.function.Multiply;
|
||||
import org.nfunk.jep.function.Not;
|
||||
import org.nfunk.jep.function.PostfixMathCommandI;
|
||||
import org.nfunk.jep.function.Power;
|
||||
import org.nfunk.jep.function.Subtract;
|
||||
import org.nfunk.jep.function.UMinus;
|
||||
|
||||
public class OperatorSet {
|
||||
protected Operator OP_GT = new Operator(">", (PostfixMathCommandI)new Comparative(1));
|
||||
|
||||
protected Operator OP_LT = new Operator("<", (PostfixMathCommandI)new Comparative(0));
|
||||
|
||||
protected Operator OP_EQ = new Operator("==", (PostfixMathCommandI)new Comparative(5));
|
||||
|
||||
protected Operator OP_LE = new Operator("<=", (PostfixMathCommandI)new Comparative(2));
|
||||
|
||||
protected Operator OP_GE = new Operator(">=", (PostfixMathCommandI)new Comparative(3));
|
||||
|
||||
protected Operator OP_NE = new Operator("!=", (PostfixMathCommandI)new Comparative(4));
|
||||
|
||||
protected Operator OP_AND = new Operator("&&", (PostfixMathCommandI)new Logical(0));
|
||||
|
||||
protected Operator OP_OR = new Operator("||", (PostfixMathCommandI)new Logical(1));
|
||||
|
||||
protected Operator OP_NOT = new Operator("!", (PostfixMathCommandI)new Not());
|
||||
|
||||
protected Operator OP_ADD = new Operator("+", (PostfixMathCommandI)new Add());
|
||||
|
||||
protected Operator OP_SUBTRACT = new Operator("-", (PostfixMathCommandI)new Subtract());
|
||||
|
||||
protected Operator OP_UMINUS = new Operator("UMinus", "-", (PostfixMathCommandI)new UMinus());
|
||||
|
||||
protected Operator OP_MULTIPLY = new Operator("*", (PostfixMathCommandI)new Multiply());
|
||||
|
||||
protected Operator OP_DIVIDE = new Operator("/", (PostfixMathCommandI)new Divide());
|
||||
|
||||
protected Operator OP_MOD = new Operator("%", (PostfixMathCommandI)new Modulus());
|
||||
|
||||
protected Operator OP_UDIVIDE = new Operator("UDivide", "^-1", null);
|
||||
|
||||
protected Operator OP_POWER = new Operator("^", (PostfixMathCommandI)new Power());
|
||||
|
||||
protected Operator OP_ASSIGN = new Operator("=", (PostfixMathCommandI)new Assign());
|
||||
|
||||
protected Operator OP_DOT = new Operator(".", (PostfixMathCommandI)new Dot());
|
||||
|
||||
protected Operator OP_CROSS = new Operator("^^", (PostfixMathCommandI)new Cross());
|
||||
|
||||
protected Operator OP_LIST = new Operator("LIST", (PostfixMathCommandI)new List());
|
||||
|
||||
public Operator[] getOperators() {
|
||||
return new Operator[] {
|
||||
this.OP_GT, this.OP_LT, this.OP_GE, this.OP_LE, this.OP_EQ, this.OP_NE, this.OP_AND, this.OP_OR, this.OP_NOT, this.OP_ADD,
|
||||
this.OP_SUBTRACT, this.OP_UMINUS, this.OP_MULTIPLY, this.OP_DIVIDE, this.OP_MOD, this.OP_POWER, this.OP_ASSIGN, this.OP_DOT, this.OP_CROSS, this.OP_LIST };
|
||||
}
|
||||
|
||||
public void printOperators() {
|
||||
Operator[] arrayOfOperator = getOperators();
|
||||
for (byte b = 0; b < arrayOfOperator.length; b++)
|
||||
System.out.println(arrayOfOperator[b].toString());
|
||||
}
|
||||
|
||||
public Operator getAdd() {
|
||||
return this.OP_ADD;
|
||||
}
|
||||
|
||||
public Operator getSubtract() {
|
||||
return this.OP_SUBTRACT;
|
||||
}
|
||||
|
||||
public Operator getUMinus() {
|
||||
return this.OP_UMINUS;
|
||||
}
|
||||
|
||||
public Operator getMultiply() {
|
||||
return this.OP_MULTIPLY;
|
||||
}
|
||||
|
||||
public Operator getDivide() {
|
||||
return this.OP_DIVIDE;
|
||||
}
|
||||
|
||||
public Operator getMod() {
|
||||
return this.OP_MOD;
|
||||
}
|
||||
|
||||
public Operator getPower() {
|
||||
return this.OP_POWER;
|
||||
}
|
||||
|
||||
public Operator getEQ() {
|
||||
return this.OP_EQ;
|
||||
}
|
||||
|
||||
public Operator getNE() {
|
||||
return this.OP_NE;
|
||||
}
|
||||
|
||||
public Operator getGE() {
|
||||
return this.OP_GE;
|
||||
}
|
||||
|
||||
public Operator getGT() {
|
||||
return this.OP_GT;
|
||||
}
|
||||
|
||||
public Operator getLE() {
|
||||
return this.OP_LE;
|
||||
}
|
||||
|
||||
public Operator getLT() {
|
||||
return this.OP_LT;
|
||||
}
|
||||
|
||||
public Operator getAnd() {
|
||||
return this.OP_AND;
|
||||
}
|
||||
|
||||
public Operator getOr() {
|
||||
return this.OP_OR;
|
||||
}
|
||||
|
||||
public Operator getNot() {
|
||||
return this.OP_NOT;
|
||||
}
|
||||
|
||||
public Operator getAssign() {
|
||||
return this.OP_ASSIGN;
|
||||
}
|
||||
|
||||
public Operator getDot() {
|
||||
return this.OP_DOT;
|
||||
}
|
||||
|
||||
public Operator getCross() {
|
||||
return this.OP_CROSS;
|
||||
}
|
||||
|
||||
public Operator getList() {
|
||||
return this.OP_LIST;
|
||||
}
|
||||
}
|
139
hrmsEjb/org/nfunk/jep/ParseException.java
Normal file
139
hrmsEjb/org/nfunk/jep/ParseException.java
Normal file
@@ -0,0 +1,139 @@
|
||||
package org.nfunk.jep;
|
||||
|
||||
public class ParseException extends Exception {
|
||||
protected boolean specialConstructor = true;
|
||||
|
||||
public Token currentToken;
|
||||
|
||||
public int[][] expectedTokenSequences;
|
||||
|
||||
public String[] tokenImage;
|
||||
|
||||
protected String eol = System.getProperty("line.separator", "\n");
|
||||
|
||||
public ParseException(Token paramToken, int[][] paramArrayOfint, String[] paramArrayOfString) {
|
||||
super("");
|
||||
this.currentToken = paramToken;
|
||||
this.expectedTokenSequences = paramArrayOfint;
|
||||
this.tokenImage = paramArrayOfString;
|
||||
}
|
||||
|
||||
public ParseException() {}
|
||||
|
||||
public ParseException(String paramString) {
|
||||
super(paramString);
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
if (!this.specialConstructor)
|
||||
return super.getMessage();
|
||||
String str = "";
|
||||
int i = 0;
|
||||
for (byte b1 = 0; b1 < this.expectedTokenSequences.length; b1++) {
|
||||
if (i < (this.expectedTokenSequences[b1]).length)
|
||||
i = (this.expectedTokenSequences[b1]).length;
|
||||
for (byte b = 0; b < (this.expectedTokenSequences[b1]).length; b++)
|
||||
str = str + this.tokenImage[this.expectedTokenSequences[b1][b]] + " ";
|
||||
if (this.expectedTokenSequences[b1][(this.expectedTokenSequences[b1]).length - 1] != 0)
|
||||
str = str + "...";
|
||||
str = str + this.eol + " ";
|
||||
}
|
||||
null = "Encountered \"";
|
||||
Token token = this.currentToken.next;
|
||||
for (byte b2 = 0; b2 < i; b2++) {
|
||||
if (b2 != 0)
|
||||
null = null + " ";
|
||||
if (token.kind == 0) {
|
||||
null = null + this.tokenImage[0];
|
||||
break;
|
||||
}
|
||||
null = null + add_escapes(token.image);
|
||||
token = token.next;
|
||||
}
|
||||
null = null + "\" at line " + this.currentToken.next.beginLine + ", column " + this.currentToken.next.beginColumn;
|
||||
null = null + "." + this.eol;
|
||||
if (this.expectedTokenSequences.length == 1) {
|
||||
null = null + "Was expecting:" + this.eol + " ";
|
||||
} else {
|
||||
null = null + "Was expecting one of:" + this.eol + " ";
|
||||
}
|
||||
return null + str;
|
||||
}
|
||||
|
||||
public String getErrorInfo() {
|
||||
if (!this.specialConstructor)
|
||||
try {
|
||||
return super.getMessage() + " at column " + this.currentToken.next.beginColumn + ".";
|
||||
} catch (Exception exception) {
|
||||
return super.getMessage();
|
||||
}
|
||||
String str = "";
|
||||
int i = 0;
|
||||
for (byte b1 = 0; b1 < this.expectedTokenSequences.length; b1++) {
|
||||
if (i < (this.expectedTokenSequences[b1]).length)
|
||||
i = (this.expectedTokenSequences[b1]).length;
|
||||
for (byte b = 0; b < (this.expectedTokenSequences[b1]).length; b++)
|
||||
str = str + this.tokenImage[this.expectedTokenSequences[b1][b]] + " ";
|
||||
if (this.expectedTokenSequences[b1][(this.expectedTokenSequences[b1]).length - 1] != 0)
|
||||
str = str + "...";
|
||||
str = str + this.eol + " ";
|
||||
}
|
||||
null = "Unexpected \"";
|
||||
Token token = this.currentToken.next;
|
||||
for (byte b2 = 0; b2 < i; b2++) {
|
||||
if (b2 != 0)
|
||||
null = null + " ";
|
||||
if (token.kind == 0) {
|
||||
null = null + this.tokenImage[0];
|
||||
break;
|
||||
}
|
||||
null = null + add_escapes(token.image);
|
||||
token = token.next;
|
||||
}
|
||||
return null + "\" at column " + this.currentToken.next.beginColumn + ".";
|
||||
}
|
||||
|
||||
protected String add_escapes(String paramString) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
for (byte b = 0; b < paramString.length(); b++) {
|
||||
char c;
|
||||
switch (paramString.charAt(b)) {
|
||||
case '\000':
|
||||
break;
|
||||
case '\b':
|
||||
stringBuffer.append("\\b");
|
||||
break;
|
||||
case '\t':
|
||||
stringBuffer.append("\\t");
|
||||
break;
|
||||
case '\n':
|
||||
stringBuffer.append("\\n");
|
||||
break;
|
||||
case '\f':
|
||||
stringBuffer.append("\\f");
|
||||
break;
|
||||
case '\r':
|
||||
stringBuffer.append("\\r");
|
||||
break;
|
||||
case '"':
|
||||
stringBuffer.append("\\\"");
|
||||
break;
|
||||
case '\'':
|
||||
stringBuffer.append("\\'");
|
||||
break;
|
||||
case '\\':
|
||||
stringBuffer.append("\\\\");
|
||||
break;
|
||||
default:
|
||||
if ((c = paramString.charAt(b)) < ' ' || c > '~') {
|
||||
String str = "0000" + Integer.toString(c, 16);
|
||||
stringBuffer.append("\\u" + str.substring(str.length() - 4, str.length()));
|
||||
break;
|
||||
}
|
||||
stringBuffer.append(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
}
|
1799
hrmsEjb/org/nfunk/jep/Parser.java
Normal file
1799
hrmsEjb/org/nfunk/jep/Parser.java
Normal file
File diff suppressed because it is too large
Load Diff
86
hrmsEjb/org/nfunk/jep/ParserConstants.java
Normal file
86
hrmsEjb/org/nfunk/jep/ParserConstants.java
Normal file
@@ -0,0 +1,86 @@
|
||||
package org.nfunk.jep;
|
||||
|
||||
public interface ParserConstants {
|
||||
public static final int EOF = 0;
|
||||
|
||||
public static final int INTEGER_LITERAL = 7;
|
||||
|
||||
public static final int DECIMAL_LITERAL = 8;
|
||||
|
||||
public static final int FLOATING_POINT_LITERAL = 9;
|
||||
|
||||
public static final int EXPONENT = 10;
|
||||
|
||||
public static final int STRING_LITERAL = 11;
|
||||
|
||||
public static final int INDENTIFIER1 = 12;
|
||||
|
||||
public static final int LETTER1 = 13;
|
||||
|
||||
public static final int DIGIT1 = 14;
|
||||
|
||||
public static final int INDENTIFIER2 = 15;
|
||||
|
||||
public static final int LETTER2 = 16;
|
||||
|
||||
public static final int DIGIT2 = 17;
|
||||
|
||||
public static final int ASSIGN = 18;
|
||||
|
||||
public static final int SEMI = 19;
|
||||
|
||||
public static final int COMMA = 20;
|
||||
|
||||
public static final int GT = 21;
|
||||
|
||||
public static final int LT = 22;
|
||||
|
||||
public static final int EQ = 23;
|
||||
|
||||
public static final int LE = 24;
|
||||
|
||||
public static final int GE = 25;
|
||||
|
||||
public static final int NE = 26;
|
||||
|
||||
public static final int AND = 27;
|
||||
|
||||
public static final int OR = 28;
|
||||
|
||||
public static final int PLUS = 29;
|
||||
|
||||
public static final int MINUS = 30;
|
||||
|
||||
public static final int MUL = 31;
|
||||
|
||||
public static final int DOT = 32;
|
||||
|
||||
public static final int DIV = 33;
|
||||
|
||||
public static final int MOD = 34;
|
||||
|
||||
public static final int NOT = 35;
|
||||
|
||||
public static final int POWER = 36;
|
||||
|
||||
public static final int CROSS = 37;
|
||||
|
||||
public static final int LSQ = 38;
|
||||
|
||||
public static final int RSQ = 39;
|
||||
|
||||
public static final int LRND = 40;
|
||||
|
||||
public static final int RRND = 41;
|
||||
|
||||
public static final int NO_DOT_IN_IDENTIFIERS = 0;
|
||||
|
||||
public static final int DEFAULT = 1;
|
||||
|
||||
public static final String[] tokenImage = new String[] {
|
||||
"<EOF>", "\" \"", "\"\\t\"", "\"\\n\"", "\"\\r\"", "<token of kind 5>", "<token of kind 6>", "<INTEGER_LITERAL>", "<DECIMAL_LITERAL>", "<FLOATING_POINT_LITERAL>",
|
||||
"<EXPONENT>", "<STRING_LITERAL>", "<INDENTIFIER1>", "<LETTER1>", "<DIGIT1>", "<INDENTIFIER2>", "<LETTER2>", "<DIGIT2>", "\"=\"", "\";\"",
|
||||
"\",\"", "\">\"", "\"<\"", "\"==\"", "\"<=\"", "\">=\"", "\"!=\"", "\"&&\"", "\"||\"", "\"+\"",
|
||||
"\"-\"", "\"*\"", "\".\"", "\"/\"", "\"%\"", "\"!\"", "\"^\"", "\"^^\"", "\"[\"", "\"]\"",
|
||||
"\"(\"", "\")\"" };
|
||||
}
|
52
hrmsEjb/org/nfunk/jep/ParserDumpVisitor.java
Normal file
52
hrmsEjb/org/nfunk/jep/ParserDumpVisitor.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package org.nfunk.jep;
|
||||
|
||||
public class ParserDumpVisitor implements ParserVisitor {
|
||||
private int indent = 0;
|
||||
|
||||
private String indentString() {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
for (byte b = 0; b < this.indent; b++)
|
||||
stringBuffer.append(" ");
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
public Object visit(SimpleNode paramSimpleNode, Object paramObject) throws ParseException {
|
||||
System.out.println(indentString() + paramSimpleNode + ": acceptor not unimplemented in subclass?");
|
||||
this.indent++;
|
||||
paramObject = paramSimpleNode.childrenAccept(this, paramObject);
|
||||
this.indent--;
|
||||
return paramObject;
|
||||
}
|
||||
|
||||
public Object visit(ASTStart paramASTStart, Object paramObject) throws ParseException {
|
||||
System.out.println(indentString() + paramASTStart);
|
||||
this.indent++;
|
||||
paramObject = paramASTStart.childrenAccept(this, paramObject);
|
||||
this.indent--;
|
||||
return paramObject;
|
||||
}
|
||||
|
||||
public Object visit(ASTFunNode paramASTFunNode, Object paramObject) throws ParseException {
|
||||
System.out.println(indentString() + paramASTFunNode);
|
||||
this.indent++;
|
||||
paramObject = paramASTFunNode.childrenAccept(this, paramObject);
|
||||
this.indent--;
|
||||
return paramObject;
|
||||
}
|
||||
|
||||
public Object visit(ASTVarNode paramASTVarNode, Object paramObject) throws ParseException {
|
||||
System.out.println(indentString() + paramASTVarNode);
|
||||
this.indent++;
|
||||
paramObject = paramASTVarNode.childrenAccept(this, paramObject);
|
||||
this.indent--;
|
||||
return paramObject;
|
||||
}
|
||||
|
||||
public Object visit(ASTConstant paramASTConstant, Object paramObject) throws ParseException {
|
||||
System.out.println(indentString() + paramASTConstant);
|
||||
this.indent++;
|
||||
paramObject = paramASTConstant.childrenAccept(this, paramObject);
|
||||
this.indent--;
|
||||
return paramObject;
|
||||
}
|
||||
}
|
1226
hrmsEjb/org/nfunk/jep/ParserTokenManager.java
Normal file
1226
hrmsEjb/org/nfunk/jep/ParserTokenManager.java
Normal file
File diff suppressed because it is too large
Load Diff
15
hrmsEjb/org/nfunk/jep/ParserTreeConstants.java
Normal file
15
hrmsEjb/org/nfunk/jep/ParserTreeConstants.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package org.nfunk.jep;
|
||||
|
||||
public interface ParserTreeConstants {
|
||||
public static final int JJTSTART = 0;
|
||||
|
||||
public static final int JJTVOID = 1;
|
||||
|
||||
public static final int JJTFUNNODE = 2;
|
||||
|
||||
public static final int JJTVARNODE = 3;
|
||||
|
||||
public static final int JJTCONSTANT = 4;
|
||||
|
||||
public static final String[] jjtNodeName = new String[] { "Start", "void", "FunNode", "VarNode", "Constant" };
|
||||
}
|
13
hrmsEjb/org/nfunk/jep/ParserVisitor.java
Normal file
13
hrmsEjb/org/nfunk/jep/ParserVisitor.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package org.nfunk.jep;
|
||||
|
||||
public interface ParserVisitor {
|
||||
Object visit(SimpleNode paramSimpleNode, Object paramObject) throws ParseException;
|
||||
|
||||
Object visit(ASTStart paramASTStart, Object paramObject) throws ParseException;
|
||||
|
||||
Object visit(ASTFunNode paramASTFunNode, Object paramObject) throws ParseException;
|
||||
|
||||
Object visit(ASTVarNode paramASTVarNode, Object paramObject) throws ParseException;
|
||||
|
||||
Object visit(ASTConstant paramASTConstant, Object paramObject) throws ParseException;
|
||||
}
|
84
hrmsEjb/org/nfunk/jep/SimpleNode.java
Normal file
84
hrmsEjb/org/nfunk/jep/SimpleNode.java
Normal file
@@ -0,0 +1,84 @@
|
||||
package org.nfunk.jep;
|
||||
|
||||
public class SimpleNode implements Node {
|
||||
protected Node parent;
|
||||
|
||||
protected Node[] children;
|
||||
|
||||
protected int id;
|
||||
|
||||
protected Parser parser;
|
||||
|
||||
public SimpleNode(int paramInt) {
|
||||
this.id = paramInt;
|
||||
}
|
||||
|
||||
public SimpleNode(Parser paramParser, int paramInt) {
|
||||
this(paramInt);
|
||||
this.parser = paramParser;
|
||||
}
|
||||
|
||||
public void jjtOpen() {}
|
||||
|
||||
public void jjtClose() {}
|
||||
|
||||
public void jjtSetParent(Node paramNode) {
|
||||
this.parent = paramNode;
|
||||
}
|
||||
|
||||
public Node jjtGetParent() {
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
public void jjtAddChild(Node paramNode, int paramInt) {
|
||||
if (this.children == null) {
|
||||
this.children = new Node[paramInt + 1];
|
||||
} else if (paramInt >= this.children.length) {
|
||||
Node[] arrayOfNode = new Node[paramInt + 1];
|
||||
System.arraycopy(this.children, 0, arrayOfNode, 0, this.children.length);
|
||||
this.children = arrayOfNode;
|
||||
}
|
||||
this.children[paramInt] = paramNode;
|
||||
}
|
||||
|
||||
public Node jjtGetChild(int paramInt) {
|
||||
return this.children[paramInt];
|
||||
}
|
||||
|
||||
public int jjtGetNumChildren() {
|
||||
return (this.children == null) ? 0 : this.children.length;
|
||||
}
|
||||
|
||||
public Object jjtAccept(ParserVisitor paramParserVisitor, Object paramObject) throws ParseException {
|
||||
return paramParserVisitor.visit(this, paramObject);
|
||||
}
|
||||
|
||||
public Object childrenAccept(ParserVisitor paramParserVisitor, Object paramObject) throws ParseException {
|
||||
if (this.children != null)
|
||||
for (byte b = 0; b < this.children.length; b++)
|
||||
this.children[b].jjtAccept(paramParserVisitor, paramObject);
|
||||
return paramObject;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return ParserTreeConstants.jjtNodeName[this.id];
|
||||
}
|
||||
|
||||
public String toString(String paramString) {
|
||||
return paramString + toString();
|
||||
}
|
||||
|
||||
public void dump(String paramString) {
|
||||
System.out.println(toString(paramString));
|
||||
if (this.children != null)
|
||||
for (byte b = 0; b < this.children.length; b++) {
|
||||
SimpleNode simpleNode = (SimpleNode)this.children[b];
|
||||
if (simpleNode != null)
|
||||
simpleNode.dump(paramString + " ");
|
||||
}
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
97
hrmsEjb/org/nfunk/jep/SymbolTable.java
Normal file
97
hrmsEjb/org/nfunk/jep/SymbolTable.java
Normal file
@@ -0,0 +1,97 @@
|
||||
package org.nfunk.jep;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
|
||||
public class SymbolTable extends Hashtable {
|
||||
protected VariableFactory vf;
|
||||
|
||||
public SymbolTable(VariableFactory paramVariableFactory) {
|
||||
this.vf = paramVariableFactory;
|
||||
}
|
||||
|
||||
private SymbolTable() {}
|
||||
|
||||
public Object get(Object paramObject) {
|
||||
return getValue(paramObject);
|
||||
}
|
||||
|
||||
public Object getValue(Object paramObject) {
|
||||
Variable variable = super.get(paramObject);
|
||||
return (variable == null) ? null : variable.getValue();
|
||||
}
|
||||
|
||||
public Variable getVar(String paramString) {
|
||||
return super.get(paramString);
|
||||
}
|
||||
|
||||
public Object put(Object paramObject1, Object paramObject2) {
|
||||
return makeVarIfNeeded((String)paramObject1, paramObject2);
|
||||
}
|
||||
|
||||
public boolean setVarValue(String paramString, Object paramObject) {
|
||||
Variable variable = super.get(paramString);
|
||||
return (variable != null) ? variable.setValue(paramObject) : false;
|
||||
}
|
||||
|
||||
public Variable addVariable(String paramString, Object paramObject) {
|
||||
Variable variable = super.get(paramString);
|
||||
if (variable != null)
|
||||
return null;
|
||||
variable = this.vf.createVariable(paramString, paramObject);
|
||||
super.put(paramString, variable);
|
||||
variable.setValidValue(true);
|
||||
return variable;
|
||||
}
|
||||
|
||||
public Variable addConstant(String paramString, Object paramObject) {
|
||||
Variable variable = addVariable(paramString, paramObject);
|
||||
if (variable != null)
|
||||
variable.setIsConstant(true);
|
||||
return variable;
|
||||
}
|
||||
|
||||
public Variable makeVarIfNeeded(String paramString, Object paramObject) {
|
||||
Variable variable = super.get(paramString);
|
||||
if (variable != null) {
|
||||
variable.setValue(paramObject);
|
||||
return variable;
|
||||
}
|
||||
variable = this.vf.createVariable(paramString, paramObject);
|
||||
super.put(paramString, variable);
|
||||
return variable;
|
||||
}
|
||||
|
||||
public Variable makeVarIfNeeded(String paramString) {
|
||||
Variable variable = super.get(paramString);
|
||||
if (variable != null)
|
||||
return variable;
|
||||
variable = this.vf.createVariable(paramString, null);
|
||||
super.put(paramString, variable);
|
||||
return variable;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
Enumeration enumeration = elements();
|
||||
while (enumeration.hasMoreElements()) {
|
||||
Variable variable = (Variable)enumeration.nextElement();
|
||||
stringBuffer.append(variable.toString());
|
||||
stringBuffer.append("\n");
|
||||
}
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
public void clearValues() {
|
||||
Enumeration enumeration = elements();
|
||||
while (enumeration.hasMoreElements()) {
|
||||
Variable variable = (Variable)enumeration.nextElement();
|
||||
if (!variable.isConstant())
|
||||
variable.setValidValue(false);
|
||||
}
|
||||
}
|
||||
|
||||
public VariableFactory getVariableFactory() {
|
||||
return this.vf;
|
||||
}
|
||||
}
|
30
hrmsEjb/org/nfunk/jep/Token.java
Normal file
30
hrmsEjb/org/nfunk/jep/Token.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package org.nfunk.jep;
|
||||
|
||||
public class Token {
|
||||
public int kind;
|
||||
|
||||
public int beginLine;
|
||||
|
||||
public int beginColumn;
|
||||
|
||||
public int endLine;
|
||||
|
||||
public int endColumn;
|
||||
|
||||
public String image;
|
||||
|
||||
public Token next;
|
||||
|
||||
public Token specialToken;
|
||||
|
||||
public String toString() {
|
||||
return this.image;
|
||||
}
|
||||
|
||||
public static final Token newToken(int paramInt) {
|
||||
switch (paramInt) {
|
||||
|
||||
}
|
||||
return new Token();
|
||||
}
|
||||
}
|
76
hrmsEjb/org/nfunk/jep/TokenMgrError.java
Normal file
76
hrmsEjb/org/nfunk/jep/TokenMgrError.java
Normal file
@@ -0,0 +1,76 @@
|
||||
package org.nfunk.jep;
|
||||
|
||||
public class TokenMgrError extends Error {
|
||||
static final int LEXICAL_ERROR = 0;
|
||||
|
||||
static final int STATIC_LEXER_ERROR = 1;
|
||||
|
||||
static final int INVALID_LEXICAL_STATE = 2;
|
||||
|
||||
static final int LOOP_DETECTED = 3;
|
||||
|
||||
int errorCode;
|
||||
|
||||
protected static final String addEscapes(String paramString) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
for (byte b = 0; b < paramString.length(); b++) {
|
||||
char c;
|
||||
switch (paramString.charAt(b)) {
|
||||
case '\000':
|
||||
break;
|
||||
case '\b':
|
||||
stringBuffer.append("\\b");
|
||||
break;
|
||||
case '\t':
|
||||
stringBuffer.append("\\t");
|
||||
break;
|
||||
case '\n':
|
||||
stringBuffer.append("\\n");
|
||||
break;
|
||||
case '\f':
|
||||
stringBuffer.append("\\f");
|
||||
break;
|
||||
case '\r':
|
||||
stringBuffer.append("\\r");
|
||||
break;
|
||||
case '"':
|
||||
stringBuffer.append("\\\"");
|
||||
break;
|
||||
case '\'':
|
||||
stringBuffer.append("\\'");
|
||||
break;
|
||||
case '\\':
|
||||
stringBuffer.append("\\\\");
|
||||
break;
|
||||
default:
|
||||
if ((c = paramString.charAt(b)) < ' ' || c > '~') {
|
||||
String str = "0000" + Integer.toString(c, 16);
|
||||
stringBuffer.append("\\u" + str.substring(str.length() - 4, str.length()));
|
||||
break;
|
||||
}
|
||||
stringBuffer.append(c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
protected static String LexicalError(boolean paramBoolean, int paramInt1, int paramInt2, int paramInt3, String paramString, char paramChar) {
|
||||
return "Lexical error at line " + paramInt2 + ", column " + paramInt3 + ". Encountered: " + (paramBoolean ? "<EOF> " : ("\"" + addEscapes(String.valueOf(paramChar)) + "\"" + " (" + paramChar + "), ")) + "after : \"" + addEscapes(paramString) + "\"";
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return super.getMessage();
|
||||
}
|
||||
|
||||
public TokenMgrError() {}
|
||||
|
||||
public TokenMgrError(String paramString, int paramInt) {
|
||||
super(paramString);
|
||||
this.errorCode = paramInt;
|
||||
}
|
||||
|
||||
public TokenMgrError(boolean paramBoolean, int paramInt1, int paramInt2, int paramInt3, String paramString, char paramChar, int paramInt4) {
|
||||
this(LexicalError(paramBoolean, paramInt1, paramInt2, paramInt3, paramString, paramChar), paramInt4);
|
||||
}
|
||||
}
|
69
hrmsEjb/org/nfunk/jep/Variable.java
Normal file
69
hrmsEjb/org/nfunk/jep/Variable.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package org.nfunk.jep;
|
||||
|
||||
import java.util.Observable;
|
||||
|
||||
public class Variable extends Observable {
|
||||
protected String name;
|
||||
|
||||
private Object value;
|
||||
|
||||
private boolean isConstant = false;
|
||||
|
||||
private boolean validValue = false;
|
||||
|
||||
protected Variable(String paramString) {
|
||||
this.name = paramString;
|
||||
this.value = null;
|
||||
this.validValue = false;
|
||||
}
|
||||
|
||||
protected Variable(String paramString, Object paramObject) {
|
||||
this.name = paramString;
|
||||
this.value = paramObject;
|
||||
this.validValue = (paramObject != null);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public boolean isConstant() {
|
||||
return this.isConstant;
|
||||
}
|
||||
|
||||
public void setIsConstant(boolean paramBoolean) {
|
||||
this.isConstant = paramBoolean;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public boolean hasValidValue() {
|
||||
return this.validValue;
|
||||
}
|
||||
|
||||
public void setValidValue(boolean paramBoolean) {
|
||||
this.validValue = paramBoolean;
|
||||
}
|
||||
|
||||
public boolean setValue(Object paramObject) {
|
||||
if (!setValueRaw(paramObject))
|
||||
return false;
|
||||
setChanged();
|
||||
notifyObservers();
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean setValueRaw(Object paramObject) {
|
||||
if (this.isConstant)
|
||||
return false;
|
||||
this.validValue = true;
|
||||
this.value = paramObject;
|
||||
return true;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return (!this.validValue || this.value == null) ? (this.name + ": null") : (this.isConstant ? (this.name + ": " + this.value.toString() + " (Constant)") : (this.name + ": " + this.value.toString()));
|
||||
}
|
||||
}
|
11
hrmsEjb/org/nfunk/jep/VariableFactory.java
Normal file
11
hrmsEjb/org/nfunk/jep/VariableFactory.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package org.nfunk.jep;
|
||||
|
||||
public class VariableFactory {
|
||||
public Variable createVariable(String paramString, Object paramObject) {
|
||||
return new Variable(paramString, paramObject);
|
||||
}
|
||||
|
||||
public Variable createVariable(String paramString) {
|
||||
return new Variable(paramString);
|
||||
}
|
||||
}
|
21
hrmsEjb/org/nfunk/jep/function/Abs.java
Normal file
21
hrmsEjb/org/nfunk/jep/function/Abs.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Abs extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(abs(object));
|
||||
}
|
||||
|
||||
public Object abs(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return new Double(((Complex)paramObject).abs());
|
||||
if (paramObject instanceof Number)
|
||||
return new Double(Math.abs(((Number)paramObject).doubleValue()));
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
46
hrmsEjb/org/nfunk/jep/function/Add.java
Normal file
46
hrmsEjb/org/nfunk/jep/function/Add.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Add extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
for (byte b = 1; b < this.curNumberOfParameters; b++) {
|
||||
Object object1 = paramStack.pop();
|
||||
object = add(object1, object);
|
||||
}
|
||||
paramStack.push(object);
|
||||
}
|
||||
|
||||
public Object add(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
if (paramObject1 instanceof Complex) {
|
||||
if (paramObject2 instanceof Complex)
|
||||
return add((Complex)paramObject1, (Complex)paramObject2);
|
||||
if (paramObject2 instanceof Number)
|
||||
return add((Complex)paramObject1, (Number)paramObject2);
|
||||
} else if (paramObject1 instanceof Number) {
|
||||
if (paramObject2 instanceof Complex)
|
||||
return add((Complex)paramObject2, (Number)paramObject1);
|
||||
if (paramObject2 instanceof Number)
|
||||
return add((Number)paramObject1, (Number)paramObject2);
|
||||
} else if (paramObject1 instanceof String && paramObject2 instanceof String) {
|
||||
return (String)paramObject1 + (String)paramObject2;
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
|
||||
public Double add(Number paramNumber1, Number paramNumber2) {
|
||||
return new Double(paramNumber1.doubleValue() + paramNumber2.doubleValue());
|
||||
}
|
||||
|
||||
public Complex add(Complex paramComplex1, Complex paramComplex2) {
|
||||
return new Complex(paramComplex1.re() + paramComplex2.re(), paramComplex1.im() + paramComplex2.im());
|
||||
}
|
||||
|
||||
public Complex add(Complex paramComplex, Number paramNumber) {
|
||||
return new Complex(paramComplex.re() + paramNumber.doubleValue(), paramComplex.im());
|
||||
}
|
||||
}
|
21
hrmsEjb/org/nfunk/jep/function/ArcCosine.java
Normal file
21
hrmsEjb/org/nfunk/jep/function/ArcCosine.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class ArcCosine extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(acos(object));
|
||||
}
|
||||
|
||||
public Object acos(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).acos();
|
||||
if (paramObject instanceof Number)
|
||||
return new Double(Math.acos(((Number)paramObject).doubleValue()));
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
28
hrmsEjb/org/nfunk/jep/function/ArcCosineH.java
Normal file
28
hrmsEjb/org/nfunk/jep/function/ArcCosineH.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class ArcCosineH extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(acosh(object));
|
||||
}
|
||||
|
||||
public Object acosh(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).acosh();
|
||||
if (paramObject instanceof Number) {
|
||||
double d = ((Number)paramObject).doubleValue();
|
||||
if (d >= 1.0D) {
|
||||
double d1 = Math.log(d + Math.sqrt(d * d - 1.0D));
|
||||
return new Double(d1);
|
||||
}
|
||||
Complex complex = new Complex(((Number)paramObject).doubleValue(), 0.0D);
|
||||
return complex.acosh();
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
21
hrmsEjb/org/nfunk/jep/function/ArcSine.java
Normal file
21
hrmsEjb/org/nfunk/jep/function/ArcSine.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class ArcSine extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(asin(object));
|
||||
}
|
||||
|
||||
public Object asin(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).asin();
|
||||
if (paramObject instanceof Number)
|
||||
return new Double(Math.asin(((Number)paramObject).doubleValue()));
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
24
hrmsEjb/org/nfunk/jep/function/ArcSineH.java
Normal file
24
hrmsEjb/org/nfunk/jep/function/ArcSineH.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class ArcSineH extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(asinh(object));
|
||||
}
|
||||
|
||||
public Object asinh(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).asinh();
|
||||
if (paramObject instanceof Number) {
|
||||
double d1 = ((Number)paramObject).doubleValue();
|
||||
double d2 = Math.log(d1 + Math.sqrt(d1 * d1 + 1.0D));
|
||||
return new Double(d2);
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
28
hrmsEjb/org/nfunk/jep/function/ArcTanH.java
Normal file
28
hrmsEjb/org/nfunk/jep/function/ArcTanH.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class ArcTanH extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(atanh(object));
|
||||
}
|
||||
|
||||
public Object atanh(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).atanh();
|
||||
if (paramObject instanceof Number) {
|
||||
double d = ((Number)paramObject).doubleValue();
|
||||
if (d > -1.0D && d < 1.0D) {
|
||||
double d1 = Math.log((1.0D + d) / (1.0D - d)) / 2.0D;
|
||||
return new Double(d1);
|
||||
}
|
||||
Complex complex = new Complex(d, 0.0D);
|
||||
return complex.atanh();
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
21
hrmsEjb/org/nfunk/jep/function/ArcTangent.java
Normal file
21
hrmsEjb/org/nfunk/jep/function/ArcTangent.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class ArcTangent extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(atan(object));
|
||||
}
|
||||
|
||||
public Object atan(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).atan();
|
||||
if (paramObject instanceof Number)
|
||||
return new Double(Math.atan(((Number)paramObject).doubleValue()));
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
19
hrmsEjb/org/nfunk/jep/function/ArcTangent2.java
Normal file
19
hrmsEjb/org/nfunk/jep/function/ArcTangent2.java
Normal file
@@ -0,0 +1,19 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
|
||||
public class ArcTangent2 extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Number number1 = (Number)paramStack.pop();
|
||||
Number number2 = (Number)paramStack.pop();
|
||||
if (number2 instanceof Number && number1 instanceof Number) {
|
||||
double d1 = ((Number)number2).doubleValue();
|
||||
double d2 = ((Number)number1).doubleValue();
|
||||
paramStack.push(new Double(Math.atan2(d1, d2)));
|
||||
} else {
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
||||
}
|
23
hrmsEjb/org/nfunk/jep/function/Arg.java
Normal file
23
hrmsEjb/org/nfunk/jep/function/Arg.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Arg extends PostfixMathCommand {
|
||||
private static final Double ONE = new Double(1.0D);
|
||||
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(arg(object));
|
||||
}
|
||||
|
||||
public Number arg(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return new Double(((Complex)paramObject).arg());
|
||||
if (paramObject instanceof Number)
|
||||
return ONE;
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
26
hrmsEjb/org/nfunk/jep/function/Assign.java
Normal file
26
hrmsEjb/org/nfunk/jep/function/Assign.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ASTVarNode;
|
||||
import org.nfunk.jep.Node;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.ParserVisitor;
|
||||
import org.nfunk.jep.Variable;
|
||||
|
||||
public class Assign extends PostfixMathCommand implements SpecialEvaluationI {
|
||||
public Object evaluate(Node paramNode, Object paramObject, ParserVisitor paramParserVisitor, Stack paramStack) throws ParseException {
|
||||
if (paramNode.jjtGetNumChildren() != 2)
|
||||
throw new ParseException("Assignment opperator must have 2 operators.");
|
||||
paramNode.jjtGetChild(1).jjtAccept(paramParserVisitor, paramObject);
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.peek();
|
||||
Node node = paramNode.jjtGetChild(0);
|
||||
if (node instanceof ASTVarNode) {
|
||||
ASTVarNode aSTVarNode = (ASTVarNode)node;
|
||||
Variable variable = aSTVarNode.getVar();
|
||||
variable.setValue(object);
|
||||
return object;
|
||||
}
|
||||
throw new ParseException("Assignment should have a variable for the lhs.");
|
||||
}
|
||||
}
|
121
hrmsEjb/org/nfunk/jep/function/Comparative.java
Normal file
121
hrmsEjb/org/nfunk/jep/function/Comparative.java
Normal file
@@ -0,0 +1,121 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Comparative extends PostfixMathCommand {
|
||||
int id;
|
||||
|
||||
double tolerance;
|
||||
|
||||
public static final int LT = 0;
|
||||
|
||||
public static final int GT = 1;
|
||||
|
||||
public static final int LE = 2;
|
||||
|
||||
public static final int GE = 3;
|
||||
|
||||
public static final int NE = 4;
|
||||
|
||||
public static final int EQ = 5;
|
||||
|
||||
public Comparative(int paramInt) {
|
||||
this.id = paramInt;
|
||||
this.numberOfParameters = 2;
|
||||
this.tolerance = 1.0E-6D;
|
||||
}
|
||||
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object1 = paramStack.pop();
|
||||
Object object2 = paramStack.pop();
|
||||
boolean bool = false;
|
||||
switch (this.id) {
|
||||
case 0:
|
||||
bool = lt(object2, object1);
|
||||
break;
|
||||
case 1:
|
||||
bool = gt(object2, object1);
|
||||
break;
|
||||
case 2:
|
||||
bool = le(object2, object1);
|
||||
break;
|
||||
case 3:
|
||||
bool = ge(object2, object1);
|
||||
break;
|
||||
case 4:
|
||||
bool = ne(object2, object1);
|
||||
break;
|
||||
case 5:
|
||||
bool = eq(object2, object1);
|
||||
break;
|
||||
}
|
||||
if (bool) {
|
||||
paramStack.push(new Double(1.0D));
|
||||
} else {
|
||||
paramStack.push(new Double(0.0D));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean lt(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
if (paramObject1 instanceof Complex || paramObject2 instanceof Complex)
|
||||
throw new ParseException("< not defined for complex numbers");
|
||||
if (paramObject1 instanceof Number && paramObject2 instanceof Number) {
|
||||
double d1 = ((Number)paramObject1).doubleValue();
|
||||
double d2 = ((Number)paramObject2).doubleValue();
|
||||
return (d1 < d2);
|
||||
}
|
||||
throw new ParseException("< not defined for object of type " + paramObject1.getClass().getName() + " and " + paramObject1.getClass().getName());
|
||||
}
|
||||
|
||||
public boolean gt(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
if (paramObject1 instanceof Complex || paramObject2 instanceof Complex)
|
||||
throw new ParseException("> not defined for complex numbers");
|
||||
if (paramObject1 instanceof Number && paramObject2 instanceof Number) {
|
||||
double d1 = ((Number)paramObject1).doubleValue();
|
||||
double d2 = ((Number)paramObject2).doubleValue();
|
||||
return (d1 > d2);
|
||||
}
|
||||
throw new ParseException("> not defined for object of type " + paramObject1.getClass().getName() + " and " + paramObject1.getClass().getName());
|
||||
}
|
||||
|
||||
public boolean le(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
if (paramObject1 instanceof Complex || paramObject2 instanceof Complex)
|
||||
throw new ParseException("<= not defined for complex numbers");
|
||||
if (paramObject1 instanceof Number && paramObject2 instanceof Number) {
|
||||
double d1 = ((Number)paramObject1).doubleValue();
|
||||
double d2 = ((Number)paramObject2).doubleValue();
|
||||
return (d1 <= d2);
|
||||
}
|
||||
throw new ParseException("<= not defined for object of type " + paramObject1.getClass().getName() + " and " + paramObject1.getClass().getName());
|
||||
}
|
||||
|
||||
public boolean ge(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
if (paramObject1 instanceof Complex || paramObject2 instanceof Complex)
|
||||
throw new ParseException(">= not defined for complex numbers");
|
||||
if (paramObject1 instanceof Number && paramObject2 instanceof Number) {
|
||||
double d1 = ((Number)paramObject1).doubleValue();
|
||||
double d2 = ((Number)paramObject2).doubleValue();
|
||||
return (d1 >= d2);
|
||||
}
|
||||
throw new ParseException(">= not defined for object of type " + paramObject1.getClass().getName() + " and " + paramObject1.getClass().getName());
|
||||
}
|
||||
|
||||
public boolean eq(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
return (paramObject1 instanceof Complex && paramObject2 instanceof Complex) ? ((Complex)paramObject1).equals((Complex)paramObject2, this.tolerance) : ((paramObject1 instanceof Complex && paramObject2 instanceof Double) ? ((Complex)paramObject1).equals(new Complex((Number)paramObject2), this.tolerance) : ((paramObject2 instanceof Complex && paramObject1 instanceof Double) ? ((Complex)paramObject2).equals(new Complex((Number)paramObject1), this.tolerance) : paramObject1.equals(paramObject2)));
|
||||
}
|
||||
|
||||
public boolean ne(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
return (paramObject1 instanceof Complex && paramObject2 instanceof Complex) ? (!((Complex)paramObject1).equals((Complex)paramObject2, this.tolerance)) : ((paramObject1 instanceof Complex && paramObject2 instanceof Double) ? (!((Complex)paramObject1).equals(new Complex((Number)paramObject2), this.tolerance)) : ((paramObject2 instanceof Complex && paramObject1 instanceof Double) ? (!((Complex)paramObject2).equals(new Complex((Number)paramObject1), this.tolerance)) : (!paramObject1.equals(paramObject2))));
|
||||
}
|
||||
|
||||
public double getTolerance() {
|
||||
return this.tolerance;
|
||||
}
|
||||
|
||||
public void setTolerance(double paramDouble) {
|
||||
this.tolerance = paramDouble;
|
||||
}
|
||||
}
|
20
hrmsEjb/org/nfunk/jep/function/ComplexPFMC.java
Normal file
20
hrmsEjb/org/nfunk/jep/function/ComplexPFMC.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class ComplexPFMC extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Number number1 = (Number)paramStack.pop();
|
||||
Number number2 = (Number)paramStack.pop();
|
||||
if (number2 instanceof Number && number1 instanceof Number) {
|
||||
double d1 = ((Number)number2).doubleValue();
|
||||
double d2 = ((Number)number1).doubleValue();
|
||||
paramStack.push(new Complex(d1, d2));
|
||||
} else {
|
||||
throw new ParseException("Complex: Invalid parameter types " + number2.getClass().getName() + " " + number2.getClass().getName());
|
||||
}
|
||||
}
|
||||
}
|
21
hrmsEjb/org/nfunk/jep/function/Cosine.java
Normal file
21
hrmsEjb/org/nfunk/jep/function/Cosine.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Cosine extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(cos(object));
|
||||
}
|
||||
|
||||
public Object cos(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).cos();
|
||||
if (paramObject instanceof Number)
|
||||
return new Double(Math.cos(((Number)paramObject).doubleValue()));
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
23
hrmsEjb/org/nfunk/jep/function/CosineH.java
Normal file
23
hrmsEjb/org/nfunk/jep/function/CosineH.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class CosineH extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(cosh(object));
|
||||
}
|
||||
|
||||
public Object cosh(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).cosh();
|
||||
if (paramObject instanceof Number) {
|
||||
double d = ((Number)paramObject).doubleValue();
|
||||
return new Double((Math.exp(d) + Math.exp(-d)) / 2.0D);
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
39
hrmsEjb/org/nfunk/jep/function/Cross.java
Normal file
39
hrmsEjb/org/nfunk/jep/function/Cross.java
Normal file
@@ -0,0 +1,39 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import java.util.Vector;
|
||||
import org.nfunk.jep.ParseException;
|
||||
|
||||
public class Cross extends PostfixMathCommand {
|
||||
static Subtract sub = new Subtract();
|
||||
|
||||
static Multiply mul = new Multiply();
|
||||
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object1 = paramStack.pop();
|
||||
Object object2 = paramStack.pop();
|
||||
paramStack.push(cross(object2, object1));
|
||||
}
|
||||
|
||||
public Object cross(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
if (paramObject1 instanceof Vector && paramObject2 instanceof Vector)
|
||||
return cross((Vector)paramObject1, (Vector)paramObject2);
|
||||
throw new ParseException("Cross: Invalid parameter type, both arguments must be vectors");
|
||||
}
|
||||
|
||||
public Object cross(Vector paramVector1, Vector paramVector2) throws ParseException {
|
||||
int i = paramVector1.size();
|
||||
if ((i != 2 && i != 3) || i != paramVector2.size())
|
||||
throw new ParseException("Cross: both sides must be of length 3");
|
||||
if (i == 3) {
|
||||
Vector vector = new Vector(3);
|
||||
vector.setSize(3);
|
||||
vector.setElementAt(sub.sub(mul.mul(paramVector1.elementAt(1), paramVector2.elementAt(2)), mul.mul(paramVector1.elementAt(2), paramVector2.elementAt(1))), 0);
|
||||
vector.setElementAt(sub.sub(mul.mul(paramVector1.elementAt(2), paramVector2.elementAt(0)), mul.mul(paramVector1.elementAt(0), paramVector2.elementAt(2))), 1);
|
||||
vector.setElementAt(sub.sub(mul.mul(paramVector1.elementAt(0), paramVector2.elementAt(1)), mul.mul(paramVector1.elementAt(1), paramVector2.elementAt(0))), 2);
|
||||
return vector;
|
||||
}
|
||||
return sub.sub(mul.mul(paramVector1.elementAt(0), paramVector2.elementAt(1)), mul.mul(paramVector1.elementAt(1), paramVector2.elementAt(0)));
|
||||
}
|
||||
}
|
84
hrmsEjb/org/nfunk/jep/function/Divide.java
Normal file
84
hrmsEjb/org/nfunk/jep/function/Divide.java
Normal file
@@ -0,0 +1,84 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import java.util.Vector;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Divide extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object1 = paramStack.pop();
|
||||
Object object2 = paramStack.pop();
|
||||
paramStack.push(div(object2, object1));
|
||||
}
|
||||
|
||||
public Object div(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
if (paramObject1 instanceof Complex) {
|
||||
if (paramObject2 instanceof Complex)
|
||||
return div((Complex)paramObject1, (Complex)paramObject2);
|
||||
if (paramObject2 instanceof Number)
|
||||
return div((Complex)paramObject1, (Number)paramObject2);
|
||||
if (paramObject2 instanceof Vector)
|
||||
return div((Complex)paramObject1, (Vector)paramObject2);
|
||||
} else if (paramObject1 instanceof Number) {
|
||||
if (paramObject2 instanceof Complex)
|
||||
return div((Number)paramObject1, (Complex)paramObject2);
|
||||
if (paramObject2 instanceof Number)
|
||||
return div((Number)paramObject1, (Number)paramObject2);
|
||||
if (paramObject2 instanceof Vector)
|
||||
return div((Number)paramObject1, (Vector)paramObject2);
|
||||
} else if (paramObject1 instanceof Vector) {
|
||||
if (paramObject2 instanceof Complex)
|
||||
return div((Vector)paramObject1, (Complex)paramObject2);
|
||||
if (paramObject2 instanceof Number)
|
||||
return div((Vector)paramObject1, (Number)paramObject2);
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
|
||||
public Double div(Number paramNumber1, Number paramNumber2) {
|
||||
return new Double(paramNumber1.doubleValue() / paramNumber2.doubleValue());
|
||||
}
|
||||
|
||||
public Complex div(Complex paramComplex1, Complex paramComplex2) {
|
||||
return paramComplex1.div(paramComplex2);
|
||||
}
|
||||
|
||||
public Complex div(Number paramNumber, Complex paramComplex) {
|
||||
Complex complex = new Complex(paramNumber.doubleValue(), 0.0D);
|
||||
return complex.div(paramComplex);
|
||||
}
|
||||
|
||||
public Complex div(Complex paramComplex, Number paramNumber) {
|
||||
return new Complex(paramComplex.re() / paramNumber.doubleValue(), paramComplex.im() / paramNumber.doubleValue());
|
||||
}
|
||||
|
||||
public Vector div(Vector paramVector, Number paramNumber) {
|
||||
Vector vector = new Vector();
|
||||
for (byte b = 0; b < paramVector.size(); b++)
|
||||
vector.addElement(div(paramVector.elementAt(b), paramNumber));
|
||||
return vector;
|
||||
}
|
||||
|
||||
public Vector div(Number paramNumber, Vector paramVector) {
|
||||
Vector vector = new Vector();
|
||||
for (byte b = 0; b < paramVector.size(); b++)
|
||||
vector.addElement(div(paramNumber, paramVector.elementAt(b)));
|
||||
return vector;
|
||||
}
|
||||
|
||||
public Vector div(Vector paramVector, Complex paramComplex) {
|
||||
Vector vector = new Vector();
|
||||
for (byte b = 0; b < paramVector.size(); b++)
|
||||
vector.addElement(div(paramVector.elementAt(b), paramComplex));
|
||||
return vector;
|
||||
}
|
||||
|
||||
public Vector div(Complex paramComplex, Vector paramVector) {
|
||||
Vector vector = new Vector();
|
||||
for (byte b = 0; b < paramVector.size(); b++)
|
||||
vector.addElement(div(paramComplex, paramVector.elementAt(b)));
|
||||
return vector;
|
||||
}
|
||||
}
|
36
hrmsEjb/org/nfunk/jep/function/Dot.java
Normal file
36
hrmsEjb/org/nfunk/jep/function/Dot.java
Normal file
@@ -0,0 +1,36 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import java.util.Vector;
|
||||
import org.nfunk.jep.ParseException;
|
||||
|
||||
public class Dot extends PostfixMathCommand {
|
||||
static Add add = new Add();
|
||||
|
||||
static Multiply mul = new Multiply();
|
||||
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object1 = paramStack.pop();
|
||||
Object object2 = paramStack.pop();
|
||||
paramStack.push(dot(object2, object1));
|
||||
}
|
||||
|
||||
public Object dot(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
if (paramObject1 instanceof Vector && paramObject2 instanceof Vector)
|
||||
return dot((Vector)paramObject1, (Vector)paramObject2);
|
||||
throw new ParseException("Dot: Invalid parameter type, both arguments must be vectors");
|
||||
}
|
||||
|
||||
public Object dot(Vector paramVector1, Vector paramVector2) throws ParseException {
|
||||
if (paramVector1.size() != paramVector2.size())
|
||||
throw new ParseException("Dot: both sides of dot must be same length");
|
||||
int i = paramVector1.size();
|
||||
if (i < 1)
|
||||
throw new ParseException("Dot: empty vectors parsed");
|
||||
Object object = mul.mul(paramVector1.elementAt(0), paramVector2.elementAt(0));
|
||||
for (byte b = 1; b < i; b++)
|
||||
object = add.add(object, mul.mul(paramVector1.elementAt(b), paramVector2.elementAt(b)));
|
||||
return object;
|
||||
}
|
||||
}
|
26
hrmsEjb/org/nfunk/jep/function/Exp.java
Normal file
26
hrmsEjb/org/nfunk/jep/function/Exp.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Exp extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(exp(object));
|
||||
}
|
||||
|
||||
public Object exp(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex) {
|
||||
Complex complex = (Complex)paramObject;
|
||||
double d1 = complex.re();
|
||||
double d2 = complex.im();
|
||||
double d3 = Math.exp(d1);
|
||||
return new Complex(d3 * Math.cos(d2), d3 * Math.sin(d2));
|
||||
}
|
||||
if (paramObject instanceof Number)
|
||||
return new Double(Math.exp(((Number)paramObject).doubleValue()));
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
34
hrmsEjb/org/nfunk/jep/function/If.java
Normal file
34
hrmsEjb/org/nfunk/jep/function/If.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.Node;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.ParserVisitor;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class If extends PostfixMathCommand implements SpecialEvaluationI {
|
||||
public Object evaluate(Node paramNode, Object paramObject, ParserVisitor paramParserVisitor, Stack paramStack) throws ParseException {
|
||||
double d;
|
||||
int i = paramNode.jjtGetNumChildren();
|
||||
if (i < 3 || i > 4)
|
||||
throw new ParseException("If operator must have 3 or 4 arguments.");
|
||||
paramNode.jjtGetChild(0).jjtAccept(paramParserVisitor, paramObject);
|
||||
checkStack(paramStack);
|
||||
Double double_ = (Double)paramStack.pop();
|
||||
if (double_ instanceof Double) {
|
||||
d = ((Double)double_).doubleValue();
|
||||
} else if (double_ instanceof Complex) {
|
||||
d = ((Complex)double_).re();
|
||||
} else {
|
||||
throw new ParseException("Condition in if operator must be double or complex");
|
||||
}
|
||||
if (d > 0.0D) {
|
||||
paramNode.jjtGetChild(1).jjtAccept(paramParserVisitor, paramObject);
|
||||
} else if (i == 3 || d < 0.0D) {
|
||||
paramNode.jjtGetChild(2).jjtAccept(paramParserVisitor, paramObject);
|
||||
} else {
|
||||
paramNode.jjtGetChild(3).jjtAccept(paramParserVisitor, paramObject);
|
||||
}
|
||||
return paramObject;
|
||||
}
|
||||
}
|
21
hrmsEjb/org/nfunk/jep/function/Imaginary.java
Normal file
21
hrmsEjb/org/nfunk/jep/function/Imaginary.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Imaginary extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(im(object));
|
||||
}
|
||||
|
||||
public Number im(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return new Double(((Complex)paramObject).im());
|
||||
if (paramObject instanceof Number)
|
||||
return new Double(0.0D);
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
20
hrmsEjb/org/nfunk/jep/function/List.java
Normal file
20
hrmsEjb/org/nfunk/jep/function/List.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import java.util.Vector;
|
||||
import org.nfunk.jep.ParseException;
|
||||
|
||||
public class List extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
if (this.curNumberOfParameters < 1)
|
||||
throw new ParseException("Empty list");
|
||||
Vector vector = new Vector(this.curNumberOfParameters);
|
||||
vector.setSize(this.curNumberOfParameters);
|
||||
for (int i = this.curNumberOfParameters - 1; i >= 0; i--) {
|
||||
Object object = paramStack.pop();
|
||||
vector.setElementAt(object, i);
|
||||
}
|
||||
paramStack.push(vector);
|
||||
}
|
||||
}
|
30
hrmsEjb/org/nfunk/jep/function/Logarithm.java
Normal file
30
hrmsEjb/org/nfunk/jep/function/Logarithm.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Logarithm extends PostfixMathCommand {
|
||||
private static final double LOG10 = Math.log(10.0D);
|
||||
|
||||
private static final Complex CLOG10 = new Complex(Math.log(10.0D), 0.0D);
|
||||
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(log(object));
|
||||
}
|
||||
|
||||
public Object log(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).log().div(CLOG10);
|
||||
if (paramObject instanceof Number) {
|
||||
double d = ((Number)paramObject).doubleValue();
|
||||
if (d > 0.0D)
|
||||
return new Double(Math.log(d) / LOG10);
|
||||
Complex complex = new Complex(d);
|
||||
return complex.log().div(CLOG10);
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
42
hrmsEjb/org/nfunk/jep/function/Logical.java
Normal file
42
hrmsEjb/org/nfunk/jep/function/Logical.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
|
||||
public class Logical extends PostfixMathCommand {
|
||||
int id;
|
||||
|
||||
public static final int AND = 0;
|
||||
|
||||
public static final int OR = 1;
|
||||
|
||||
public Logical(int paramInt) {
|
||||
this.id = paramInt;
|
||||
this.numberOfParameters = 2;
|
||||
}
|
||||
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Number number1 = (Number)paramStack.pop();
|
||||
Number number2 = (Number)paramStack.pop();
|
||||
if (number2 instanceof Number && number1 instanceof Number) {
|
||||
boolean bool;
|
||||
double d1 = ((Number)number2).doubleValue();
|
||||
double d2 = ((Number)number1).doubleValue();
|
||||
switch (this.id) {
|
||||
case 0:
|
||||
bool = (d1 != 0.0D && d2 != 0.0D) ? true : false;
|
||||
break;
|
||||
case 1:
|
||||
bool = (d1 != 0.0D || d2 != 0.0D) ? true : false;
|
||||
break;
|
||||
default:
|
||||
bool = false;
|
||||
break;
|
||||
}
|
||||
paramStack.push(new Double(bool));
|
||||
} else {
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
||||
}
|
20
hrmsEjb/org/nfunk/jep/function/Modulus.java
Normal file
20
hrmsEjb/org/nfunk/jep/function/Modulus.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
|
||||
public class Modulus extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Number number1 = (Number)paramStack.pop();
|
||||
Number number2 = (Number)paramStack.pop();
|
||||
if (number2 instanceof Number && number1 instanceof Number) {
|
||||
double d1 = ((Number)number1).doubleValue();
|
||||
double d2 = ((Number)number2).doubleValue();
|
||||
double d3 = d2 % d1;
|
||||
paramStack.push(new Double(d3));
|
||||
} else {
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
||||
}
|
68
hrmsEjb/org/nfunk/jep/function/Multiply.java
Normal file
68
hrmsEjb/org/nfunk/jep/function/Multiply.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import java.util.Vector;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Multiply extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
for (byte b = 1; b < this.curNumberOfParameters; b++) {
|
||||
Object object1 = paramStack.pop();
|
||||
object = mul(object1, object);
|
||||
}
|
||||
paramStack.push(object);
|
||||
}
|
||||
|
||||
public Object mul(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
if (paramObject1 instanceof Complex) {
|
||||
if (paramObject2 instanceof Complex)
|
||||
return mul((Complex)paramObject1, (Complex)paramObject2);
|
||||
if (paramObject2 instanceof Number)
|
||||
return mul((Complex)paramObject1, (Number)paramObject2);
|
||||
if (paramObject2 instanceof Vector)
|
||||
return mul((Vector)paramObject2, (Complex)paramObject1);
|
||||
} else if (paramObject1 instanceof Number) {
|
||||
if (paramObject2 instanceof Complex)
|
||||
return mul((Complex)paramObject2, (Number)paramObject1);
|
||||
if (paramObject2 instanceof Number)
|
||||
return mul((Number)paramObject1, (Number)paramObject2);
|
||||
if (paramObject2 instanceof Vector)
|
||||
return mul((Vector)paramObject2, (Number)paramObject1);
|
||||
} else if (paramObject1 instanceof Vector) {
|
||||
if (paramObject2 instanceof Complex)
|
||||
return mul((Vector)paramObject1, (Complex)paramObject2);
|
||||
if (paramObject2 instanceof Number)
|
||||
return mul((Vector)paramObject1, (Number)paramObject2);
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
|
||||
public Double mul(Number paramNumber1, Number paramNumber2) {
|
||||
return new Double(paramNumber1.doubleValue() * paramNumber2.doubleValue());
|
||||
}
|
||||
|
||||
public Complex mul(Complex paramComplex1, Complex paramComplex2) {
|
||||
return paramComplex1.mul(paramComplex2);
|
||||
}
|
||||
|
||||
public Complex mul(Complex paramComplex, Number paramNumber) {
|
||||
return paramComplex.mul(paramNumber.doubleValue());
|
||||
}
|
||||
|
||||
public Vector mul(Vector paramVector, Number paramNumber) {
|
||||
Vector vector = new Vector();
|
||||
for (byte b = 0; b < paramVector.size(); b++)
|
||||
vector.addElement(mul(paramVector.elementAt(b), paramNumber));
|
||||
return vector;
|
||||
}
|
||||
|
||||
public Vector mul(Vector paramVector, Complex paramComplex) {
|
||||
Vector vector = new Vector();
|
||||
for (byte b = 0; b < paramVector.size(); b++)
|
||||
vector.addElement(mul(paramComplex, paramVector.elementAt(b)));
|
||||
return vector;
|
||||
}
|
||||
}
|
26
hrmsEjb/org/nfunk/jep/function/NaturalLogarithm.java
Normal file
26
hrmsEjb/org/nfunk/jep/function/NaturalLogarithm.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class NaturalLogarithm extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(ln(object));
|
||||
}
|
||||
|
||||
public Object ln(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).log();
|
||||
if (paramObject instanceof Number) {
|
||||
double d = ((Number)paramObject).doubleValue();
|
||||
if (d > 0.0D)
|
||||
return new Double(Math.log(d));
|
||||
Complex complex = new Complex(d);
|
||||
return complex.log();
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
17
hrmsEjb/org/nfunk/jep/function/Not.java
Normal file
17
hrmsEjb/org/nfunk/jep/function/Not.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
|
||||
public class Not extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Number number = (Number)paramStack.pop();
|
||||
if (number instanceof Number) {
|
||||
boolean bool = (((Number)number).doubleValue() == 0.0D) ? true : false;
|
||||
paramStack.push(new Double(bool));
|
||||
} else {
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
||||
}
|
18
hrmsEjb/org/nfunk/jep/function/Polar.java
Normal file
18
hrmsEjb/org/nfunk/jep/function/Polar.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Polar extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Number number1 = (Number)paramStack.pop();
|
||||
Number number2 = (Number)paramStack.pop();
|
||||
if (number2 instanceof Number && number1 instanceof Number) {
|
||||
paramStack.push(Complex.polarValueOf(number2, number1));
|
||||
} else {
|
||||
throw new ParseException("Complex: Invalid parameter types " + number2.getClass().getName() + " " + number2.getClass().getName());
|
||||
}
|
||||
}
|
||||
}
|
27
hrmsEjb/org/nfunk/jep/function/PostfixMathCommand.java
Normal file
27
hrmsEjb/org/nfunk/jep/function/PostfixMathCommand.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
|
||||
public class PostfixMathCommand implements PostfixMathCommandI {
|
||||
protected int numberOfParameters = 0;
|
||||
|
||||
protected int curNumberOfParameters = 0;
|
||||
|
||||
protected void checkStack(Stack paramStack) throws ParseException {
|
||||
if (null == paramStack)
|
||||
throw new ParseException("Stack argument null");
|
||||
}
|
||||
|
||||
public int getNumberOfParameters() {
|
||||
return this.numberOfParameters;
|
||||
}
|
||||
|
||||
public void setCurNumberOfParameters(int paramInt) {
|
||||
this.curNumberOfParameters = paramInt;
|
||||
}
|
||||
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
throw new ParseException("run() method of PostfixMathCommand called");
|
||||
}
|
||||
}
|
12
hrmsEjb/org/nfunk/jep/function/PostfixMathCommandI.java
Normal file
12
hrmsEjb/org/nfunk/jep/function/PostfixMathCommandI.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
|
||||
public interface PostfixMathCommandI {
|
||||
void run(Stack paramStack) throws ParseException;
|
||||
|
||||
int getNumberOfParameters();
|
||||
|
||||
void setCurNumberOfParameters(int paramInt);
|
||||
}
|
53
hrmsEjb/org/nfunk/jep/function/Power.java
Normal file
53
hrmsEjb/org/nfunk/jep/function/Power.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Power extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object1 = paramStack.pop();
|
||||
Object object2 = paramStack.pop();
|
||||
paramStack.push(power(object2, object1));
|
||||
}
|
||||
|
||||
public Object power(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
if (paramObject1 instanceof Complex) {
|
||||
if (paramObject2 instanceof Complex)
|
||||
return power((Complex)paramObject1, (Complex)paramObject2);
|
||||
if (paramObject2 instanceof Number)
|
||||
return power((Complex)paramObject1, (Number)paramObject2);
|
||||
} else if (paramObject1 instanceof Number) {
|
||||
if (paramObject2 instanceof Complex)
|
||||
return power((Number)paramObject1, (Complex)paramObject2);
|
||||
if (paramObject2 instanceof Number)
|
||||
return power((Number)paramObject1, (Number)paramObject2);
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
|
||||
public Object power(Number paramNumber1, Number paramNumber2) {
|
||||
if (paramNumber1.doubleValue() < 0.0D && paramNumber2.doubleValue() != paramNumber2.intValue()) {
|
||||
Complex complex = new Complex(paramNumber1.doubleValue(), 0.0D);
|
||||
return complex.power(paramNumber2.doubleValue());
|
||||
}
|
||||
return new Double(Math.pow(paramNumber1.doubleValue(), paramNumber2.doubleValue()));
|
||||
}
|
||||
|
||||
public Object power(Complex paramComplex1, Complex paramComplex2) {
|
||||
Complex complex = paramComplex1.power(paramComplex2);
|
||||
return (complex.im() == 0.0D) ? new Double(complex.re()) : complex;
|
||||
}
|
||||
|
||||
public Object power(Complex paramComplex, Number paramNumber) {
|
||||
Complex complex = paramComplex.power(paramNumber.doubleValue());
|
||||
return (complex.im() == 0.0D) ? new Double(complex.re()) : complex;
|
||||
}
|
||||
|
||||
public Object power(Number paramNumber, Complex paramComplex) {
|
||||
Complex complex1 = new Complex(paramNumber.doubleValue(), 0.0D);
|
||||
Complex complex2 = complex1.power(paramComplex);
|
||||
return (complex2.im() == 0.0D) ? new Double(complex2.re()) : complex2;
|
||||
}
|
||||
}
|
11
hrmsEjb/org/nfunk/jep/function/Random.java
Normal file
11
hrmsEjb/org/nfunk/jep/function/Random.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
|
||||
public class Random extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
paramStack.push(new Double(Math.random()));
|
||||
}
|
||||
}
|
21
hrmsEjb/org/nfunk/jep/function/Real.java
Normal file
21
hrmsEjb/org/nfunk/jep/function/Real.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Real extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(re(object));
|
||||
}
|
||||
|
||||
public Number re(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return new Double(((Complex)paramObject).re());
|
||||
if (paramObject instanceof Number)
|
||||
return (Number)paramObject;
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
21
hrmsEjb/org/nfunk/jep/function/Sine.java
Normal file
21
hrmsEjb/org/nfunk/jep/function/Sine.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Sine extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(sin(object));
|
||||
}
|
||||
|
||||
public Object sin(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).sin();
|
||||
if (paramObject instanceof Number)
|
||||
return new Double(Math.sin(((Number)paramObject).doubleValue()));
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
23
hrmsEjb/org/nfunk/jep/function/SineH.java
Normal file
23
hrmsEjb/org/nfunk/jep/function/SineH.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class SineH extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(sinh(object));
|
||||
}
|
||||
|
||||
public Object sinh(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).sinh();
|
||||
if (paramObject instanceof Number) {
|
||||
double d = ((Number)paramObject).doubleValue();
|
||||
return new Double((Math.exp(d) - Math.exp(-d)) / 2.0D);
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
10
hrmsEjb/org/nfunk/jep/function/SpecialEvaluationI.java
Normal file
10
hrmsEjb/org/nfunk/jep/function/SpecialEvaluationI.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.Node;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.ParserVisitor;
|
||||
|
||||
public interface SpecialEvaluationI {
|
||||
Object evaluate(Node paramNode, Object paramObject, ParserVisitor paramParserVisitor, Stack paramStack) throws ParseException;
|
||||
}
|
23
hrmsEjb/org/nfunk/jep/function/SquareRoot.java
Normal file
23
hrmsEjb/org/nfunk/jep/function/SquareRoot.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class SquareRoot extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(sqrt(object));
|
||||
}
|
||||
|
||||
public Object sqrt(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).sqrt();
|
||||
if (paramObject instanceof Number) {
|
||||
double d = ((Number)paramObject).doubleValue();
|
||||
return (d < 0.0D) ? (new Complex(d)).sqrt() : new Double(Math.sqrt(d));
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
12
hrmsEjb/org/nfunk/jep/function/Str.java
Normal file
12
hrmsEjb/org/nfunk/jep/function/Str.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
|
||||
public class Str extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(object.toString());
|
||||
}
|
||||
}
|
45
hrmsEjb/org/nfunk/jep/function/Subtract.java
Normal file
45
hrmsEjb/org/nfunk/jep/function/Subtract.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Subtract extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object1 = paramStack.pop();
|
||||
Object object2 = paramStack.pop();
|
||||
paramStack.push(sub(object2, object1));
|
||||
}
|
||||
|
||||
public Object sub(Object paramObject1, Object paramObject2) throws ParseException {
|
||||
if (paramObject1 instanceof Complex) {
|
||||
if (paramObject2 instanceof Complex)
|
||||
return sub((Complex)paramObject1, (Complex)paramObject2);
|
||||
if (paramObject2 instanceof Number)
|
||||
return sub((Complex)paramObject1, (Number)paramObject2);
|
||||
} else if (paramObject1 instanceof Number) {
|
||||
if (paramObject2 instanceof Complex)
|
||||
return sub((Number)paramObject1, (Complex)paramObject2);
|
||||
if (paramObject2 instanceof Number)
|
||||
return sub((Number)paramObject1, (Number)paramObject2);
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
|
||||
public Double sub(Number paramNumber1, Number paramNumber2) {
|
||||
return new Double(paramNumber1.doubleValue() - paramNumber2.doubleValue());
|
||||
}
|
||||
|
||||
public Complex sub(Complex paramComplex1, Complex paramComplex2) {
|
||||
return new Complex(paramComplex1.re() - paramComplex2.re(), paramComplex1.im() - paramComplex2.im());
|
||||
}
|
||||
|
||||
public Complex sub(Complex paramComplex, Number paramNumber) {
|
||||
return new Complex(paramComplex.re() - paramNumber.doubleValue(), paramComplex.im());
|
||||
}
|
||||
|
||||
public Complex sub(Number paramNumber, Complex paramComplex) {
|
||||
return new Complex(paramNumber.doubleValue() - paramComplex.re(), -paramComplex.im());
|
||||
}
|
||||
}
|
30
hrmsEjb/org/nfunk/jep/function/Sum.java
Normal file
30
hrmsEjb/org/nfunk/jep/function/Sum.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
|
||||
public class Sum extends PostfixMathCommand {
|
||||
private Add addFun = new Add();
|
||||
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
Number number2;
|
||||
if (null == paramStack)
|
||||
throw new ParseException("Stack argument null");
|
||||
Number number1 = (Number)paramStack.pop();
|
||||
if (number1 instanceof Number) {
|
||||
number2 = number1;
|
||||
} else {
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
for (byte b = 1; b < this.curNumberOfParameters; b++) {
|
||||
number1 = (Number)paramStack.pop();
|
||||
if (number1 instanceof Number) {
|
||||
number2 = this.addFun.add(number1, number2);
|
||||
} else {
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
b++;
|
||||
}
|
||||
paramStack.push(number2);
|
||||
}
|
||||
}
|
23
hrmsEjb/org/nfunk/jep/function/TanH.java
Normal file
23
hrmsEjb/org/nfunk/jep/function/TanH.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class TanH extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(tanh(object));
|
||||
}
|
||||
|
||||
public Object tanh(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).tanh();
|
||||
if (paramObject instanceof Number) {
|
||||
double d = ((Number)paramObject).doubleValue();
|
||||
return new Double((Math.exp(d) - Math.exp(-d)) / (Math.pow(Math.E, d) + Math.pow(Math.E, -d)));
|
||||
}
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
21
hrmsEjb/org/nfunk/jep/function/Tangent.java
Normal file
21
hrmsEjb/org/nfunk/jep/function/Tangent.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class Tangent extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(tan(object));
|
||||
}
|
||||
|
||||
public Object tan(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).tan();
|
||||
if (paramObject instanceof Number)
|
||||
return new Double(Math.tan(((Number)paramObject).doubleValue()));
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
21
hrmsEjb/org/nfunk/jep/function/UMinus.java
Normal file
21
hrmsEjb/org/nfunk/jep/function/UMinus.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package org.nfunk.jep.function;
|
||||
|
||||
import java.util.Stack;
|
||||
import org.nfunk.jep.ParseException;
|
||||
import org.nfunk.jep.type.Complex;
|
||||
|
||||
public class UMinus extends PostfixMathCommand {
|
||||
public void run(Stack paramStack) throws ParseException {
|
||||
checkStack(paramStack);
|
||||
Object object = paramStack.pop();
|
||||
paramStack.push(umin(object));
|
||||
}
|
||||
|
||||
public Object umin(Object paramObject) throws ParseException {
|
||||
if (paramObject instanceof Complex)
|
||||
return ((Complex)paramObject).neg();
|
||||
if (paramObject instanceof Number)
|
||||
return new Double(-((Number)paramObject).doubleValue());
|
||||
throw new ParseException("Invalid parameter type");
|
||||
}
|
||||
}
|
403
hrmsEjb/org/nfunk/jep/type/Complex.java
Normal file
403
hrmsEjb/org/nfunk/jep/type/Complex.java
Normal file
@@ -0,0 +1,403 @@
|
||||
package org.nfunk.jep.type;
|
||||
|
||||
public class Complex {
|
||||
private double re = 0.0D;
|
||||
|
||||
private double im = 0.0D;
|
||||
|
||||
public Complex() {}
|
||||
|
||||
public Complex(double paramDouble) {}
|
||||
|
||||
public Complex(Number paramNumber) {}
|
||||
|
||||
public Complex(Complex paramComplex) {}
|
||||
|
||||
public Complex(double paramDouble1, double paramDouble2) {}
|
||||
|
||||
public double re() {
|
||||
return this.re;
|
||||
}
|
||||
|
||||
public double im() {
|
||||
return this.im;
|
||||
}
|
||||
|
||||
public void set(Complex paramComplex) {
|
||||
this.re = paramComplex.re;
|
||||
this.im = paramComplex.im;
|
||||
}
|
||||
|
||||
public void set(double paramDouble1, double paramDouble2) {
|
||||
this.re = paramDouble1;
|
||||
this.im = paramDouble2;
|
||||
}
|
||||
|
||||
public void setRe(double paramDouble) {
|
||||
this.re = paramDouble;
|
||||
}
|
||||
|
||||
public void setIm(double paramDouble) {
|
||||
this.im = paramDouble;
|
||||
}
|
||||
|
||||
public boolean equals(Complex paramComplex, double paramDouble) {
|
||||
double d1 = this.re - paramComplex.re;
|
||||
double d2 = this.im - paramComplex.im;
|
||||
return (d1 * d1 + d2 * d2 <= paramDouble * paramDouble);
|
||||
}
|
||||
|
||||
public boolean equals(Object paramObject) {
|
||||
if (!(paramObject instanceof Complex))
|
||||
return false;
|
||||
Complex complex = (Complex)paramObject;
|
||||
return (Double.doubleToLongBits(this.re) == Double.doubleToLongBits(complex.re) && Double.doubleToLongBits(this.im) == Double.doubleToLongBits(complex.im));
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
null = 17;
|
||||
long l1 = Double.doubleToLongBits(this.re);
|
||||
long l2 = Double.doubleToLongBits(this.im);
|
||||
int i = (int)(l1 ^ l1 >> 32L);
|
||||
int j = (int)(l2 ^ l2 >> 32L);
|
||||
null = 37 * null + i;
|
||||
return 37 * null + j;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "(" + this.re + ", " + this.im + ")";
|
||||
}
|
||||
|
||||
public boolean isInfinite() {
|
||||
return (Double.isInfinite(this.re) || Double.isInfinite(this.im));
|
||||
}
|
||||
|
||||
public boolean isNaN() {
|
||||
return (Double.isNaN(this.re) || Double.isNaN(this.im));
|
||||
}
|
||||
|
||||
public double abs() {
|
||||
double d1 = Math.abs(this.re);
|
||||
double d2 = Math.abs(this.im);
|
||||
if (d1 == 0.0D && d2 == 0.0D)
|
||||
return 0.0D;
|
||||
if (d1 > d2) {
|
||||
double d = d2 / d1;
|
||||
return d1 * Math.sqrt(1.0D + d * d);
|
||||
}
|
||||
double d3 = d1 / d2;
|
||||
return d2 * Math.sqrt(1.0D + d3 * d3);
|
||||
}
|
||||
|
||||
public double abs2() {
|
||||
return this.re * this.re + this.im * this.im;
|
||||
}
|
||||
|
||||
public double arg() {
|
||||
return Math.atan2(this.im, this.re);
|
||||
}
|
||||
|
||||
public Complex neg() {
|
||||
return new Complex(-this.re, -this.im);
|
||||
}
|
||||
|
||||
public Complex mul(double paramDouble) {
|
||||
return new Complex(this.re * paramDouble, this.im * paramDouble);
|
||||
}
|
||||
|
||||
public Complex add(Complex paramComplex) {
|
||||
return new Complex(this.re + paramComplex.re, this.im + paramComplex.im);
|
||||
}
|
||||
|
||||
public Complex sub(Complex paramComplex) {
|
||||
return new Complex(this.re - paramComplex.re, this.im - paramComplex.im);
|
||||
}
|
||||
|
||||
public Complex mul(Complex paramComplex) {
|
||||
return new Complex(this.re * paramComplex.re - this.im * paramComplex.im, this.im * paramComplex.re + this.re * paramComplex.im);
|
||||
}
|
||||
|
||||
public Complex div(Complex paramComplex) {
|
||||
double d1;
|
||||
double d2;
|
||||
if (Math.abs(paramComplex.re) >= Math.abs(paramComplex.im)) {
|
||||
double d3 = paramComplex.im / paramComplex.re;
|
||||
double d4 = paramComplex.re + d3 * paramComplex.im;
|
||||
d1 = (this.re + d3 * this.im) / d4;
|
||||
d2 = (this.im - d3 * this.re) / d4;
|
||||
} else {
|
||||
double d3 = paramComplex.re / paramComplex.im;
|
||||
double d4 = paramComplex.im + d3 * paramComplex.re;
|
||||
d1 = (this.re * d3 + this.im) / d4;
|
||||
d2 = (this.im * d3 - this.re) / d4;
|
||||
}
|
||||
return new Complex(d1, d2);
|
||||
}
|
||||
|
||||
public Complex power(double paramDouble) {
|
||||
double d1 = Math.pow(abs(), paramDouble);
|
||||
boolean bool = false;
|
||||
byte b = 0;
|
||||
if (this.im == 0.0D && this.re < 0.0D) {
|
||||
bool = true;
|
||||
b = 2;
|
||||
}
|
||||
if (this.re == 0.0D && this.im > 0.0D) {
|
||||
bool = true;
|
||||
b = 1;
|
||||
}
|
||||
if (this.re == 0.0D && this.im < 0.0D) {
|
||||
bool = true;
|
||||
b = -1;
|
||||
}
|
||||
if (bool && b * paramDouble == (int)(b * paramDouble)) {
|
||||
short[] arrayOfShort1 = { 0, 1, 0, -1 };
|
||||
short[] arrayOfShort2 = { 1, 0, -1, 0 };
|
||||
int i = (int)(b * paramDouble) % 4;
|
||||
if (i < 0)
|
||||
i = 4 + i;
|
||||
return new Complex(d1 * arrayOfShort2[i], d1 * arrayOfShort1[i]);
|
||||
}
|
||||
double d2 = paramDouble * arg();
|
||||
return new Complex(d1 * Math.cos(d2), d1 * Math.sin(d2));
|
||||
}
|
||||
|
||||
public Complex power(Complex paramComplex) {
|
||||
if (paramComplex.im == 0.0D)
|
||||
return power(paramComplex.re);
|
||||
double d1 = Math.log(abs());
|
||||
double d2 = arg();
|
||||
double d3 = d1 * paramComplex.re - d2 * paramComplex.im;
|
||||
double d4 = d1 * paramComplex.im + d2 * paramComplex.re;
|
||||
double d5 = Math.exp(d3);
|
||||
return new Complex(d5 * Math.cos(d4), d5 * Math.sin(d4));
|
||||
}
|
||||
|
||||
public Complex log() {
|
||||
return new Complex(Math.log(abs()), arg());
|
||||
}
|
||||
|
||||
public Complex sqrt() {
|
||||
Complex complex;
|
||||
if (this.re == 0.0D && this.im == 0.0D) {
|
||||
complex = new Complex(0.0D, 0.0D);
|
||||
} else {
|
||||
double d3;
|
||||
double d1 = Math.abs(this.re);
|
||||
double d2 = Math.abs(this.im);
|
||||
if (d1 >= d2) {
|
||||
double d = d2 / d1;
|
||||
d3 = Math.sqrt(d1) * Math.sqrt(0.5D * (1.0D + Math.sqrt(1.0D + d * d)));
|
||||
} else {
|
||||
double d = d1 / d2;
|
||||
d3 = Math.sqrt(d2) * Math.sqrt(0.5D * (d + Math.sqrt(1.0D + d * d)));
|
||||
}
|
||||
if (this.re >= 0.0D) {
|
||||
complex = new Complex(d3, this.im / 2.0D * d3);
|
||||
} else {
|
||||
if (this.im < 0.0D)
|
||||
d3 = -d3;
|
||||
complex = new Complex(this.im / 2.0D * d3, d3);
|
||||
}
|
||||
}
|
||||
return complex;
|
||||
}
|
||||
|
||||
public Complex sin() {
|
||||
double d1 = -this.im;
|
||||
double d2 = this.re;
|
||||
double d7 = Math.exp(d1);
|
||||
double d3 = d7 * Math.cos(d2);
|
||||
double d4 = d7 * Math.sin(d2);
|
||||
d7 = Math.exp(-d1);
|
||||
double d5 = d7 * Math.cos(-d2);
|
||||
double d6 = d7 * Math.sin(-d2);
|
||||
d3 -= d5;
|
||||
d4 -= d6;
|
||||
return new Complex(0.5D * d4, -0.5D * d3);
|
||||
}
|
||||
|
||||
public Complex cos() {
|
||||
double d1 = -this.im;
|
||||
double d2 = this.re;
|
||||
double d7 = Math.exp(d1);
|
||||
double d3 = d7 * Math.cos(d2);
|
||||
double d4 = d7 * Math.sin(d2);
|
||||
d7 = Math.exp(-d1);
|
||||
double d5 = d7 * Math.cos(-d2);
|
||||
double d6 = d7 * Math.sin(-d2);
|
||||
d3 += d5;
|
||||
d4 += d6;
|
||||
return new Complex(0.5D * d3, 0.5D * d4);
|
||||
}
|
||||
|
||||
public Complex tan() {
|
||||
double d1 = -this.im;
|
||||
double d2 = this.re;
|
||||
double d7 = Math.exp(d1);
|
||||
double d3 = d7 * Math.cos(d2);
|
||||
double d4 = d7 * Math.sin(d2);
|
||||
d7 = Math.exp(-d1);
|
||||
double d5 = d7 * Math.cos(-d2);
|
||||
double d6 = d7 * Math.sin(-d2);
|
||||
d3 -= d5;
|
||||
d4 -= d6;
|
||||
Complex complex1 = new Complex(0.5D * d3, 0.5D * d4);
|
||||
d1 = -this.im;
|
||||
d2 = this.re;
|
||||
d7 = Math.exp(d1);
|
||||
d3 = d7 * Math.cos(d2);
|
||||
d4 = d7 * Math.sin(d2);
|
||||
d7 = Math.exp(-d1);
|
||||
d5 = d7 * Math.cos(-d2);
|
||||
d6 = d7 * Math.sin(-d2);
|
||||
d3 += d5;
|
||||
d4 += d6;
|
||||
Complex complex2 = new Complex(0.5D * d3, 0.5D * d4);
|
||||
return complex1.div(complex2);
|
||||
}
|
||||
|
||||
public Complex asin() {
|
||||
double d1 = 1.0D - this.re * this.re - this.im * this.im;
|
||||
double d2 = 0.0D - this.re * this.im + this.im * this.re;
|
||||
Complex complex = new Complex(d1, d2);
|
||||
complex = complex.sqrt();
|
||||
complex.re += -this.im;
|
||||
complex.im += this.re;
|
||||
d1 = Math.log(complex.abs());
|
||||
d2 = complex.arg();
|
||||
complex.re = d2;
|
||||
complex.im = -d1;
|
||||
return complex;
|
||||
}
|
||||
|
||||
public Complex acos() {
|
||||
double d1 = 1.0D - this.re * this.re - this.im * this.im;
|
||||
double d2 = 0.0D - this.re * this.im + this.im * this.re;
|
||||
Complex complex = new Complex(d1, d2);
|
||||
complex = complex.sqrt();
|
||||
d1 = -complex.im;
|
||||
d2 = complex.re;
|
||||
this.re += d1;
|
||||
this.im += d2;
|
||||
d1 = Math.log(complex.abs());
|
||||
d2 = complex.arg();
|
||||
complex.re = d2;
|
||||
complex.im = -d1;
|
||||
return complex;
|
||||
}
|
||||
|
||||
public Complex atan() {
|
||||
Complex complex = new Complex(-this.re, 1.0D - this.im);
|
||||
double d1 = this.re;
|
||||
double d2 = 1.0D + this.im;
|
||||
complex = complex.div(new Complex(d1, d2));
|
||||
d1 = Math.log(complex.abs());
|
||||
d2 = complex.arg();
|
||||
complex.re = 0.5D * d2;
|
||||
complex.im = -0.5D * d1;
|
||||
return complex;
|
||||
}
|
||||
|
||||
public Complex sinh() {
|
||||
double d1 = Math.exp(this.re);
|
||||
double d2 = d1 * Math.cos(this.im);
|
||||
double d3 = d1 * Math.sin(this.im);
|
||||
d1 = Math.exp(-this.re);
|
||||
double d4 = d1 * Math.cos(-this.im);
|
||||
double d5 = d1 * Math.sin(-this.im);
|
||||
d2 -= d4;
|
||||
d3 -= d5;
|
||||
return new Complex(0.5D * d2, 0.5D * d3);
|
||||
}
|
||||
|
||||
public Complex cosh() {
|
||||
double d1 = Math.exp(this.re);
|
||||
double d2 = d1 * Math.cos(this.im);
|
||||
double d3 = d1 * Math.sin(this.im);
|
||||
d1 = Math.exp(-this.re);
|
||||
double d4 = d1 * Math.cos(-this.im);
|
||||
double d5 = d1 * Math.sin(-this.im);
|
||||
d2 += d4;
|
||||
d3 += d5;
|
||||
return new Complex(0.5D * d2, 0.5D * d3);
|
||||
}
|
||||
|
||||
public Complex tanh() {
|
||||
double d1 = Math.exp(this.re);
|
||||
double d2 = d1 * Math.cos(this.im);
|
||||
double d3 = d1 * Math.sin(this.im);
|
||||
d1 = Math.exp(-this.re);
|
||||
double d4 = d1 * Math.cos(-this.im);
|
||||
double d5 = d1 * Math.sin(-this.im);
|
||||
d2 -= d4;
|
||||
d3 -= d5;
|
||||
Complex complex1 = new Complex(0.5D * d2, 0.5D * d3);
|
||||
d1 = Math.exp(this.re);
|
||||
d2 = d1 * Math.cos(this.im);
|
||||
d3 = d1 * Math.sin(this.im);
|
||||
d1 = Math.exp(-this.re);
|
||||
d4 = d1 * Math.cos(-this.im);
|
||||
d5 = d1 * Math.sin(-this.im);
|
||||
d2 += d4;
|
||||
d3 += d5;
|
||||
Complex complex2 = new Complex(0.5D * d2, 0.5D * d3);
|
||||
return complex1.div(complex2);
|
||||
}
|
||||
|
||||
public Complex asinh() {
|
||||
Complex complex = new Complex(this.re * this.re - this.im * this.im + 1.0D, this.re * this.im + this.im * this.re);
|
||||
complex = complex.sqrt();
|
||||
complex.re += this.re;
|
||||
complex.im += this.im;
|
||||
double d = complex.arg();
|
||||
complex.re = Math.log(complex.abs());
|
||||
complex.im = d;
|
||||
return complex;
|
||||
}
|
||||
|
||||
public Complex acosh() {
|
||||
Complex complex = new Complex(this.re * this.re - this.im * this.im - 1.0D, this.re * this.im + this.im * this.re);
|
||||
complex = complex.sqrt();
|
||||
complex.re += this.re;
|
||||
complex.im += this.im;
|
||||
double d = complex.arg();
|
||||
complex.re = Math.log(complex.abs());
|
||||
complex.im = d;
|
||||
return complex;
|
||||
}
|
||||
|
||||
public Complex atanh() {
|
||||
Complex complex = new Complex(1.0D + this.re, this.im);
|
||||
double d1 = 1.0D - this.re;
|
||||
double d2 = -this.im;
|
||||
complex = complex.div(new Complex(d1, d2));
|
||||
d1 = Math.log(complex.abs());
|
||||
d2 = complex.arg();
|
||||
complex.re = 0.5D * d1;
|
||||
complex.im = 0.5D * d2;
|
||||
return complex;
|
||||
}
|
||||
|
||||
public static Complex polarValueOf(Number paramNumber1, Number paramNumber2) {
|
||||
double d1 = paramNumber1.doubleValue();
|
||||
double d2 = paramNumber2.doubleValue();
|
||||
return new Complex(d1 * Math.cos(d2), d1 * Math.sin(d2));
|
||||
}
|
||||
|
||||
public double doubleValue() {
|
||||
return this.re;
|
||||
}
|
||||
|
||||
public float floatValue() {
|
||||
return (float)this.re;
|
||||
}
|
||||
|
||||
public int intValue() {
|
||||
return (int)this.re;
|
||||
}
|
||||
|
||||
public long longValue() {
|
||||
return (long)this.re;
|
||||
}
|
||||
}
|
7
hrmsEjb/org/nfunk/jep/type/DoubleNumberFactory.java
Normal file
7
hrmsEjb/org/nfunk/jep/type/DoubleNumberFactory.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package org.nfunk.jep.type;
|
||||
|
||||
public class DoubleNumberFactory implements NumberFactory {
|
||||
public Object createNumber(String paramString) {
|
||||
return new Double(paramString);
|
||||
}
|
||||
}
|
5
hrmsEjb/org/nfunk/jep/type/NumberFactory.java
Normal file
5
hrmsEjb/org/nfunk/jep/type/NumberFactory.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package org.nfunk.jep.type;
|
||||
|
||||
public interface NumberFactory {
|
||||
Object createNumber(String paramString);
|
||||
}
|
Reference in New Issue
Block a user