Attempts to rewrite an Expression in terms of the symbols allowed by the symbol scope
given the known equalities. Returns null if unsuccessful.
This method allows rewriting non-deterministic expressions.
171105
public Expression rewriteExpressionAllowNonDeterministic(Expression expression, Predicate<Symbol> symbolScope)
    {
        return rewriteExpression(expression, symbolScope, true);
    }
857820
final public Selector Expression() throws ParseException {
                          Selector left, right=null; int op = -1;
    left = Term();
    switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
    case 7:
    case 8:
      op = PlusMinus();
      right = Expression();
      break;
    default:
      jj_la1[5] = jj_gen;
      ;
    }
    if (right == null) {if (true) return left;}
    else {if (true) return new OperatorImpl(op, left, right);}
    throw new Error("Missing return statement in function");
  }
687518
private void evaluateExpressions() throws JspException {
        Object obj = null;

        /* 
         * Note: we don't check for type mismatches here; we assume
         * the expression evaluator will return the expected type
         * (by virtue of knowledge we give it about what that type is).
         * A ClassCastException here is truly unexpected, so we let it
         * propagate up.
         */

        // 'value' attribute
        if (value_ != null) {
            value = ExpressionEvaluatorManager.evaluate(
                    "value", value_, Object.class, this, pageContext);
        }

        // 'type' attribute
        if (type_ != null) {
            type = (String) ExpressionEvaluatorManager.evaluate(
                    "type", type_, String.class, this, pageContext);
        }

        // 'pattern' attribute
        if (pattern_ != null) {
            pattern = (String) ExpressionEvaluatorManager.evaluate(
                    "pattern", pattern_, String.class, this, pageContext);
        }

        // 'currencyCode' attribute
        if (currencyCode_ != null) {
            currencyCode = (String) ExpressionEvaluatorManager.evaluate(
                    "currencyCode", currencyCode_, String.class, this,
                    pageContext);
        }

        // 'currencySymbol' attribute
        if (currencySymbol_ != null) {
            currencySymbol = (String) ExpressionEvaluatorManager.evaluate(
                    "currencySymbol", currencySymbol_, String.class, this,
                    pageContext);
        }

        // 'groupingUsed' attribute
        if (groupingUsed_ != null) {
            obj = ExpressionEvaluatorManager.evaluate(
                    "groupingUsed", groupingUsed_, Boolean.class, this,
                    pageContext);
            if (obj != null) {
                isGroupingUsed = ((Boolean) obj).booleanValue();
            }
        }

        // 'maxIntegerDigits' attribute
        if (maxIntegerDigits_ != null) {
            obj = ExpressionEvaluatorManager.evaluate(
                    "maxIntegerDigits", maxIntegerDigits_, Integer.class, this,
                    pageContext);
            if (obj != null) {
                maxIntegerDigits = ((Integer) obj).intValue();
            }
        }

        // 'minIntegerDigits' attribute
        if (minIntegerDigits_ != null) {
            obj = ExpressionEvaluatorManager.evaluate(
                    "minIntegerDigits", minIntegerDigits_, Integer.class, this,
                    pageContext);
            if (obj != null) {
                minIntegerDigits = ((Integer) obj).intValue();
            }
        }

        // 'maxFractionDigits' attribute
        if (maxFractionDigits_ != null) {
            obj = ExpressionEvaluatorManager.evaluate(
                    "maxFractionDigits", maxFractionDigits_, Integer.class, this,
                    pageContext);
            if (obj != null) {
                maxFractionDigits = ((Integer) obj).intValue();
            }
        }

        // 'minFractionDigits' attribute
        if (minFractionDigits_ != null) {
            obj = ExpressionEvaluatorManager.evaluate(
                    "minFractionDigits", minFractionDigits_, Integer.class, this,
                    pageContext);
            if (obj != null) {
                minFractionDigits = ((Integer) obj).intValue();
            }
        }
    }
361078
public static AbstractExpression buildEquavalenceExpression(Collection<AbstractExpression> leftExprs, Collection<AbstractExpression> rightExprs) {
        assert(leftExprs.size() == rightExprs.size());
        Iterator<AbstractExpression> leftIt = leftExprs.iterator();
        Iterator<AbstractExpression> rightIt = rightExprs.iterator();
        AbstractExpression result = null;
        while (leftIt.hasNext() && rightIt.hasNext()) {
            AbstractExpression leftExpr = leftIt.next();
            AbstractExpression rightExpr = rightIt.next();
            AbstractExpression eqaulityExpr = new ComparisonExpression(ExpressionType.COMPARE_EQUAL, leftExpr, rightExpr);
            if (result == null) {
                result = eqaulityExpr;
            } else {
                result = new ConjunctionExpression(ExpressionType.CONJUNCTION_AND, result, eqaulityExpr);
            }
        }
        return result;
    }
1029409
public final void mEQUAL() throws RecognitionException {
        try {
            int _type = EQUAL;
            int _channel = DEFAULT_TOKEN_CHANNEL;
            // src/riemann/Query.g:11:7: ( '=' )
            // src/riemann/Query.g:11:9: '='
            {
            match('='); 

            }

            state.type = _type;
            state.channel = _channel;
        }
        finally {
        }
    }
134797
@Nullable
    public static Predicate anyOf(Collection<Predicate> exprs) {
        Predicate rv = null;
        for (Predicate b : exprs) {
            if (b != null) {
                rv = rv == null ? b : ExpressionUtils.or(rv,b);
            }
        }
        return rv;
    }
1288078
function(symbol) { 
            var has_trig = symbol.hasTrig();
            // we get all the points where a possible zero might exist
            var points1 = get_points(symbol, 0.1);
            var points2 = get_points(symbol, 0.05);
            var points3 = get_points(symbol, 0.01);
            var points = core.Utils.arrayUnique(points1.concat(points2).concat(points3)),
                l = points.length;
            //compile the function and the derivative of the function
            var f = build(symbol.clone()),
                fp = build(_C.diff(symbol.clone()));
            for(var i=0; i<l; i++) {
                var point = points[i];
                add_to_result(Newton(point, f, fp), has_trig);
            }
            solutions.sort();
        }
294451
function evaluate(expr) {
            if (expr.substring(0, 2) === '==') {
                return 'write(JSON.stringify('+expr.substring(2).trim()+'));\n';
            } else if (expr.substring(0, 1) === '=') {
                return 'write('+expr.substring(1).trim()+');\n';
            } else if (expr.substring(0, 3) === '...') {
                expr = '//...\n'+expr.substring(3).trim()+'\n//.';
            }
            if (expr !== '') {
                return expr+'\n';
            }
            return '';
        }
640369
def casting_operators(
            self,
            name=None,
            function=None,
            return_type=None,
            arg_types=None,
            header_dir=None,
            header_file=None,
            recursive=None,
            allow_empty=None):
        """"""
        return (
            self._find_multiple(
                self._impl_matchers[scopedef_t.casting_operator],
                name=name,
                function=function,
                decl_type=self._impl_decl_types[
                    scopedef_t.casting_operator],
                return_type=return_type,
                arg_types=arg_types,
                header_dir=header_dir,
                header_file=header_file,
                recursive=recursive,
                allow_empty=allow_empty)
        )
1101197
static Integer numerator(final String s) {
        if ("".equals(s)) {
            return null;
        }
        String[] tokens = s.split("/");
        return emptyToNullInteger(tokens[0]);
    }
1296739
public final void ternaryExpression() throws RecognitionException {
		ParserRuleReturnScope ts =null;
		ParserRuleReturnScope fs =null;

		 ternOp++; 
		try {
			// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:175:5: ( QUESTION ts= expression COLON fs= expression )
			// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:175:7: QUESTION ts= expression COLON fs= expression
			{
			match(input,QUESTION,FOLLOW_QUESTION_in_ternaryExpression854); if (state.failed) return;
			pushFollow(FOLLOW_expression_in_ternaryExpression858);
			ts=expression();
			state._fsp--;
			if (state.failed) return;
			match(input,COLON,FOLLOW_COLON_in_ternaryExpression860); if (state.failed) return;
			pushFollow(FOLLOW_expression_in_ternaryExpression864);
			fs=expression();
			state._fsp--;
			if (state.failed) return;
			}

		}

		catch (RecognitionException re) {
		    throw re;
		}

		finally {
			// do for sure before leaving
			 ternOp--; 
		}
	}
62710
public final void mGREATER_EQUAL() throws RecognitionException {
        try {
            int _type = GREATER_EQUAL;
            int _channel = DEFAULT_TOKEN_CHANNEL;
            // src/riemann/Query.g:15:15: ( '>=' )
            // src/riemann/Query.g:15:17: '>='
            {
            match(">="); 


            }

            state.type = _type;
            state.channel = _channel;
        }
        finally {
        }
    }
758089
@Override
    protected InfixExpression createCorrectOddnessCheck(ASTRewrite rewrite, Expression numberExpression) {
        Assert.isNotNull(rewrite);
        Assert.isNotNull(numberExpression);

        final AST ast = rewrite.getAST();
        InfixExpression andOddnessCheck = ast.newInfixExpression();
        ParenthesizedExpression parenthesizedExpression = ast.newParenthesizedExpression();
        InfixExpression andExpression = ast.newInfixExpression();

        andExpression.setLeftOperand((Expression) rewrite.createMoveTarget(numberExpression));
        andExpression.setOperator(AND);
        andExpression.setRightOperand(ast.newNumberLiteral("1"));
        parenthesizedExpression.setExpression(andExpression);
        andOddnessCheck.setLeftOperand(parenthesizedExpression);
        andOddnessCheck.setOperator(EQUALS);
        andOddnessCheck.setRightOperand(ast.newNumberLiteral("1"));

        return andOddnessCheck;

    }
382882
public final BaseDescr andExpression() throws RecognitionException {
		BaseDescr result = null;


		BaseDescr left =null;
		BaseDescr right =null;

		try {
			// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:273:3: (left= equalityExpression ( AMPER right= equalityExpression )* )
			// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:273:5: left= equalityExpression ( AMPER right= equalityExpression )*
			{
			pushFollow(FOLLOW_equalityExpression_in_andExpression1348);
			left=equalityExpression();
			state._fsp--;
			if (state.failed) return result;
			if ( state.backtracking==0 ) { if( buildDescr  ) { result = left; } }
			// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:274:3: ( AMPER right= equalityExpression )*
			loop30:
			while (true) {
				int alt30=2;
				int LA30_0 = input.LA(1);
				if ( (LA30_0==AMPER) ) {
					alt30=1;
				}

				switch (alt30) {
				case 1 :
					// src/main/resources/org/drools/compiler/lang/DRL5Expressions.g:274:5: AMPER right= equalityExpression
					{
					match(input,AMPER,FOLLOW_AMPER_in_andExpression1356); if (state.failed) return result;
					pushFollow(FOLLOW_equalityExpression_in_andExpression1360);
					right=equalityExpression();
					state._fsp--;
					if (state.failed) return result;
					if ( state.backtracking==0 ) { if( buildDescr  ) {
					               ConstraintConnectiveDescr descr = ConstraintConnectiveDescr.newIncAnd();
					               descr.addOrMerge( result );
					               descr.addOrMerge( right );
					               result = descr;
					           }
					         }
					}
					break;

				default :
					break loop30;
				}
			}

			}

		}

		catch (RecognitionException re) {
		    throw re;
		}

		finally {
			// do for sure before leaving
		}
		return result;
	}
1016981
@VisibleForTesting
    Expression getScopedCanonical(Expression expression, Predicate<Symbol> symbolScope)
    {
        Expression canonicalIndex = canonicalMap.get(expression);
        if (canonicalIndex == null) {
            return null;
        }
        return getCanonical(filter(equalitySets.get(canonicalIndex), symbolToExpressionPredicate(symbolScope)));
    }
16100
private AttributeAtom rewriteWithRelationVariable(Atom parentAtom){
        if (parentAtom.isResource() && ((AttributeAtom) parentAtom).getRelationVariable().isReturned()) return rewriteWithRelationVariable();
        return this;
    }
855703
private boolean executeQuantifier(int index, Expr.Quantifier expr, CallStack frame) {
		Tuple<Decl.Variable> vars = expr.getParameters();
		if (index == vars.size()) {
			// This is the base case where we evaluate the condition itself.
			RValue.Bool r = executeExpression(BOOL_T, expr.getOperand(), frame);
			boolean q = (expr instanceof Expr.UniversalQuantifier);
			// If this evaluates to true, then we will continue executing the
			// quantifier.
			return r.boolValue() == q;
		} else {
			Decl.Variable var = vars.get(index);
			RValue.Array range = executeExpression(ARRAY_T, var.getInitialiser(), frame);
			RValue[] elements = range.getElements();
			for (int i = 0; i != elements.length; ++i) {
				frame.putLocal(var.getName(), elements[i]);
				boolean r = executeQuantifier(index + 1, expr, frame);
				if (!r) {
					// early termination
					return r;
				}
			}
			return true;
		}
	}