// Makes a new entry in the identification table for the given identifier
        // and attribute. The new entry belongs to the current level.
        // duplicated is set to to true iff there is already an entry for the
        // same identifier at the current level.

        public void enter(String id, Declaration attr)
        {
            IdEntry entry = this.latest;
            bool    present = false, searching = true;

            // Check for duplicate entry ...
            while (searching)
            {
                if (entry == null || entry.level < this.level)
                {
                    searching = false;
                }
                else if (entry.id.Equals(id))
                {
                    present   = true;
                    searching = false;
                }
                else
                {
                    entry = entry.previous;
                }
            }

            attr.duplicated = present;
            // Add new entry ...
            entry       = new IdEntry(id, attr, this.level, this.latest);
            this.latest = entry;
        }
コード例 #2
0
 public IdEntry(String id, Declaration attr, int level, IdEntry previous)
 {
     this.id       = id;
     this.attr     = attr;
     this.level    = level;
     this.previous = previous;
 }
        // Closes the topmost level in the identification table, discarding
        // all entries belonging to that level.

        public void closeScope()
        {
            IdEntry entry, local;

            // Presumably, idTable.level > 0.
            entry = this.latest;
            while (entry.level == this.level)
            {
                local = entry;
                entry = local.previous;
            }

            this.level--;
            this.latest = entry;
        }
 public IdentificationTable()
 {
     level  = 0;
     latest = null;
 }