using System; using System.Collections.Generic; namespace NTERA.Interpreter { public class VariableDictionary : Dictionary> { public VariableDictionary() : base(StringComparer.InvariantCultureIgnoreCase) { InitDefaults(); } public new Value this[string key] { get => this[key, 0]; set => this[key, 0] = value; } public Value this[string key, int arrayIndex] { get => base[key][arrayIndex]; set { if (base.TryGetValue(key, out var dict)) dict[arrayIndex] = value; else Add(key, arrayIndex, value); } } public void Add(string key, Value value) { Add(key, 0, value); } public void Add(string key, int arrayIndex, Value value) { base.Add(key, new Dictionary { [arrayIndex] = value }); } private void InitDefaults() { Add("LOCAL", 0); Add("LOCALS", ""); Add("RESULT", 0); Add("RESULTS", ""); } } }