Example #1
0
        // evaluates sub-expression and applies unary operator
        public object VisitUnaryExpr(Expr.Unary expr)
        {
            object right = Evaluate(expr.right);

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

            case Token.TokenType.Minus:
                return(-(double)right);
            }

            // Unreachable.
            return(null);
        }
Example #2
0
 public string VisitUnaryExpr(Expr.Unary expr)
 {
     return(Parenthesize(expr.op.lexeme, expr.right));
 }
Example #3
0
 public object VisitUnaryExpr(Expr.Unary expr)
 {
     Resolve(expr.right);
     return(null);
 }