예제 #1
0
        public object Visit(Expr.Prefix prefix)
        {
            object right = Evaluate(prefix.rhs);

            switch (prefix.opp.type)
            {
            case TokenType.Bang:
                return(!IsTrue(right));

            case TokenType.Minus:
                ValidateNumberOperand(prefix.opp, right);
                return(-(double)right);

            case TokenType.MinusMinus:
                ValidateNumberOperand(prefix.opp, right);
                return((double)right - 1);

            case TokenType.PlusPlus:
                ValidateNumberOperand(prefix.opp, right);
                return((double)right + 1);
            }

            // Unreachable
            return(null);
        }
예제 #2
0
 public object Visit(Expr.Prefix _prefix)
 {
     return(null);
 }
예제 #3
0
 string Expr.IVisitor <string> .Visit(Expr.Prefix prefix)
 {
     return(Parenthesize(prefix.opp.lexeme, prefix.rhs));
 }