示例#1
0
        public object VisitUnary(Expression.Unary expression)
        {
            var right = Evaluate(expression.Right);

            switch (expression.Operator.Type)
            {
            case TokenType.Minus:
                CheckNumberOperand(expression.Operator, right);
                return(-(double)right);

            case TokenType.Bang:
                return(!IsTruthy(right));
            }

            // unreachable.
            return(null);
        }
示例#2
0
 public string VisitUnary(Expression.Unary expression)
 {
     return(Parenthesize(expression.Operator.Lexeme, expression.Right));
 }