Exemple #1
0
  /**
   * 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.
   *
   * @return The calculated value of the expression if no errors occur. Returns null otherwise.
   */
  public Object getValueAsObject() {
    Object result;

    if (topNode == null) return null;
    // evaluate the expression
    try {
      result = ev.getValue(topNode, symTab);
    } catch (ParseException e) {
      if (debug) System.out.println(e);
      errorList.addElement("Error during evaluation: " + e.getMessage());
      return null;
    } catch (RuntimeException e) {
      if (debug) System.out.println(e);
      errorList.addElement(e.getClass().getName() + ": " + e.getMessage());
      return null;
    }
    return result;
  }
Exemple #2
0
 /**
  * Evaluate an expression. This method evaluates the argument rather than the topNode of the JEP
  * instance. It should be used in conjunction with {@link #parse parse} rather than {@link
  * #parseExpression parseExpression}.
  *
  * @param node the top node of the tree representing the expression.
  * @return The value of the expression
  * @throws ParseException if for some reason the expression could not be evaluated
  * @throws RuntimeException could potentially be thrown.
  * @since 2.3.0 alpha
  */
 public Object evaluate(Node node) throws ParseException {
   return ev.getValue(node, this.symTab);
 }