Beispiel #1
0
        public object VisitUnaryExpr(Expr.Unary expr)
        {
            object right = Evaluate(expr.right);

            switch (expr.op.type)
            {
            case TokenType.BANG:
                return(!IsTruthy(right));

            case TokenType.MINUS:
                CheckNumberOperand(expr.op, right);
                return(-(double)right);
            }

            return(null);
        }
Beispiel #2
0
 public string VisitUnaryExpr(Expr.Unary expr)
 {
     return(Parenthesize(expr.op.lexeme, expr.right));
 }