Ejemplo n.º 1
0
 public IValue Operator(string op, IValue operand)
 {
     if (op == "()")
     {
         var parameterChecker = new TypeChecker(parameterType);
         if (!parameterChecker.Check(operand))
         {
             throw new TypeException("Function parameter is invalid");
         }
         var result        = ValueBehaviourFactory.GetBehaviour(this, operand).BinaryOperator(this, op, operand);
         var resultChecker = new TypeChecker(returnType);
         if (!resultChecker.Check(result))
         {
             throw new TypeException("Function result is invalid");
         }
         IType type;
         if (returnType.Type.Check(ValueType.TYPE))
         {
             type = returnType.Get <IType>();
         }
         else if (returnType.Type.Check(ValueType.LIST))
         {
             type = new ListType(returnType, returnType.ToString());
         }
         else
         {
             throw new TypeException("Function return value invalid!");
         }
         return(new Binding(result.ToString(), type, result).Value);
     }
     return(ValueBehaviourFactory.GetBehaviour(this, operand).BinaryOperator(this, op, operand));
 }
Ejemplo n.º 2
0
 public override bool Equals(object obj)
 {
     if (obj is Value)
     {
         var val2 = obj as Value;
         return((ValueBehaviourFactory.GetBehaviour(this, val2).BinaryOperator(this, "==", val2)).Get <int>() == 1);
     }
     return(false);
 }
Ejemplo n.º 3
0
 public IValue Operator(string op)
 {
     return(ValueBehaviourFactory.GetBehaviour(this).UnaryOperator(this, op));
 }
Ejemplo n.º 4
0
        public override IValue VisitUnary_operators(gramParser.Unary_operatorsContext context)
        {
            var result = Visit(context.expr());

            return(ValueBehaviourFactory.GetBehaviour(result).UnaryOperator(result, context.SUB().GetText()));
        }
Ejemplo n.º 5
0
 public IValue Operator(string op, IValue operand)
 {
     return(ValueBehaviourFactory.GetBehaviour(this, operand).BinaryOperator(this, op, operand));
 }