public SymbolsScope AddChild(string key = "") { var newScope = new SymbolsScope(); newScope.Parent = this; if (this.Childs.Count == 0) { if (key == "") { key = "0"; } this.Childs.Add(key, newScope); return newScope; } var lastChild = this.Childs.Last(); lastChild.Value.Next = newScope; if (key == "") { key = (Convert.ToInt16(lastChild.Key) + 1).ToString(); } this.Childs.Add(key, newScope); return newScope; }
public void UseNamedChildScope(string id) { try { currScope = currScope.Childs[id]; } catch (KeyNotFoundException) { currScope = currScope.AddChild(id); } }
public void UseChildScope() { if (currScope.Childs.Count == 0) { currScope = currScope.AddChild(); } else { currScope = currScope.Childs.First().Value; } }
public void UseParentScope() { if (currScope.Parent == null) { throw new InvalidOperationException("parent scope does not exist"); } currScope = currScope.Parent; }
public void UseGlobalScope() { currScope = globalScope; }
public SymbolTable() { globalScope = new SymbolsScope(); UseGlobalScope(); }