src/main/java/org/mvel2/compiler/AbstractParser.java
protected void reduce() {
    Object v1, v2;
    int operator;
    try {
      switch (operator = (Integer) stk.pop()) {
        case ADD:
        case SUB:
        case DIV:
        case MULT:
        case MOD:
        case EQUAL:
        case NEQUAL:
        case GTHAN:
        case LTHAN:
        case GETHAN:
        case LETHAN:
        case POWER:
        case STR_APPEND:
          stk.op(operator);
          break;

        case AND:
          v1 = stk.pop();
          stk.push(((Boolean) stk.pop()) && ((Boolean) v1));
          break;

        case OR:
          v1 = stk.pop();
          stk.push(((Boolean) stk.pop()) || ((Boolean) v1));
          break;

        case CHOR:
          v1 = stk.pop();
          if (!isEmpty(v2 = stk.pop()) || !isEmpty(v1)) {
            stk.clear();
            stk.push(!isEmpty(v2) ? v2 : v1);
            return;
          }
          else stk.push(null);
          break;

        case REGEX:
          stk.push(java.util.regex.Pattern.compile(java.lang.String.valueOf(stk.pop()))
              .matcher(java.lang.String.valueOf(stk.pop())).matches());
          break;

        case INSTANCEOF:
          stk.push(((Class) stk.pop()).isInstance(stk.pop()));
          break;

        case CONVERTABLE_TO:
          stk.push(org.mvel2.DataConversion.canConvert(stk.peek2().getClass(), (Class) stk.pop2()));
          break;

        case CONTAINS:
          stk.push(containsCheck(stk.peek2(), stk.pop2()));
          break;

        case SOUNDEX:
          stk.push(soundex(java.lang.String.valueOf(stk.pop()))
              .equals(soundex(java.lang.String.valueOf(stk.pop()))));
          break;

        case SIMILARITY:
          stk.push(similarity(java.lang.String.valueOf(stk.pop()), java.lang.String.valueOf(stk.pop())));
          break;

        default:
          reduceNumeric(operator);
      }
    }
    catch (ClassCastException e) {
      throw new CompileException("syntax error or incompatable types", expr, st, e);
    }
    catch (ArithmeticException e) {
      throw new CompileException("arithmetic error: " + e.getMessage(), expr, st, e);
    }
    catch (Exception e) {
      throw new CompileException("failed to subEval expression", expr, st, e);
    }
  }
/**
   * This method is called when we reach the point where we must subEval a trinary operation in the expression.
   * (ie. val1 op val2).  This is not the same as a binary operation, although binary operations would appear
   * to have 3 structures as well.  A binary structure (or also a junction in the expression) compares the
   * current state against 2 downrange structures (usually an op and a val).
   */
This method is called when we reach the point where we must subEval a trinary operation in the expression.
.  This is not the same as a binary operation, although binary operations would appear
to have 3 structures as well.  A binary structure (or also a junction in the expression) compares the
current state against 2 downrange structures (usually an op and a val).
This method is called when we reach the point where we must subEval a trinary operation in the expression . . This is not the same as a binary operation although binary operations would appear to have 3 structures as well . A binary structure ( or also a junction in the expression ) compares the current state against 2 downrange structures ( usually an op and a val ) .
protected void reduce() {
    Object v1, v2;
    int operator;
    try {
      switch (operator = (Integer) stk.pop()) {
        case ADD:
        case SUB:
        case DIV:
        case MULT:
        case MOD:
        case EQUAL:
        case NEQUAL:
        case GTHAN:
        case LTHAN:
        case GETHAN:
        case LETHAN:
        case POWER:
        case STR_APPEND:
          stk.op(operator);
          break;
        case AND:
          v1 = stk.pop();
          stk.push(((Boolean) stk.pop()) && ((Boolean) v1));
          break;
        case OR:
          v1 = stk.pop();
          stk.push(((Boolean) stk.pop()) || ((Boolean) v1));
          break;
        case CHOR:
          v1 = stk.pop();
          if (!isEmpty(v2 = stk.pop()) || !isEmpty(v1)) {
            stk.clear();
            stk.push(!isEmpty(v2) ? v2 : v1);
            return;
          }
          else stk.push(null);
          break;
        case REGEX:
          stk.push(java.util.regex.Pattern.compile(java.lang.String.valueOf(stk.pop()))
              .matcher(java.lang.String.valueOf(stk.pop())).matches());
          break;
        case INSTANCEOF:
          stk.push(((Class) stk.pop()).isInstance(stk.pop()));
          break;
        case CONVERTABLE_TO:
          stk.push(org.mvel2.DataConversion.canConvert(stk.peek2().getClass(), (Class) stk.pop2()));
          break;
        case CONTAINS:
          stk.push(containsCheck(stk.peek2(), stk.pop2()));
          break;
        case SOUNDEX:
          stk.push(soundex(java.lang.String.valueOf(stk.pop()))
              .equals(soundex(java.lang.String.valueOf(stk.pop()))));
          break;
        case SIMILARITY:
          stk.push(similarity(java.lang.String.valueOf(stk.pop()), java.lang.String.valueOf(stk.pop())));
          break;
        default:
          reduceNumeric(operator);
      }
    }
    catch (ClassCastException e) {
      throw new CompileException("syntax error or incompatable types", expr, st, e);
    }
    catch (ArithmeticException e) {
      throw new CompileException("arithmetic error: " + e.getMessage(), expr, st, e);
    }
    catch (Exception e) {
      throw new CompileException("failed to subEval expression", expr, st, e);
    }
  }
protected void reduce ( ) { Object v1 , v2 ; int operator ; try { switch ( operator = ( Integer ) stk . pop ( ) ) { case ADD : case SUB : case DIV : case MULT : case MOD : case EQUAL : case NEQUAL : case GTHAN : case LTHAN : case GETHAN : case LETHAN : case POWER : case STR_APPEND : stk . op ( operator ) ; break ; case AND : v1 = stk . pop ( ) ; stk . push ( ( ( Boolean ) stk . pop ( ) ) && ( ( Boolean ) v1 ) ) ; break ; case OR : v1 = stk . pop ( ) ; stk . push ( ( ( Boolean ) stk . pop ( ) ) || ( ( Boolean ) v1 ) ) ; break ; case CHOR : v1 = stk . pop ( ) ; if ( ! isEmpty ( v2 = stk . pop ( ) ) || ! isEmpty ( v1 ) ) { stk . clear ( ) ; stk . push ( ! isEmpty ( v2 ) ? v2 : v1 ) ; return ; } else stk . push ( null ) ; break ; case REGEX : stk . push ( java . util . regex . Pattern . compile ( java . lang . String . valueOf ( stk . pop ( ) ) ) . matcher ( java . lang . String . valueOf ( stk . pop ( ) ) ) . matches ( ) ) ; break ; case INSTANCEOF : stk . push ( ( ( Class ) stk . pop ( ) ) . isInstance ( stk . pop ( ) ) ) ; break ; case CONVERTABLE_TO : stk . push ( org . mvel2 . DataConversion . canConvert ( stk . peek2 ( ) . getClass ( ) , ( Class ) stk . pop2 ( ) ) ) ; break ; case CONTAINS : stk . push ( containsCheck ( stk . peek2 ( ) , stk . pop2 ( ) ) ) ; break ; case SOUNDEX : stk . push ( soundex ( java . lang . String . valueOf ( stk . pop ( ) ) ) . equals ( soundex ( java . lang . String . valueOf ( stk . pop ( ) ) ) ) ) ; break ; case SIMILARITY : stk . push ( similarity ( java . lang . String . valueOf ( stk . pop ( ) ) , java . lang . String . valueOf ( stk . pop ( ) ) ) ) ; break ; default : reduceNumeric ( operator ) ; } } catch ( ClassCastException e ) { throw new CompileException ( "syntax error or incompatable types" , expr , st , e ) ; } catch ( ArithmeticException e ) { throw new CompileException ( "arithmetic error: " + e . getMessage ( ) , expr , st , e ) ; } catch ( Exception e ) { throw new CompileException ( "failed to subEval expression" , expr , st , e ) ; } }
This method is called when we reach the point where we must subEval a trinary operation in the expression.
This method is called when we reach the point where we must subEval a trinary operation in the expression .