Package chemaxon.jep

Class ChemJEP<C extends ChemContext>

java.lang.Object
chemaxon.jep.ChemJEP<C>
All Implemented Interfaces:
chemaxon.marvin.util.CallbackIface, Serializable

@PublicApi public class ChemJEP<C extends ChemContext> extends Object implements chemaxon.marvin.util.CallbackIface, Serializable
Expression parser and evaluator for chemical expressions.
Since:
JChem 2.2, Marvin 5.1
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The compilation error message.
    protected Vector<Throwable>
    Deprecated, for removal: This API element is subject to removal in a future version.
    This class no longer collects exceptions but throws them when they are encountered.
    static final String
    The evaluation error message.
    static final int
    Logical result value: FALSE.
    static final int
    Logical result value: TRUE.
    static final int
    Logical result value: UNDECIDED.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Deprecated, for removal: This API element is subject to removal in a future version.
    Direct creation of a ChemJEP object will no longer be supported, use the Evaluator.compile(java.lang.String) methods instead.
    ChemJEP(Class<? extends C> contextClass)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Direct creation of a ChemJEP object will no longer be supported, use the Evaluator.compile(java.lang.String) methods instead.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    Complex number support will be removed without replacement.
    chemaxon.nfunk.jep.type.Complex
    addComplexVariable(String name, double re, double im)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Complex number support will be removed without replacement.
    protected void
    Deprecated, for removal: This API element is subject to removal in a future version.
    This class no longer collects exceptions but throws them when they are encountered.
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    The function table will not be modifiable anymore.
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    The symbol table has been replaced with the constant table, and it will become unmodifiable.
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    These functions will be removed without replacement.
    addVariable(String name, double value)
    Deprecated, for removal: This API element is subject to removal in a future version.
    The symbol table has been replaced with the constant table, and it will become unmodifiable.
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    The symbol table has been replaced with the constant table, and it will become unmodifiable.
    callback(String method, Object arg)
    Deprecated, for removal: This API element is subject to removal in a future version.
    No longer used for accessing the context, will be removed without replacement.
    void
    compile(String expression)
    Compiles the expression string to an inner structure.
    Returns the constant table used by this parser.
    evaluate(C context)
    Evaluates the expression.
    boolean
    Evaluates the expression and converts the result boolean.
    boolean[]
    Evaluates the expression and converts the result to boolean[].
    double
    evaluate_double(C context)
    Evaluates the expression and converts the result to double.
    double[]
    Evaluates the expression and converts the result to double[].
    chemaxon.nfunk.jep.type.Complex
    Deprecated, for removal: This API element is subject to removal in a future version.
    Complex number support will be removed without replacement.
    getError(int i)
    Deprecated, for removal: This API element is subject to removal in a future version.
    This class no longer collects exceptions but throws them when they are encountered.
    int
    Deprecated, for removal: This API element is subject to removal in a future version.
    This class no longer collects exceptions but throws them when they are encountered.
    Deprecated, for removal: This API element is subject to removal in a future version.
    This class no longer collects exceptions but throws them when they are encountered.
    Deprecated, for removal: This API element is subject to removal in a future version.
    This class no longer collects exceptions but throws them when they are encountered.
    Deprecated, for removal: This API element is subject to removal in a future version.
    The function table will become an internal API.
    static int
    Returns the logical correspondent of the specified result object: TRUE, FALSE or UNDECIDED.
    chemaxon.nfunk.jep.type.NumberFactory
    Deprecated, for removal: This API element is subject to removal in a future version.
    This feature will be removed without replacement.
    chemaxon.nfunk.jep.SymbolTable
    Deprecated, for removal: This API element is subject to removal in a future version.
    Use constantTable() instead.
    chemaxon.nfunk.jep.Node
    Deprecated, for removal: This API element is subject to removal in a future version.
    This method returns an internal representation which will be hidden in the future.
    double
    Deprecated, for removal: This API element is subject to removal in a future version.
    Deprecated, for removal: This API element is subject to removal in a future version.
    boolean
    Deprecated, for removal: This API element is subject to removal in a future version.
    This class no longer collects exceptions but throws them when they are encountered.
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    The function table will become unmodifiable.
    void
    Deprecated, for removal: This API element is subject to removal in a future version.
    The symbol table has been replaced with the constant table, and it will become unmodifiable.
    static boolean
    Returns whether the result object is undecided.
    void
    parseExpression(String expression_in)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Use compile(String) instead.
    Deprecated, for removal: This API element is subject to removal in a future version.
    The function table will become unmodifiable.
    Deprecated, for removal: This API element is subject to removal in a future version.
    The symbol table has been replaced with the constant table, and it will become unmodifiable.
    void
    setAllowUndeclared(boolean value)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Undeclared variables will always be allowed in the future, changing this will no longer be supported.
    void
    setImplicitMul(boolean value)
    Deprecated, for removal: This API element is subject to removal in a future version.
    This option will be removed without replacement.
    protected void
    setSymbolTable(chemaxon.nfunk.jep.SymbolTable symTab)
    Deprecated, for removal: This API element is subject to removal in a future version.
    void
    setTraverse(boolean value)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Use Evaluator.setVerbose(boolean) instead before creating the ChemJEP.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • FALSE

      public static final int FALSE
      Logical result value: FALSE.
      See Also:
    • TRUE

      public static final int TRUE
      Logical result value: TRUE.
      See Also:
    • UNDECIDED

      public static final int UNDECIDED
      Logical result value: UNDECIDED.
      See Also:
    • COMPILE_ERROR

      public static final String COMPILE_ERROR
      The compilation error message.
      See Also:
    • EVALUATION_ERROR

      public static final String EVALUATION_ERROR
      The evaluation error message.
      See Also:
    • errorList

      Deprecated, for removal: This API element is subject to removal in a future version.
      This class no longer collects exceptions but throws them when they are encountered. The list this method uses is filled but otherwise ignored.
      The error list of this parser.
  • Constructor Details

    • ChemJEP

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public ChemJEP() throws chemaxon.nfunk.jep.ParseException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Direct creation of a ChemJEP object will no longer be supported, use the Evaluator.compile(java.lang.String) methods instead.
      Constructor. Initiates the this JEP with no context.
      Throws:
      chemaxon.nfunk.jep.ParseException - on error
    • ChemJEP

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public ChemJEP(Class<? extends C> contextClass) throws chemaxon.nfunk.jep.ParseException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Direct creation of a ChemJEP object will no longer be supported, use the Evaluator.compile(java.lang.String) methods instead.
      Constructor. Sets the context class, adds context functions.
      Parameters:
      contextClass - is the context class
      Throws:
      chemaxon.nfunk.jep.ParseException - on error
  • Method Details

    • constantTable

      public ConstantTable constantTable()
      Returns the constant table used by this parser.
    • addFunction

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public void addFunction(String name, PostfixMathCommandI function) throws chemaxon.nfunk.jep.ParseException
      Deprecated, for removal: This API element is subject to removal in a future version.
      The function table will not be modifiable anymore. No replacement.
      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:
      name - is the name of the function
      function - is the function object that is used for evaluating the function
      Throws:
      chemaxon.nfunk.jep.ParseException - if there exists a function with the same name
    • setSymbolTable

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) protected void setSymbolTable(chemaxon.nfunk.jep.SymbolTable symTab)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Sets the SymbolTable object.
      Parameters:
      symTab - is the SymbolTable object
    • compile

      public void compile(String expression) throws chemaxon.nfunk.jep.ParseException
      Compiles the expression string to an inner structure. This speeds-up evaluation.
      Parameters:
      expression - is the expression string
      Throws:
      chemaxon.nfunk.jep.ParseException - on compile error
    • parseExpression

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public void parseExpression(String expression_in) throws chemaxon.nfunk.jep.ParseException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use compile(String) instead.
      Parses the expression. If there are errors in the expression, they are added to the errorList member.
      Parameters:
      expression_in - The input expression string
      Throws:
      chemaxon.nfunk.jep.ParseException - on error
    • callback

      Deprecated, for removal: This API element is subject to removal in a future version.
      No longer used for accessing the context, will be removed without replacement.
      Delegates CallbackIface.callback(String, Object) to the context.
      Specified by:
      callback in interface chemaxon.marvin.util.CallbackIface
      Parameters:
      method - is the method name
      arg - is the method argument
    • evaluate

      public Object evaluate(C context) throws chemaxon.nfunk.jep.ParseException
      Evaluates the expression. The expression string must have been given and compiled beforehand by compile(String expression).
      Parameters:
      context - is the evaluation context
      Returns:
      the evaluation result
      Throws:
      chemaxon.nfunk.jep.ParseException - on evaluation error
    • getValueAsObject

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public Object getValueAsObject() throws chemaxon.nfunk.jep.ParseException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Evaluates and returns the value of the expression as an object. 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.
      Throws:
      chemaxon.nfunk.jep.ParseException - on error
    • evaluate_double

      public double evaluate_double(C context) throws chemaxon.nfunk.jep.ParseException
      Evaluates the expression and converts the result to double. The expression string must have been given and compiled beforehand by compile(String expression).
      Parameters:
      context - is the evaluation context
      Returns:
      the evaluation result
      Throws:
      chemaxon.nfunk.jep.ParseException - on evaluation error
    • getValue

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public double getValue() throws chemaxon.nfunk.jep.ParseException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Evaluates and returns the value of the expression. If the value is complex, the real component of the complex number is returned. To get the complex value, use getComplexValue().
      Returns:
      The calculated value of the expression. If the value is complex, the real component is returned. If an error occurs during evaluation, 0 is returned.
      Throws:
      chemaxon.nfunk.jep.ParseException - on error
    • evaluate_doubles

      public double[] evaluate_doubles(C context) throws chemaxon.nfunk.jep.ParseException
      Evaluates the expression and converts the result to double[]. This is useful if the result is an object array in which case each element is converted to double. The expression string must have been given and compiled beforehand by compile(String expression).
      Parameters:
      context - is the evaluation context
      Returns:
      the evaluation result
      Throws:
      chemaxon.nfunk.jep.ParseException - on evaluation error
    • evaluate_boolean

      public boolean evaluate_boolean(C context) throws chemaxon.nfunk.jep.ParseException
      Evaluates the expression and converts the result boolean. Boolean return values are returned as double: 1.0 for true and 0.0 for false. This function returns true for a value greater than 0.5, false otherwise. This means that for boolean expressions the return value will be OK (and we also eliminated floating-point comparison inaccuracy :-). The expression string must have been given and compiled beforehand by compile(String expression).
      Parameters:
      context - is the evaluation context
      Returns:
      the evaluation result
      Throws:
      chemaxon.nfunk.jep.ParseException - on evaluation error
    • evaluate_booleans

      public boolean[] evaluate_booleans(C context) throws chemaxon.nfunk.jep.ParseException
      Evaluates the expression and converts the result to boolean[]. This is useful if the result is an object array in which case each element is converted to boolean. The expression string must have been given and compiled beforehand by compile(String expression).
      Parameters:
      context - is the evaluation context
      Returns:
      the evaluation result
      Throws:
      EvaluationException - on evaluation error
      chemaxon.nfunk.jep.ParseException
    • getComplexValue

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public chemaxon.nfunk.jep.type.Complex getComplexValue() throws chemaxon.nfunk.jep.ParseException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Complex number support will be removed without replacement.
      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.
      Throws:
      chemaxon.nfunk.jep.ParseException - on error
    • getLogicalValue

      public static int getLogicalValue(Object result)
      Returns the logical correspondent of the specified result object: TRUE, FALSE or UNDECIDED.
      Parameters:
      result - is the result object
      Returns:
      the corresponding logical value
      Since:
      JChem 3.2
    • isUndecided

      public static boolean isUndecided(Object result)
      Returns whether the result object is undecided.
      Returns:
      true if the result is undecided
    • initSymTab

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public void initSymTab()
      Deprecated, for removal: This API element is subject to removal in a future version.
      The symbol table has been replaced with the constant table, and it will become unmodifiable. Use Evaluator.compile(String, Class, ConstantTable) instead.
      Creates a new SymbolTable object as symTab.
    • addStandardConstants

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public void addStandardConstants()
      Deprecated, for removal: This API element is subject to removal in a future version.
      The symbol table has been replaced with the constant table, and it will become unmodifiable. Use Evaluator.compile(String, Class, ConstantTable) instead.
      Adds the constants pi and e to the parser. As addStandardFunctions(), this method should be called immediatly after the JEP object is created.
    • addComplex

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public void addComplex()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Complex number support will be removed without replacement.
      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.
    • addVariable

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public Double addVariable(String name, double value)
      Deprecated, for removal: This API element is subject to removal in a future version.
      The symbol table has been replaced with the constant table, and it will become unmodifiable. Use Evaluator.compile(String, Class, ConstantTable) instead.
      Adds a new 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 added
      value - Initial value or new value for the variable
      Returns:
      Double object of the variable
    • addComplexVariable

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public chemaxon.nfunk.jep.type.Complex addComplexVariable(String name, double re, double im)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Complex number support will be removed without replacement.
      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 added
      re - Initial real value or new real value for the variable
      re - Initial imaginary value or new imaginary value for the variable
      Returns:
      Complex object of the variable
    • addVariableAsObject

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public void addVariableAsObject(String name, Object object)
      Deprecated, for removal: This API element is subject to removal in a future version.
      The symbol table has been replaced with the constant table, and it will become unmodifiable. Use Evaluator.compile(String, Class, ConstantTable) instead.
      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 added
      object - Initial value or new value for the variable
    • removeVariable

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public Object removeVariable(String name)
      Deprecated, for removal: This API element is subject to removal in a future version.
      The symbol table has been replaced with the constant table, and it will become unmodifiable. Use Evaluator.compile(String, Class, ConstantTable) instead.
      Removes a variable from the parser. For example after calling addStandardConstants(), removeVariable("e") might be called to remove the euler constant from the set of variables.
      Returns:
      The value of the variable if it was added earlier. If the variable is not in the table of variables, null is returned.
    • initFunTab

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public void initFunTab()
      Deprecated, for removal: This API element is subject to removal in a future version.
      The function table will become unmodifiable. Configure the Evaluator instead before creating the ChemJEP.
      Creates a new FunctionTable object as funTab.
    • addStandardFunctions

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public void addStandardFunctions()
      Deprecated, for removal: This API element is subject to removal in a future version.
      These functions will be removed without replacement.
      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.
    • getFunction

      Deprecated, for removal: This API element is subject to removal in a future version.
      The function table will become an internal API. No replacement.
      Returns a function from the function table.
      Parameters:
      name - is the function name
      Returns:
      the stored function or its clone, or null if no such function
    • removeFunction

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public Object removeFunction(String name)
      Deprecated, for removal: This API element is subject to removal in a future version.
      The function table will become unmodifiable. Configure the Evaluator instead before creating the ChemJEP.
      Removes a function from the parser.
      Returns:
      If the function was added earlier, the function class instance is returned. If the function was not present, null is returned.
    • setTraverse

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public void setTraverse(boolean value)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use Evaluator.setVerbose(boolean) instead before creating the ChemJEP.
      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 ouput device.

      The default value is false.

      Parameters:
      value - The boolean traversal option.
    • setImplicitMul

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public void setImplicitMul(boolean value)
      Deprecated, for removal: This API element is subject to removal in a future version.
      This option will be removed without replacement.
      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.
    • setAllowUndeclared

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public void setAllowUndeclared(boolean value)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Undeclared variables will always be allowed in the future, changing this will no longer be supported.
      Sets the value for the undeclared variables option. If this option is set to true, expressions containing variables that were not previously added to ChemJEP will not produce an "Unrecognized Symbol" error. Sets the value for the undeclared variables option.

      If this option is set to false, variables that were not previously added to ChemJEP will produce an error while parsing.

      The default value is true.

      Parameters:
      value - The boolean option for allowing undeclared variables.
    • getTopNode

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public chemaxon.nfunk.jep.Node getTopNode()
      Deprecated, for removal: This API element is subject to removal in a future version.
      This method returns an internal representation which will be hidden in the future. No replacement.
      Returns the top node of the expression tree. Because all nodes are pointed to either directly or indirectly, the entire expression tree can be accessed through this node. It may be used to manipulate the expression, and subsequently evaluate it manually.
      Returns:
      The top node of the expression tree
    • getSymbolTable

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public chemaxon.nfunk.jep.SymbolTable getSymbolTable()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Use constantTable() instead.
      Returns the symbol table (the list of all variables that the parser recognises).
      Returns:
      The symbol table
    • getNumberFactory

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public chemaxon.nfunk.jep.type.NumberFactory getNumberFactory()
      Deprecated, for removal: This API element is subject to removal in a future version.
      This feature will be removed without replacement.
      Returns the number factory.
    • hasError

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public boolean hasError()
      Deprecated, for removal: This API element is subject to removal in a future version.
      This class no longer collects exceptions but throws them when they are encountered. The list this method uses is filled but otherwise ignored.
      Returns whether the error list has at least one element.
    • getErrors

      Deprecated, for removal: This API element is subject to removal in a future version.
      This class no longer collects exceptions but throws them when they are encountered. The list this method uses is filled but otherwise ignored.
      Returns all exceptions in the error list.
    • getErrorInfo

      Deprecated, for removal: This API element is subject to removal in a future version.
      This class no longer collects exceptions but throws them when they are encountered. The list this method uses is filled but otherwise ignored.
      Returns a string describing all exceptions in the error list.
    • addError

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) protected void addError(Exception ex)
      Deprecated, for removal: This API element is subject to removal in a future version.
      This class no longer collects exceptions but throws them when they are encountered. The list this method uses is filled but otherwise ignored.
      Adds an exception to the error list.
    • getError

      Deprecated, for removal: This API element is subject to removal in a future version.
      This class no longer collects exceptions but throws them when they are encountered. The list this method uses is filled but otherwise ignored.
      Returns an exception from the error list by its index.
    • getErrorCount

      @Deprecated(forRemoval=true) @SubjectToRemoval(date=JUL_01_2025) public int getErrorCount()
      Deprecated, for removal: This API element is subject to removal in a future version.
      This class no longer collects exceptions but throws them when they are encountered. The list this method uses is filled but otherwise ignored.
      Returns the number of exceptions in the error list.