public class JEP extends Object implements ExpressionParser
Title: 常用代码打包
Description: 表达式解析器
The JEP class is the main interface with which the user should interact. It contains all necessary methods to parse and evaluate expressions.
The most important methods are parseExpression(String), for parsing the mathematical or other expression, and getValue() or getValueAsObject for obtaining the value of the expression.
Copyright: Copyright spk (c) 2003
Company: spk
| 限定符和类型 | 字段和说明 |
|---|---|
protected boolean |
allowUndeclared
Allow undeclared variables option
|
protected Vector |
errorList
Error List
|
protected FunctionTable |
funTab
Function Table
|
protected boolean |
implicitMul
Implicit multiplication option
|
protected static Log |
log |
protected SymbolTable |
symTab
Symbol Table
|
| 构造器和说明 |
|---|
JEP()
Creates a new JEP instance with the default settings.
|
JEP(boolean traverse_in,
boolean allowUndeclared_in,
boolean implicitMul_in,
NumberFactory numberFactory_in)
Creates a new JEP instance with custom settings.
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
addFunction(String functionName,
Function function)
加入函数
|
void |
addFunction(String functionName,
FunctionI function)
Adds a new function to the parser.
|
void |
addFuntionTable(FunctionTable functionTable)
加入函数表
|
void |
addStandardConstants()
Adds the constants pi and e to the parser.
|
void |
addStandardFunctions()
Adds the standard functions to the parser.
|
Double |
addVariable(String name,
double value)
Adds a new variable to the parser, or updates the value of an existing
variable.
|
void |
addVariableAsObject(String name,
Object object)
Adds a new variable to the parser as an object, or updates the value of
an existing variable.
|
void |
addVariableNames(String[] names)
加入变量名,用于解析表达式用。
|
String |
getErrorInfo()
Reports information on the errors that occured during the most recent
action.
|
String |
getExpression()
取得Parser中当前的表达式
|
Hashtable |
getFunctionTable()
Returns the function table (the list of all functions that the parser
recognizes).
|
NumberFactory |
getNumberFactory()
Returns the number factory.
|
HashMap |
getSymbolTable()
Returns the symbol table (the list of all variables that the parser
recognises).
|
Node |
getTopNode()
Returns the top node of the expression tree.
|
double |
getValue()
Evaluates and returns the value of the expression.
|
Object |
getValueAsObject()
Evaluates and returns the value of the expression as an object.
|
boolean |
hasError()
Returns true if an error occured during the most recent action (parsing
or evaluation).
|
void |
initFunTab()
Creates a new FunctionTable object as funTab.
|
void |
initSymTab()
Creates a new SymbolTable object as symTab.
|
boolean |
parseExpression(String expression_in)
Parses the expression.
|
Object |
removeFunction(String name)
Removes a function from the parser.
|
Object |
removeVariable(String name)
Removes a variable from the parser.
|
void |
setAllowUndeclared(boolean value)
Sets the value for the undeclared variables option.
|
void |
setImplicitMul(boolean value)
Sets the value of the implicit multiplication option.
|
void |
setTraverse(boolean value)
Sets the value of the traverse option. setTraverse is useful for
debugging purposes.
|
protected static Log log
protected boolean allowUndeclared
protected boolean implicitMul
protected SymbolTable symTab
protected FunctionTable funTab
protected Vector errorList
public JEP()
Traverse = false
Allow undeclared variables = false
Implicit multiplication = false
Number Factory = DoubleNumberFactory
public JEP(boolean traverse_in,
boolean allowUndeclared_in,
boolean implicitMul_in,
NumberFactory numberFactory_in)
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.public String getExpression()
ExpressionParsergetExpression 在接口中 ExpressionParserpublic void initSymTab()
public void initFunTab()
public void addStandardFunctions()
addStandardFunctions 在接口中 ExpressionParserpublic void addStandardConstants()
addStandardConstants 在接口中 ExpressionParserpublic void addFunction(String functionName, FunctionI function)
functionName - The name of the functionfunction - The function object that is used for evaluating the functionpublic void addFunction(String functionName, Function function)
ExpressionParseraddFunction 在接口中 ExpressionParserfunctionName - 函数的名称function - 要加入的函数public void addFuntionTable(FunctionTable functionTable)
addFuntionTable 在接口中 ExpressionParserpublic Double addVariable(String name, double value)
name - Name of the variable to be addedvalue - Initial value or new value for the variablepublic void addVariableAsObject(String name, Object object)
addVariableAsObject 在接口中 ExpressionParsername - Name of the variable to be addedobject - Initial value or new value for the variablepublic Object removeVariable(String name)
removeVariable 在接口中 ExpressionParsername - 变量的名称null is
returned.public Object removeFunction(String name)
removeFunction 在接口中 ExpressionParsername - 函数的名称null is
returned.public void setTraverse(boolean value)
The default value is false.
value - The boolean traversal option.public void setImplicitMul(boolean value)
"1 2"is valid and is interpreted as
"1*2".
The default value is false.
value - The boolean implicit multiplication option.public void setAllowUndeclared(boolean value)
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.
setAllowUndeclared 在接口中 ExpressionParservalue - The boolean option for allowing undeclared variables.public boolean parseExpression(String expression_in)
errorList member.parseExpression 在接口中 ExpressionParserexpression_in - The input expression stringpublic double getValue()
throws Exception
Exceptionpublic Object getValueAsObject()
getValueAsObject 在接口中 ExpressionParserpublic boolean hasError()
hasError 在接口中 ExpressionParsertrue if an error occured during the most
recent action (parsing or evaluation).public String getErrorInfo()
getErrorInfo 在接口中 ExpressionParserpublic Node getTopNode()
public HashMap getSymbolTable()
getSymbolTable 在接口中 ExpressionParserpublic Hashtable getFunctionTable()
getFunctionTable 在接口中 ExpressionParserpublic NumberFactory getNumberFactory()
public void addVariableNames(String[] names)
ExpressionParseraddVariableNames 在接口中 ExpressionParserCopyright © 2023 onecode. All rights reserved.