def Evaluate(stack):

  def Resolve(stack):
    """Resolves the postfix stack and evaluates the expression into one value.

    The <stack> is the expression in postfix notation.

    Arguments:
      stack: Postfix notation to be resolved.

    Raises:
      ValueError: If an invalid function name is given or not enough arguments
      are provided for an operator/function.

    Returns:
      The resolution of the postfix notation.
    """
    if not stack:
      raise bigquery_client.BigqueryInvalidQueryError(
          'Not enough arguments.', None, None, None)
    top = stack.pop()
    if isinstance(top, util.OperatorToken):
      args = []
      for unused_i in range(top.num_args):
        args.append(Resolve(stack))
      args.reverse()
      if None in args:
        return None
      if top.num_args == 1:
        return _UNARY_OPERATORS[str(top)](*args)
      else:
        try:
          return _BINARY_OPERATORS[top](*args)
        except ZeroDivisionError:
          raise bigquery_client.BigqueryInvalidQueryError(
              'Division by zero.', None, None, None)
    elif isinstance(top, util.BuiltInFunctionToken):
      func_name = str(top)
      if func_name in _ZERO_ARGUMENT_FUNCTIONS:
        result = _ZERO_ARGUMENT_FUNCTIONS[func_name]
      elif func_name in _ONE_ARGUMENT_FUNCTIONS:
        op = Resolve(stack)
        if op is None:
          result = None
        result = _ONE_ARGUMENT_FUNCTIONS[func_name](op)
      elif func_name in _TWO_ARGUMENT_FUNCTIONS:
        op2 = Resolve(stack)
        op1 = Resolve(stack)
        if op1 is None or op2 is None:
          result = None
        result = _TWO_ARGUMENT_FUNCTIONS[func_name](op1, op2)
      elif func_name in _THREE_ARGUMENT_FUNCTIONS:
        op3 = Resolve(stack)
        op2 = Resolve(stack)
        op1 = Resolve(stack)
        if op1 is None or op2 is None or op3 is None:
          result = None
        result = _THREE_ARGUMENT_FUNCTIONS[func_name](op1, op2, op3)
      else:
        raise bigquery_client.BigqueryInvalidQueryError(
            'No function ' + func_name + ' exists.', None, None, None)
      return result
    elif isinstance(top, util.FieldToken):
      raise bigquery_client.BigqueryInvalidQueryError(
          '%s does not exist as a column.' % str(top), None, None, None)
    elif isinstance(top, util.LiteralToken):
      return top.value
    else:
      return top

  result = Resolve(stack)
  if stack:
    raise bigquery_client.BigqueryInvalidQueryError(
        'Invaid number of arguments.', None, None, None)
  return result
Evaluates the postfix stack to find the result of the expression.
dataset/ETHPy150Open google/encrypted-bigquery-client/src/query_interpreter.py/Evaluate