Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
 public void UseNamedChildScope(string id)
 {
     try
     {
         currScope = currScope.Childs[id];
     }
     catch (KeyNotFoundException)
     {
         currScope = currScope.AddChild(id);
     }
 }
Ejemplo n.º 3
0
 public void UseChildScope()
 {
     if (currScope.Childs.Count == 0)
     {
         currScope = currScope.AddChild();
     }
     else
     {
         currScope = currScope.Childs.First().Value;
     }
 }
Ejemplo n.º 4
0
        public void UseParentScope()
        {
            if (currScope.Parent == null)
            {
                throw new InvalidOperationException("parent scope does not exist");
            }

            currScope = currScope.Parent;
        }
Ejemplo n.º 5
0
 public void UseGlobalScope()
 {
     currScope = globalScope;
 }
Ejemplo n.º 6
0
 public SymbolTable()
 {
     globalScope = new SymbolsScope();
     UseGlobalScope();
 }