Package org.nfunk.jep
Class JEP
- java.lang.Object
-
- org.nfunk.jep.JEP
-
@Deprecated public class JEP extends java.lang.Object
Deprecated.As of 3.0 release, replaced by com.singularsys.jep.JepThis class serves as a compatibility class to assist in the transition from Jep 2.x to Jep 3.0. The class is deprecated and should only be used if using com.singularsys.jep.JEP is not feasible.Only the core functionality of the 2.x Jep class is maintained in this class. Some functionality has been omitted.
Visit http://www.singularsys.com/jep for the newest version of Jep, and complete documentation.
- Author:
- Nathan Funk
-
-
Constructor Summary
Constructors Constructor Description JEP()
Deprecated.Creates a new JEP instance with the default settings.JEP(boolean traverse_in, boolean allowUndeclared_in, boolean implicitMul_in, NumberFactory numberFactory_in)
Deprecated.Creates a new JEP instance with custom settings.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addComplex()
Deprecated.Call this function if you want to parse expressions which involve complex numbers.void
addFunction(java.lang.String functionName, PostfixMathCommandI function)
Deprecated.Adds a new function to the parser.void
addStandardConstants()
Deprecated.Adds the constants pi and e to the parser.void
addStandardFunctions()
Deprecated.Adds the standard functions to the parser.Complex
addVariable(java.lang.String name, double re, double im)
Deprecated.Adds a new complex variable to the parser, or updates the value of an existing variable.void
addVariable(java.lang.String name, java.lang.Object object)
Deprecated.Adds a new variable to the parser as an object, or updates the value of an existing variable.boolean
getAllowUndeclared()
Deprecated.Returns the value of the allowUndeclared option.Complex
getComplexValue()
Deprecated.Evaluates and returns the value of the expression as a complex number.java.lang.String
getErrorInfo()
Deprecated.Reports information on the errors that occurred during the most recent action.FunctionTable
getFunctionTable()
Deprecated.Returns the function table (the list of all functions that the parser recognizes).boolean
getImplicitMul()
Deprecated.Returns the value of the implicit multiplication option.NumberFactory
getNumberFactory()
Deprecated.Returns the number factory.OperatorTableI
getOperatorSet()
Deprecated.Returns the operator set.Parser
getParser()
Deprecated.Returns the parse object.VariableTable
getSymbolTable()
Deprecated.Returns the symbol table (the list of all variables that the parser recognizes).boolean
getTraverse()
Deprecated.Returns the value of the traverse option.double
getValue()
Deprecated.Evaluates and returns the value of the expression as a double number.java.lang.Object
getValueAsObject()
Deprecated.Evaluates and returns the value of the expression as an object.java.lang.Object
getVarValue(java.lang.String name)
Deprecated.Returns the value of the variable with given name.boolean
hasError()
Deprecated.Returns true if an error occurred during the most recent action (parsing or evaluation).void
initFunTab()
Deprecated.Creates a new FunctionTable object as funTab.void
initSymTab()
Deprecated.Creates a new SymbolTable object as symTab.Node
parseExpression(java.lang.String expression_in)
Deprecated.Parses the expression.void
setAllowUndeclared(boolean value)
Deprecated.Sets the value for the undeclared variables option.void
setImplicitMul(boolean value)
Deprecated.Sets the value of the implicit multiplication option.void
setTraverse(boolean value)
Deprecated.Sets the value of the traverse option. setTraverse is useful for debugging purposes.
-
-
-
Constructor Detail
-
JEP
public JEP()
Deprecated.Creates a new JEP instance with the default settings.Traverse = false
Allow undeclared variables = false
Implicit multiplication = false
Number Factory = DoubleNumberFactory
-
JEP
public JEP(boolean traverse_in, boolean allowUndeclared_in, boolean implicitMul_in, NumberFactory numberFactory_in)
Deprecated.Creates a new JEP instance with custom settings. If the numberFactory_in is null, the default number factory is used.- Parameters:
traverse_in
- The traverse option.allowUndeclared_in
- The "allow undeclared variables" option.implicitMul_in
- The implicit multiplication option.numberFactory_in
- The number factory to be used.
-
-
Method Detail
-
initSymTab
public void initSymTab()
Deprecated.Creates a new SymbolTable object as symTab.
-
initFunTab
public void initFunTab()
Deprecated.Creates a new FunctionTable object as funTab.
-
addStandardFunctions
public void addStandardFunctions()
Deprecated.Adds the standard functions to the parser. If this function is not called before parsing an expression, functions such as sin() or cos() would produce an "Unrecognized function..." error. In most cases, this method should be called immediately after the JEP object is created.- Since:
- 2.3.0 alpha added if and exp functions, 2.3.0 beta 1 added str function
-
addStandardConstants
public void addStandardConstants()
Deprecated.Adds the constants pi and e to the parser. As addStandardFunctions(), this method should be called immediately after the JEP object is created.
-
addComplex
public void addComplex()
Deprecated.Call this function if you want to parse expressions which involve complex numbers. This method specifies "i" as the imaginary unit (0,1). Two functions re() and im() are also added for extracting the real or imaginary components of a complex number respectively.- Since:
- 2.3.0 alpha The functions cmod and arg are added to get the modulus and argument., 2.3.0 beta 1 The functions complex and polar to convert x,y and r,theta to Complex., Feb 05 added complex conjugate conj.
-
addFunction
public void addFunction(java.lang.String functionName, PostfixMathCommandI function)
Deprecated.Adds a new function to the parser. This must be done before parsing an expression so the parser is aware that the new function may be contained in the expression.- Parameters:
functionName
- The name of the functionfunction
- The function object that is used for evaluating the function
-
addVariable
public Complex addVariable(java.lang.String name, double re, double im) throws JepException
Deprecated.Adds a new complex variable to the parser, or updates the value of an existing variable. This must be done before parsing an expression so the parser is aware that the new variable may be contained in the expression.- Parameters:
name
- Name of the variable to be addedre
- Initial real value or new real value for the variableim
- Initial imaginary value or new imaginary value for the variable- Returns:
- Complex object of the variable
- Throws:
JepException
- If a constant with the given name already exists.
-
addVariable
public void addVariable(java.lang.String name, java.lang.Object object) throws JepException
Deprecated.Adds a new variable to the parser as an object, or updates the value of an existing variable. This must be done before parsing an expression so the parser is aware that the new variable may be contained in the expression.- Parameters:
name
- Name of the variable to be addedobject
- Initial value or new value for the variable- Throws:
JepException
- If a constant with the given name already exists.
-
getVarValue
public java.lang.Object getVarValue(java.lang.String name)
Deprecated.Returns the value of the variable with given name.- Parameters:
name
- name of the variable.- Returns:
- the current value of the variable.
- Since:
- 2.3.0 alpha
-
setTraverse
public void setTraverse(boolean value)
Deprecated.Sets the value of the traverse option. setTraverse is useful for debugging purposes. When traverse is set to true, the parse-tree will be dumped to the standard output device.The default value is false.
- Parameters:
value
- The boolean traversal option.
-
getTraverse
public boolean getTraverse()
Deprecated.Returns the value of the traverse option.- Returns:
- True if the traverse option is enabled. False otherwise.
-
setImplicitMul
public void setImplicitMul(boolean value)
Deprecated.Sets the value of the implicit multiplication option. If this option is set to true before parsing, implicit multiplication will be allowed. That means that an expression such as"1 2"
is valid and is interpreted as"1*2"
.The default value is false.
- Parameters:
value
- The boolean implicit multiplication option.
-
getImplicitMul
public boolean getImplicitMul()
Deprecated.Returns the value of the implicit multiplication option.- Returns:
- True if the implicit multiplication option is enabled. False otherwise.
-
setAllowUndeclared
public void setAllowUndeclared(boolean value)
Deprecated.Sets the value for the undeclared variables option. If this option is set to true, expressions containing variables that were not previously added to JEP will not produce an "Unrecognized Symbol" error. The new variables will automatically be added while parsing, and initialized to 0.If this option is set to false, variables that were not previously added to JEP will produce an error while parsing.
The default value is false.
- Parameters:
value
- The boolean option for allowing undeclared variables.
-
getAllowUndeclared
public boolean getAllowUndeclared()
Deprecated.Returns the value of the allowUndeclared option.- Returns:
- True if the allowUndeclared option is enabled. False otherwise.
-
parseExpression
public Node parseExpression(java.lang.String expression_in)
Deprecated.Parses the expression. If there are errors in the expression, they are added to theerrorList
member.- Parameters:
expression_in
- The input expression string- Returns:
- the root node of the expression tree.
-
getValue
public double getValue()
Deprecated.Evaluates and returns the value of the expression as a double number.- Returns:
- The calculated value of the expression as a double number. If the type of the value does not implement the Number interface (e.g. Complex), NaN is returned. If an error occurs during evaluation, NaN is returned and hasError() will return true. Also, if an error previously occured while parsing, or if no expression has been parsed, NaN is returned.
- See Also:
getComplexValue()
-
getComplexValue
public Complex getComplexValue()
Deprecated.Evaluates and returns the value of the expression as a complex number.- Returns:
- The calculated value of the expression as a complex number if no errors occur. Returns null otherwise.
-
getValueAsObject
public java.lang.Object getValueAsObject()
Deprecated.Evaluates and returns the value of the expression as an object. The EvaluatorVisitor member ev is used to do the evaluation procedure. This method is useful when the type of the value is unknown, or not important.- Returns:
- The calculated value of the expression if no errors occur. Returns null otherwise.
-
hasError
public boolean hasError()
Deprecated.Returns true if an error occurred during the most recent action (parsing or evaluation). This is done by checking whether there are any items in the error list stored in the Jep instance.- Returns:
- Returns
true
if an error occurred during the most recent action (parsing or evaluation).
-
getErrorInfo
public java.lang.String getErrorInfo()
Deprecated.Reports information on the errors that occurred during the most recent action.- Returns:
- A string containing information on the errors, each separated by a newline character; null if no error has occurred
-
getSymbolTable
public VariableTable getSymbolTable()
Deprecated.Returns the symbol table (the list of all variables that the parser recognizes).- Returns:
- The symbol table
-
getFunctionTable
public FunctionTable getFunctionTable()
Deprecated.Returns the function table (the list of all functions that the parser recognizes).- Returns:
- The function table
-
getNumberFactory
public NumberFactory getNumberFactory()
Deprecated.Returns the number factory.- Returns:
- the NumberFactory used by this JEP instance.
-
getOperatorSet
public OperatorTableI getOperatorSet()
Deprecated.Returns the operator set.- Returns:
- the OperatorSet used by this JEP instance.
- Since:
- 2.3.0 alpha
-
getParser
public Parser getParser()
Deprecated.Returns the parse object.- Returns:
- the Parse used by this JEP.
- Since:
- 2.3.0 beta 1
-
-