Evaluate an expression using the variable values.
@param string $expression the expression. A PHP expression with placeholders
like {a} for where the variables need to go.
@return float the computed result.
424101
public function calculate($expression) {
        // Make sure no malicious code is present in the expression. Refer MDL-46148 for details.
        if ($error = qtype_calculated_find_formula_errors($expression)) {
            throw new moodle_exception('illegalformulasyntax', 'qtype_calculated', '', $error);
        }
        $expression = $this->substitute_values_for_eval($expression);
        if ($datasets = question_bank::get_qtype('calculated')->find_dataset_names($expression)) {
            // Some placeholders were not substituted.
            throw new moodle_exception('illegalformulasyntax', 'qtype_calculated', '',
                '{' . reset($datasets) . '}');
        }
        return $this->calculate_raw($expression);
    }
820253
public function addEvaluatedExpressions(array $expressions)
    {
        foreach ($expressions as $expression => $result) {
            try {
                $this->evaluatedExpressions[] = $this->addVariable($expression, $result);
            } catch (BufferFullException $e) {
                $this->evaluatedExpressions[] = $this->variableTable->bufferFullVariable();
            }
        }
    }
688694
private function compute(string $expression): int
    {
        // catch anything which could be a security issue
        if (0 !== preg_match("/[^\d.+*%^|&~<>\/()-]/", $this->expression)) {
            throw new \InvalidArgumentException('Wrong value in error types config value:' . $this->expression);
        }

        return 0 + (int)eval('return ' . $expression . ';');
    }
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]
259412
function(expression){
      var t = this,
          value = null;

      // Evaluate the expression
      try {
        value = eval(expression);
      } catch (e) {
        var err = 'Unable to evaluate expression: "' + expression + '"';
        logger.error('evaluate', err);
        throw new Error(err);
      }

      // Return the value
      return value;
    }
751679
protected function compileVar($expression)
	{
		// expected => ('varName', View::shared('someVar'))

		$args  = substr($expression, 1, -1);
		$args2 = explode('=', $args);

		if(count($args2) !== 2)
		{
			throw new InvalidArgumentException("The @def statemant is out of pattern: @def(var = \$someValue)");
		}

		$var  = str_replace(array('\'', ' '), '', $args2[0]);
		$data = trim($args2[1]);

		return "<?php \${$var} = {$data};?>";
	}
387352
protected function compileEchoStack($expression)
    {
        foreach (['RawEcho', 'Echo'] as $token) {
            $out = $this->{'compile'.$token}($expression);

            if (strlen($out) !== 0) {
                $expression = $out;
            }
        }

        return $expression;
    }
99463
public function getValue()
	{
		$arguments	= func_get_args();
		$expression	= $this->insertValues( $arguments );
		$value		= $this->evaluateExpression( $expression, $arguments );
		return $value;
	}
134045
function matches($expression)
    {
        $parts = explode('.', $expression);

        // Defer evaluation of next expression to loop node.
        if (isset($parts[1])) {
            return ($this->loopNode->matches($parts[1]));
        }

        // Next expression is empty, hence it matches.
        return true;
    }
1212011
static private function translate ($expression)
  {
    list ($main, $op) = self::translateSimpleExpression ($expression);

    $exp = $main;
    if ($op == '|') {
      $filters = preg_split (self::PARSE_FILTER, $expression);
      if ($filters)
        foreach ($filters as $filter)
          $exp = self::translateFilter ($filter, $exp);
    }

    return $exp;
  }
1370786
public static function evaluateEelExpression($expression, EelEvaluatorInterface $eelEvaluator, array $contextVariables, array $defaultContextConfiguration = [])
    {
        $matches = null;
        if (!preg_match(Package::EelExpressionRecognizer, $expression, $matches)) {
            throw new Exception('The EEL expression "' . $expression . '" was not a valid EEL expression. Perhaps you forgot to wrap it in ${...}?', 1410441849);
        }

        $defaultContextVariables = self::getDefaultContextVariables($defaultContextConfiguration);
        $contextVariables = array_merge($defaultContextVariables, $contextVariables);

        if (isset($contextVariables['q'])) {
            throw new Exception('Context variable "q" not allowed, as it is already reserved for FlowQuery use.', 1410441819);
        }

        $contextVariables['q'] = function ($element) {
            return new FlowQuery\FlowQuery(is_array($element) || $element instanceof \Traversable ? $element : [$element]);
        };

        $context = new ProtectedContext($contextVariables);
        $context->whitelist('q');

        return $eelEvaluator->evaluate($matches['exp'], $context);
    }
998870
public function valuesExpr($expression) {
		$args = func_get_args();
		$this->expression = array_shift($args);
		
		if (empty($args))
			return $this;
		
		//check if argument is a list
		try {
			$this->valuesArray($args[0]);
		}
		catch (\InvalidArgumentException $e) {
			$this->valueList = $args;
		}
		
		return $this;
	}
244284
protected function generateEvaluatorCode($expression)
    {
        $parser = new EntityPrivilegeExpressionParser($expression);
        /** @var boolean|array $result */
        $result = $parser->match_Expression();

        if ($result === false) {
            throw new ParserException(sprintf('Expression "%s" could not be parsed.', $expression), 1416933186);
        } elseif ($parser->pos !== strlen($expression)) {
            throw new ParserException(sprintf('Expression "%s" could not be parsed. Error starting at character %d: "%s".', $expression, $parser->pos, substr($expression, $parser->pos)), 1416933203);
        } elseif (!array_key_exists('code', $result)) {
            throw new ParserException(sprintf('Parser error, no code in result %s ', json_encode($result)), 1416933192);
        }
        return $result['code'];
    }
956851
public function postProcessExpression(Expression $expression)
    {
        if ($this->hasHash($expression->hashCode())) {
            $alias = $this->getAlias($expression->hashCode());
            $alias = new Expr\Column($alias);
            $alias->setBuilder($this);
            $expression = new Expr\Raw(sprintf('%s AS %s', $expression->toSQL(), $alias->toSQL()));
        }
        
        return $expression;
    }
173899
public function evaluateJavascript($expression, $limit = null)
    {
        $key = '___lastValue___' . uniqid();
        $this->executeStep(
            sprintf("_sahi.setServerVarPlain(%s, JSON.stringify(%s))", json_encode($key), $expression),
            $limit
        );

        $resp = $this->executeCommand('getVariable', array('key' => $key));

        return json_decode($resp, true);
    }
1318851
public function addExpression($expression)
    {
        if (!$this->expressions->contains($expression)) {
            $this->expressions[] = $expression;
        }

        return $this;
    }
913972
protected function compileForelse($expression)
    {
        $empty = '$__empty_'.++$this->forElseCounter;

        preg_match('/\( *(.*) +as *(.*)\)$/is', $expression, $matches);

        $iteratee = trim($matches[1]);

        $iteration = trim($matches[2]);

        $initLoop = "\$__currentLoopData = {$iteratee}; \$__env->addLoop(\$__currentLoopData);";

        $iterateLoop = '$__env->incrementLoopIndices(); $loop = $__env->getLastLoop();';

        return "<?php {$empty} = true; {$initLoop} foreach(\$__currentLoopData as {$iteration}): {$iterateLoop} {$empty} = false; ?>";
    }