示例#1
0
        public override Value divide(Value v)
        {
            if(v.getNumber() == 0)
                throw new VirtualMachineRuntimeException("0;You can not divide by 0 ( Error: \"" + getText() + " / 0\").");
            var newValue = value / v.getNumber();

            return new NumberValue(newValue);
        }
示例#2
0
        bool visitEnter(ReturnStatement returnStatement)
        {
            Expression expression = returnStatement.expression;

            returnValue = expressionEvaluator.resolve(scopes.First(), expression);

            return false;
        }
示例#3
0
        bool visitEnter(FunctionCall functionCall)
        {
            Identifier identifier = functionCall.functionName;
            ArgumentList argumentList = functionCall.argumentList;

            //std::cout + identifier.getName());

            returnValue = new NullValue();

            Function function = scopes.First().getFunction(identifier);

            scopes.Enqueue(new Scope(scopes.First()));

            if (argumentList != null && argumentList.arguments.Count > 0)
            {
                List<Value.Value> valueList = new List<Value.Value>();

                foreach (Expression ex in argumentList.arguments)
                {
                    valueList.Add(expressionEvaluator.resolve(scopes.First(), ex));
                }

                function.mapScope(scopes.First(), valueList);
            }

            Value.Value tempValue = function.execute(scopes.First());

            if (tempValue != null)
            {
                returnValue = tempValue;
            }

            return false;
        }
示例#4
0
 public override Value greaterEqual(Value v)
 {
     return new BooleanValue(value >= v.getNumber());
 }
示例#5
0
 public override Value greaterEqual(Value v)
 {
     return new BooleanValue(value.Length >= v.getText().Length);
 }
示例#6
0
 public override Value smallerEqual(Value v)
 {
     throw new VirtualMachineRuntimeException("SmallerEqual operation unavailable for bool.");
 }
示例#7
0
 public override Value multiply(Value v)
 {
     throw new VirtualMachineRuntimeException("Multiply operation unavailable for bool.");
 }
示例#8
0
 public override Value greater(Value v)
 {
     throw new VirtualMachineRuntimeException("Greater operation unavailable for bool.");
 }
示例#9
0
        public override Value subtract(Value v)
        {
            var newValue = value - v.getNumber();

            return new NumberValue(newValue);
        }
示例#10
0
        public override Value add(Value v)
        {
            var newValue = value + v.getNumber();

            return new NumberValue(newValue);
        }
示例#11
0
 public Variable(Identifier identifier, Value.Value value)
 {
     this.identifier = identifier;
     this.value = value;
 }
示例#12
0
 public override Value greaterEqual(Value v)
 {
     throw new VirtualMachineRuntimeException("Operation unavailable for NullValue.");
 }
示例#13
0
 public override Value smallerEqual(Value v)
 {
     return new BooleanValue(value.Length <= v.getText().Length);
 }
示例#14
0
 public override Value notEquals(Value v)
 {
     return value != v.getText() ? new BooleanValue(true) : new BooleanValue(false);
 }
示例#15
0
 public override Value divide(Value v)
 {
     throw new VirtualMachineRuntimeException("Divide operation unavailable for bool.");
 }
示例#16
0
 public override Value equals(Value v)
 {
     return new BooleanValue(value == v.getBoolean());
 }
示例#17
0
        public override Value multiply(Value v)
        {
            var newValue = value * v.getNumber();

            return new NumberValue(newValue);
        }
示例#18
0
 public override Value modulo(Value v)
 {
     throw new VirtualMachineRuntimeException("Modulo operation unavailable for bool.");
 }
示例#19
0
 public override Value modulo(Value v)
 {
     var newValue = Convert.ToInt32(value)%Convert.ToInt32(v.getNumber());
     return new NumberValue(newValue);
 }
示例#20
0
 public override Value notEquals(Value v)
 {
     return new BooleanValue(value != v.getBoolean());
 }
示例#21
0
 public override Value smallerEqual(Value v)
 {
     return new BooleanValue(value <= v.getNumber());
 }
示例#22
0
 public override Value subtract(Value v)
 {
     throw new VirtualMachineRuntimeException("Subtract operation unavailable for bool.");
 }
示例#23
0
 public override Value add(Value v)
 {
     return new TextValue(value + v.getText());
 }