Example #1
0
 /** Inserts the specified name into this symbol table and returns the corresponding symbol. */
 public Symbol Insert(string name, Definition definition)
 {
     #if TEST
     if (name == null)
         throw new System.ArgumentException("name");
     #endif
     Symbol symbol = new Symbol(definition, _stack.Peek());
     try
     {
         _stack.Peek().InsertObject(name, symbol);
     }
     catch (Toolbox.VFS.Error)
     {
         throw new ParserError(definition.Cursor, "Symbol already exists: " + name);
     }
     return symbol;
 }
Example #2
0
 public SymbolTable()
 {
     _stack.Push(_volume);
     _world = new Symbol(null, _volume);
 }
Example #3
0
        public void EnterBlock(string name, Definition definition)
        {
            #if TEST
            if (name == null)
                throw new System.ArgumentException("name");
            if (definition == null)
                throw new System.ArgumentException("definition");
            #endif

            // Handle re-visits to existing scopes.
            Folder<Symbol> found = (Folder<Symbol>) _stack.Peek().Resolve(name);
            if (found != null && found.Data.Definition == definition)
            {
                _stack.Push(found);
                return;
            }

            // Create new folder and push it onto the stack of open folders.
            Symbol symbol = new Symbol(definition);
            symbol.Folder = _stack.Peek().InsertFolder(name, symbol);
            _stack.Push(symbol.Folder);
        }
Example #4
0
        public bool TryLookup(string name, out Symbol result)
        {
            Object<Symbol> @object = _stack.Peek().FindUpwards(name);
            if (@object == null)
            {
                result = null;
                return false;
            }

            result = (Symbol) @object.Data;
            return true;
        }