Esempio n. 1
0
        public object VisitUnaryExpr(Expr.Unary expr)
        {
            var right = Evaluate(expr.Right);

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

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

            return(null);
        }
Esempio n. 2
0
 public string VisitUnaryExpr(Expr.Unary expr)
 {
     return($"{expr.Operator}{expr.Right.Accept(this)}");
 }
Esempio n. 3
0
 public string VisitUnaryExpr(Expr.Unary expr)
 {
     return(Parenthesize(expr.Operator.Lexeme, expr.Right));
 }