Beispiel #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);
        }
Beispiel #2
0
        bool visitEnter(ReturnStatement returnStatement)
        {
            Expression expression = returnStatement.expression;

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

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

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

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

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