示例#1
0
    public object visitUnaryExpr(Expression.Unary expr)
    {
        var first = expr.Operand.Accept(this);

        if (expr.Operator == null)
        {
            return(first);
        }

        // TODO Sematically check available operations (string - string impossible)
        // TODO abstract these operations (and maybe variable types)
        switch (expr.Operator.GetName())
        {
        case "PLUS":
            return((int)first);

        case "MINUS":
            return(-((int)first));

        case "NOT":
            return(!((bool)first));

        default:
            throw new System.NotImplementedException(string.Format("UNARY {0} NOT IMPLEMENTED", expr.Operator.GetName()));
        }
    }
示例#2
0
        protected override object?Visit(Expression.Unary ury)
        {
            base.Visit(ury);
            // TODO: Implement everything
            // For now we assume correct usage
            switch (ury.Operator)
            {
            case Expression.UnaryOp.Dereference:
            {
                var subType = System.TypeOf(ury.Operand);
                if (!(subType is Type.Ptr))
                {
                    // TODO
                    throw new NotImplementedException("Can't deref non-pointer!");
                }
            }
            break;

            default:
            {
                // TODO
            }
            break;
            }
            return(null);
        }
    public string visitUnaryExpr(Expression.Unary expr)
    {
        var firstType = expr.Operand.Accept(this);

        // TODO use eval to get types?
        if (expr.Operator != null && expr.Operator.Type == TokenType.NOT)
        {
            return("bool");
        }

        return(firstType);
    }
        public object VisitUnaryExpression(Expression.Unary expression)
        {
            object right = Evaluate(expression.right);

            switch (expression.op.type)
            {
            case TokenType.MINUS:
                CheckNumberOperand(expression.op, right);
                return(-(double)right);

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

            // Unreachable.
            return(null);
        }
示例#5
0
文件: Compiler.cs 项目: Daouki/ivy
        public ByteCodeChunk VisitUnaryExpression(Expression.Unary expression)
        {
            var chunk = new ByteCodeChunk();

            chunk.AddRange(VisitExpression(expression.Right));

            switch (expression.Operator.Type)
            {
            case TokenType.Minus:
                chunk.AddInstruction(Instruction.NegateI);
                break;

            default:
                throw new ArgumentOutOfRangeException(
                          $"`{expression.Operator.Type.ToString()} is not a valid unary operator.'");
            }

            return(chunk);
        }
示例#6
0
 public string VisitUnaryExpression(Expression.Unary expression)
 {
     return(Parenthesize(expression.op.lexeme, expression.right));
 }
示例#7
0
 public object VisitUnaryExpression(Expression.Unary expression)
 {
     Resolve(expression.right);
     return(null);
 }
示例#8
0
文件: Resolver.cs 项目: jukaLang/Juka
 public object VisitUnaryExpr(Expression.Unary expr)
 {
     throw new NotImplementedException("Resolver VisitUnaryExpr is not implemented");
 }
示例#9
0
 public object VisitUnaryExpr(Expression.Unary expr)
 {
     throw new NotImplementedException();
 }