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); }
bool visitEnter(ReturnStatement returnStatement) { Expression expression = returnStatement.expression; returnValue = expressionEvaluator.resolve(scopes.First(), expression); return false; }
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; }
public override Value greaterEqual(Value v) { return new BooleanValue(value >= v.getNumber()); }
public override Value greaterEqual(Value v) { return new BooleanValue(value.Length >= v.getText().Length); }
public override Value smallerEqual(Value v) { throw new VirtualMachineRuntimeException("SmallerEqual operation unavailable for bool."); }
public override Value multiply(Value v) { throw new VirtualMachineRuntimeException("Multiply operation unavailable for bool."); }
public override Value greater(Value v) { throw new VirtualMachineRuntimeException("Greater operation unavailable for bool."); }
public override Value subtract(Value v) { var newValue = value - v.getNumber(); return new NumberValue(newValue); }
public override Value add(Value v) { var newValue = value + v.getNumber(); return new NumberValue(newValue); }
public Variable(Identifier identifier, Value.Value value) { this.identifier = identifier; this.value = value; }
public override Value greaterEqual(Value v) { throw new VirtualMachineRuntimeException("Operation unavailable for NullValue."); }
public override Value smallerEqual(Value v) { return new BooleanValue(value.Length <= v.getText().Length); }
public override Value notEquals(Value v) { return value != v.getText() ? new BooleanValue(true) : new BooleanValue(false); }
public override Value divide(Value v) { throw new VirtualMachineRuntimeException("Divide operation unavailable for bool."); }
public override Value equals(Value v) { return new BooleanValue(value == v.getBoolean()); }
public override Value multiply(Value v) { var newValue = value * v.getNumber(); return new NumberValue(newValue); }
public override Value modulo(Value v) { throw new VirtualMachineRuntimeException("Modulo operation unavailable for bool."); }
public override Value modulo(Value v) { var newValue = Convert.ToInt32(value)%Convert.ToInt32(v.getNumber()); return new NumberValue(newValue); }
public override Value notEquals(Value v) { return new BooleanValue(value != v.getBoolean()); }
public override Value smallerEqual(Value v) { return new BooleanValue(value <= v.getNumber()); }
public override Value subtract(Value v) { throw new VirtualMachineRuntimeException("Subtract operation unavailable for bool."); }
public override Value add(Value v) { return new TextValue(value + v.getText()); }