コード例 #1
0
ファイル: SymbolTable.cs プロジェクト: paulochang/DecafIde
 /// <summary>
 /// Finds and retrieves the symbol by Id and category.
 /// </summary>
 /// <param name="id">The id you're looking for</param>
 /// <param name="theCategory">The category you're looking into</param>
 /// <returns>The symbol or null if not found.</returns>
 public Symbol FindSymbol(string id, symbolCategory theCategory)
 {
     Symbol theResult;
     switch (theCategory)
     {
         case symbolCategory.Cvariable:
             if (theVariableTable.TryGetValue(id, out theResult))
                 return theResult;
             else
                 return null;
         case symbolCategory.CstructDecl:
             if (theStructDeclTable.TryGetValue(id, out theResult))
                 return theResult;
             else
                 return null;
         case symbolCategory.Cmethod:
             if (theMethodTable.TryGetValue(id, out theResult))
                 return theResult;
             else
                 return null;
         default:
             throw new Exception("Internal symbolCategory error");
     }
 }
コード例 #2
0
ファイル: SymbolTable.cs プロジェクト: paulochang/DecafIde
 /// <summary>
 /// Finds and retrieves the specified symbol type by ID and Category
 /// </summary>
 /// <param name="id">The id you're looking for.</param>
 /// <param name="theCategory">The category you're looking into.</param>
 /// <returns></returns>
 public SymbolType? GetSymbolType(string id, symbolCategory theCategory)
 {
     Symbol tempSymbol = FindSymbol(id, theCategory);
     if (tempSymbol != null) return tempSymbol.Type;
     else return null;
 }
コード例 #3
0
ファイル: ScopeManager.cs プロジェクト: paulochang/DecafIde
        /// <summary>
        /// Performs and superficial search of a certain symbol
        /// </summary>
        /// <param name="id">The symbol ID</param>
        /// <param name="theCategory">The symbol category</param>
        /// <returns></returns>
        public Symbol currentScopeFindSymbol(string id, symbolCategory theCategory)
        {
            Symbol result = null;

            result = currentScope.FindSymbol(id, theCategory);
            return result;
        }
コード例 #4
0
ファイル: SymbolTable.cs プロジェクト: paulochang/DecafIde
 /// <summary>
 /// Checks whether the symbol id is contained within the specified category
 /// </summary>
 /// <param name="id">The id to look for</param>
 /// <param name="theCategory">The category that you should try to find it into</param>
 /// <returns>True if the symbol is found, false otherwise.</returns>
 public bool CheckSymbol(string id, symbolCategory theCategory)
 {
     switch (theCategory)
     {
         case symbolCategory.Cvariable:
             return theVariableTable.ContainsKey(id);
         case symbolCategory.CstructDecl:
             return theStructDeclTable.ContainsKey(id);
         case symbolCategory.Cmethod:
             return theMethodTable.ContainsKey(id);
         default:
             throw new Exception("Internal symbolCategory error");
     }
 }
コード例 #5
0
ファイル: ScopeManager.cs プロジェクト: paulochang/DecafIde
        /// <summary>
        /// Checks if the symbol with certain id and category is present in the current scope
        /// </summary>
        /// <param name="id">The symbol supposed id</param>
        /// <param name="theCategory">The symbol supposed category</param>
        /// <returns></returns>
        internal bool CheckScope(string id, symbolCategory theCategory)
        {
            bool symbolInScope = currentScope.CheckSymbol(id, theCategory);
            if (symbolInScope) return symbolInScope;
            if (currentScope.getEnclosingScope() != null)
                return currentScope.getEnclosingScope().CheckSymbol(id, theCategory);

            return false;

            //Boolean symbolFound = false;
            //Stack<SymbolTable> tempStack = new Stack<SymbolTable>();

            //while ((!symbolFound) && (currentScope.Count > 0))
            //{
            //    symbolFound = currentScope.Peek().CheckSymbol(id, theCategory);
            //    if (!symbolFound) tempStack.Push(currentScope.Pop());
            //}

            //while (tempStack.Count > 0)
            //    currentScope.Push(tempStack.Pop());

            //return symbolFound;
        }
コード例 #6
0
ファイル: ScopeManager.cs プロジェクト: paulochang/DecafIde
        /// <summary>
        /// Finds the symbol based on its ID and category (Variable, method or structDeclaration)
        /// </summary>
        /// <param name="id">The symbol ID</param>
        /// <param name="theCategory">The symbol category</param>
        /// <returns></returns>
        public Symbol FindSymbol(string id, symbolCategory theCategory)
        {
            Symbol s = currentScope.FindSymbol(id, theCategory);
            if (s != null) return s;
            if (currentScope.getEnclosingScope() != null)
                return currentScope.getEnclosingScope().FindSymbol(id, theCategory);

            return null;

            //Symbol result = null;
            //Boolean symbolFound = false;
            //Stack<SymbolTable> tempStack = new Stack<SymbolTable>();

            //while ((!symbolFound) && (currentScope.Count > 0))
            //{
            //    result = currentScope.Peek().FindSymbol(id, theCategory);
            //    symbolFound = result != null;
            //    if (!symbolFound) tempStack.Push(currentScope.Pop());
            //}

            //if (currentScope.Count <= 0) throw new
            //Exception("Symbol " + id + " not found in symbolTable.");
            //while (tempStack.Count > 0)
            //    currentScope.Push(tempStack.Pop());

            //return result;
        }
コード例 #7
0
ファイル: Symbol.cs プロジェクト: paulochang/DecafIde
 /// <summary>
 /// Initializes a symbol declaration with the specified type and category.
 /// </summary>
 /// <param name="theSymbolType">The current symbol type</param>
 /// <param name="theCategory">The current symbol category</param>
 public Symbol(SymbolType theSymbolType, symbolCategory theCategory)
 {
     type = theSymbolType;
     category = theCategory;
 }
コード例 #8
0
ファイル: Symbol.cs プロジェクト: paulochang/DecafIde
 /// <summary>
 /// Initializes a variable declaration with the specified type.
 /// </summary>
 /// <param name="theSymbolType">The variable type</param>
 public Symbol(SymbolType theSymbolType)
 {
     type = theSymbolType;
     category = symbolCategory.Cvariable;
 }
コード例 #9
0
ファイル: Symbol.cs プロジェクト: paulochang/DecafIde
 /// <summary>
 /// Intializes a struct declaration, which has a void type.
 /// </summary>
 public Symbol()
 {
     type = SymbolType.Tvoid;
     category = symbolCategory.CstructDecl;
 }