protected override void Execute(SmallBasicEngine engine) { BaseValue value = engine.EvaluationStack.Pop(); executeAux(new ArrayValue(engine.Memory), this.array, this.indicesCount); BaseValue executeAux(ArrayValue memory, string index, int remainingIndices) { if (remainingIndices == 0) { if (string.IsNullOrEmpty(value.ToString())) { memory.RemoveIndex(index); } else { memory.SetIndex(index, value); } } else { ArrayValue nextMemory = memory.TryGetValue(index, out BaseValue elementValue) && elementValue is ArrayValue elementArrayValue ? elementArrayValue : new ArrayValue(); string nextIndex = engine.EvaluationStack.Pop().ToString(); memory.SetIndex(index, executeAux(nextMemory, nextIndex, remainingIndices - 1)); } return(memory); } }
protected override BaseValue Execute(BaseValue first, BaseValue second) { if (first is NumberValue && second is NumberValue) { return(new NumberValue(first.ToNumber() + second.ToNumber())); } return(StringValue.Create(first.ToString() + second.ToString())); }
protected override BaseValue Execute(BaseValue first, BaseValue second) => new BooleanValue(first.ToString() != second.ToString());