Пример #1
0
        /// <summary>
        /// Enter the given symbol information into the symbol table.  If the given
        ///    symbol is already present at the current nest level, produce an error
        ///    message, but do NOT throw any exceptions from this method.
        /// </summary>
        public virtual void enter(string s, Attributes info)
        {
            SymbolTableEntry symbolTableEntry = RetrieveSymbol(s);

            if (symbolTableEntry != null)
            {
                return; // error message; symbol is already in the current scope dont add it
            }
            else
            {
                SymbolTableEntry tableEntry = null;
                if (symTable.ContainsKey(s))
                {
                    List <SymbolTableEntry> existingSymbolTableEntryList = symTable[s];
                    if (existingSymbolTableEntryList != null)
                    {
                        tableEntry = AddSymbolTableEntry(s, info);
                        existingSymbolTableEntryList.Add(tableEntry);
                    }
                }
                else
                {
                    List <SymbolTableEntry> newSymbolTableEntryList = new List <SymbolTableEntry>();
                    tableEntry = AddSymbolTableEntry(s, info);
                    newSymbolTableEntryList.Add(tableEntry);
                    symTable.Add(s, newSymbolTableEntryList);
                }

                List <SymbolTableEntry> currentScopeList = scopeDisplay[CurrentNestLevel];
                if (!currentScopeList.Contains(tableEntry))
                {
                    currentScopeList.Add(tableEntry);
                }
            }
        }
Пример #2
0
        public virtual SymbolTableEntry AddSymbolTableEntry(string name, Attributes attributes)
        {
            SymbolTableEntry symbolTableEntry = new SymbolTableEntry();

            symbolTableEntry.NAME  = name;
            symbolTableEntry.TYPE  = attributes;
            symbolTableEntry.LEVEL = CurrentNestLevel;
            return(symbolTableEntry);
        }
Пример #3
0
 private void DeleteSymTableEntry(SymbolTableEntry sym)
 {
     if (symTable.ContainsKey(sym.NAME))
     {
         List <SymbolTableEntry> symbolTableEntryList = symTable[sym.NAME];
         foreach (var item in symbolTableEntryList)
         {
             if (item.LEVEL == sym.LEVEL)
             {
                 if (symbolTableEntryList.Count() == 1)
                 {
                     symTable.Remove(sym.NAME);
                 }
                 else
                 {
                     symbolTableEntryList.Remove(item);
                 }
                 return;
             }
         }
     }
 }