Create an evaluator function for the .. (double dot) token. Consumes
zero or more levels of the ascent, the fewest that are required to find
a match when given to previousExpr.
199767
function skipMany(previousExpr) {

      if( previousExpr == always ) {
         /* If there is no previous expression this consume command 
            is at the start of the jsonPath.
            Since JSONPath specifies what we'd like to find but not 
            necessarily everything leading down to it, when running
            out of JSONPath to check against we default to true */            
         return always;
      }
          
      var 
          // In JSONPath .. is equivalent to !.. so if .. reaches the root
          // the match has succeeded. Ie, we might write ..foo or !..foo
          // and both should match identically.
          terminalCaseWhenArrivingAtRoot = rootExpr(),
          terminalCaseWhenPreviousExpressionIsSatisfied = previousExpr,
          recursiveCase = skip1(function(ascent) {
             return cases(ascent);
          }),

          cases = lazyUnion(
                     terminalCaseWhenArrivingAtRoot
                  ,  terminalCaseWhenPreviousExpressionIsSatisfied
                  ,  recursiveCase  
                  );
      
      return cases;
   }
633349
function makeSimpleExpr(expr) {
    var a, b, c;
    if (expr.charAt(0) === '$') {
        return new VariableExpr(expr.substr(1));
    } else if (expr.charAt(0) === '@') {
        a = new NodeTestName(expr.substr(1));
        b = new StepExpr('attribute', a);
        c = new LocationExpr();
        c.appendStep(b);
        return c;
    } else if (expr.match(/^[0-9]+$/)) {
        return new NumberExpr(expr);
    } else {
        a = new NodeTestName(expr);
        b = new StepExpr('child', a);
        c = new LocationExpr();
        c.appendStep(b);
        return c;
    }
}
538297
def eval(self, expr):
        
        # set a copy of the expression aside, so we can give nice errors...

        self.expr = expr

        # and evaluate:
        return self._eval(ast.parse(expr.strip()).body[0].value)
316933
public Object eval( CallStack callstack, Interpreter interpreter)
        throws EvalError
    {
        if ( jjtGetNumChildren() > 0 )
            type = ((BSHType)jjtGetChild(0)).getType( callstack, interpreter );
        else
            type = UNTYPED;

        if (isVarArgs)
            type = Array.newInstance(type, 0).getClass();

        return type;
    }
1005215
def _evaluate(self,x,return_indices = False):
        '''
        
        '''
        return self._evalOrDer(x,True,False)[0]
817383
def prettify_evalue(evalue)
      evalue.to_s.sub(/(\d*\.\d*)e?([+-]\d*)?/) do
        s = format('%.3f', Regexp.last_match[1])
        s << " x 10<sup>#{Regexp.last_match[2]}</sup>" if Regexp.last_match[2]
        s
      end
    end
74174
def eval(self, valuation=None, trace=None):
        
        args2 = []
        for a in self.args:
            if isinstance(a, Function) or isinstance(a, IPredicate):
                args2.append(Constant(a.eval(valuation=valuation, trace=trace)))

            elif isinstance(a, Variable):
                found = False
                for v in valuation:
                    if str(v.var) == a.name:
                        args2.append(Constant(str(v.value.name)))
                        found = True
                        break
                if not found:
                    raise Exception("IPredicate instantiation failed : missing vars")
            else:
                args2.append(Constant(a))

        return args2
567278
def _eval_progress(self, match):
        '''
        
        '''
        _locals = {k: safe_float(v) for k, v in match.groupdict().items()}
        if "x" not in _locals:
            _locals["x"] = [safe_float(x) for x in match.groups()]
        try:
            return int(eval(self.progress_expr, {}, _locals))
        except:
            return None
603350
public Object evaluate(Object pContext,
                           VariableResolver pResolver,
                           Map functions,
                           String defaultPrefix,
                           Logger pLogger)
            throws ELException {
        Object value = mExpression.evaluate(pContext, pResolver, functions,
                defaultPrefix, pLogger);
        if (mOperator != null) {
            value = mOperator.apply(value, pContext, pLogger);
        } else {
            for (int i = mOperators.size() - 1; i >= 0; i--) {
                UnaryOperator operator = (UnaryOperator) mOperators.get(i);
                value = operator.apply(value, pContext, pLogger);
            }
        }
        return value;
    }
274809
public Object eval( CallStack callstack, Interpreter interpreter )
        throws EvalError
    {
        throw new InterpreterError(
            "Unimplemented or inappropriate for " + getClass().getName() );
    }
1247384
function step2$1(token) {
                var r1 = getR1(token);

                if (!r1) {
                    return token;
                }

                if (r1.match(/(d|v)t$/)) {
                    return token.slice(0, -1);
                }

                return token;
            }
853966
public Object evaluate(Object pContext,
                           VariableResolver pResolver,
                           Map functions,
                           String defaultPrefix,
                           Logger pLogger)
            throws ELException {
        Object value = mExpression.evaluate(pContext, pResolver, functions,
                defaultPrefix, pLogger);
        for (int i = 0; i < mOperators.size(); i++) {
            BinaryOperator operator = (BinaryOperator) mOperators.get(i);

            // For the And/Or operators, we need to coerce to a boolean
            // before testing if we shouldEvaluate
            if (operator.shouldCoerceToBoolean()) {
                value = Coercions.coerceToBoolean(value, pLogger);
            }

            if (operator.shouldEvaluate(value)) {
                Expression expression = (Expression) mExpressions.get(i);
                Object nextValue = expression.evaluate(pContext, pResolver,
                        functions, defaultPrefix,
                        pLogger);

                value = operator.apply(value, nextValue, pContext, pLogger);
            }
        }
        return value;
    }
3426
private static Requirement evaluateReversePolishNotation(Iterator<Tokenizer.Token> iterator, Semver.SemverType type) {
        try {
            Tokenizer.Token token = iterator.next();

            if (token.type == Tokenizer.TokenType.VERSION) {
                if ("*".equals(token.value) || (type == Semver.SemverType.NPM && "latest".equals(token.value))) {
                    // Special case for "*" and "latest" in NPM
                    return new Requirement(new Range("0.0.0", Range.RangeOperator.GTE), null, null, null);
                }
                Semver version = new Semver(token.value, type);
                if (version.getMinor() != null && version.getPatch() != null) {
                    Range range = new Range(version, Range.RangeOperator.EQ);
                    return new Requirement(range, null, null, null);
                } else {
                    // If we have a version with a wildcard char (like 1.2.x, 1.2.* or 1.2), we need a tilde requirement
                    return tildeRequirement(version.getValue(), type);
                }
            } else if (token.type == Tokenizer.TokenType.HYPHEN) {
                Tokenizer.Token token3 = iterator.next(); // Note that token3 is before token2!
                Tokenizer.Token token2 = iterator.next();
                return hyphenRequirement(token2.value, token3.value, type);
            } else if (token.type.isUnary()) {
                Tokenizer.Token token2 = iterator.next();

                Range.RangeOperator rangeOp;
                switch (token.type) {
                    case EQ:
                        rangeOp = Range.RangeOperator.EQ;
                        break;
                    case LT:
                        rangeOp = Range.RangeOperator.LT;
                        break;
                    case LTE:
                        rangeOp = Range.RangeOperator.LTE;
                        break;
                    case GT:
                        rangeOp = Range.RangeOperator.GT;
                        break;
                    case GTE:
                        rangeOp = Range.RangeOperator.GTE;
                        break;
                    case TILDE:
                        return tildeRequirement(token2.value, type);
                    case CARET:
                        return caretRequirement(token2.value, type);
                    default:
                        throw new SemverException("Invalid requirement");
                }

                Range range = new Range(token2.value, rangeOp);
                return new Requirement(range, null, null, null);
            } else {
                Requirement req1 = evaluateReversePolishNotation(iterator, type);
                Requirement req2 = evaluateReversePolishNotation(iterator, type);

                RequirementOperator requirementOp;
                switch (token.type) {
                    case OR:
                        requirementOp = RequirementOperator.OR;
                        break;
                    case AND:
                        requirementOp = RequirementOperator.AND;
                        break;
                    default:
                        throw new SemverException("Invalid requirement");
                }

                return new Requirement(null, req1, requirementOp, req2);
            }
        } catch (NoSuchElementException e) {
            throw new SemverException("Invalid requirement");
        }
    }
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 '';
        }
140174
def evaluate(expression):
    
    op_stack  = deque() # operator stack
    out_stack = deque() # output stack (values)
    tokens = parse(expression) # calls the function only once!
    for token in tokens:
        if numeric_value.match(token):
            out_stack.append(float(token))
        elif token == '(':
            op_stack.append(token)
        elif token == ')':
            while len(op_stack) > 0 and op_stack[-1] != '(':
                apply_operation(op_stack, out_stack)
            op_stack.pop() # Remove remaining '('
        else: # is_operator(token)
            while len(op_stack) > 0 and is_operator(op_stack[-1]) and higher_priority(op_stack[-1], token):
                apply_operation(op_stack, out_stack)
            op_stack.append(token)

    while len(op_stack) > 0:
        apply_operation(op_stack, out_stack)

    return out_stack[-1]
5646
function Matcher(matchFunc, toString) {
    this.match = function(expression) {
        // Save/restore marks to ensure that failed matches always restore
        // the original location in the expression.
        var result;
        expression.mark();
        result = matchFunc(expression);
        if (result) {
            expression.drop();
        } else {
            expression.restore();
        }
        return result;
    };
    this.toString = typeof toString === "function" ? toString : function() {
        return toString;
    };
}
516600
def eval_expr(expr_str, show_tokens=False, showast=False,
              showgrammar=False, compile_mode='exec'):
    

    parser_debug = {'rules': False, 'transition': False,
                    'reduce': showgrammar,
                    'errorstack': True, 'context': True }
    parsed = parse_expr(expr_str, show_tokens=show_tokens,
                        parser_debug=parser_debug)
    if showast:
        print(parsed)

    assert parsed == 'expr', 'Should have parsed grammar start'

    evaluator = ExprEvaluator()

    # What we've been waiting for: Generate source from AST!
    return evaluator.traverse(parsed)