Пример #1
0
        public Symbol <AST> Resolve(string name, bool search_global, int line = -1)
        {
            if (EnclosingScope == null && !search_global)
            {
                return(null);
            }

            if (symbols.ContainsKey(name))
            {
                return(symbols[name]);
            }

            Symbol <AST> rt = null;

            // if not here, check any enclosing scope
            if (EnclosingScope != null)
            {
                rt = EnclosingScope.Resolve(name, search_global);
            }

            if (rt == null && line > 0)
            {
                ConsoleColor restore = Console.ForegroundColor;
                Console.ForegroundColor = System.ConsoleColor.Red;
                Console.Error.WriteLine("line {0}: {1} is undefined", line, name);
                Console.ForegroundColor = restore;
            }
            return(rt); // not found
        }
Пример #2
0
        public Boolean AllowedForwardReferences(Ast ast)
        {
            if (Symbols.ContainsKey(ast.Token.TokenValue))
            {
                return(AllowAllForwardReferences);
            }

            if (EnclosingScope == null)
            {
                return(false);
            }

            return(EnclosingScope.AllowedForwardReferences(ast));
        }
Пример #3
0
        public Symbol Resolve(String name)
        {
            Symbol o;

            if (Symbols.TryGetValue(name, out o))
            {
                return(o);
            }

            if (EnclosingScope == null)
            {
                return(null);
            }

            return(EnclosingScope.Resolve(name));
        }
Пример #4
0
        public IdentifierDesc FindIdentifier(string name)
        {
            var identifier = FindIdentifierInCurrentScope(name);

            if (identifier != null)
            {
                return(identifier);
            }

            if (EnclosingScope != null)
            {
                identifier = EnclosingScope.FindIdentifier(name);
            }

            return(identifier);
        }
Пример #5
0
        public Symbol Resolve(string name)
        {
            Symbol s;

            if (this.Members.TryGetValue(name, out s))
            {
                return(s);
            }
            else if (EnclosingScope != null)
            {
                return(EnclosingScope.Resolve(name));
            }
            else
            {
                return(null);
            }
        }
Пример #6
0
        /// <summary> ClassSymbol and MethodSymbol overload this.</summary>
        /// <param name="name">the symbol to resolve</param>
        /// <param name="search_global">search the global namespace?</param>
        /// <returns>Symbol</returns>
        public virtual Symbol <AST> ResolveSymbol(string name, bool search_global)
        {
            if (EnclosingScope == null && !search_global)
            {
                return(null);
            }

            if (Members.ContainsKey(name))
            {
                return(Members[name]);
            }
            // if not here, check any parent scope
            if (EnclosingScope != null)
            {
                return(EnclosingScope.Resolve(name, search_global));
            }
            return(null); // not found
        }