Exemple #1
0
        public bool put(string strId, string strToken, string strValue)
        {
            IDENTIFIER idTemp = (IDENTIFIER)hashSymbolTable[strId];

            if (idTemp == null || idTemp.Scope == "NULL" && idTemp.Lexeme == "NULL")
            {
                IndexOutOfRangeException e = new IndexOutOfRangeException();

                throw e;
            }

            if (strToken != KEEP)
            {
                idTemp.Token = strToken;
                idTemp.CheckForArr();
            }

            if (strValue != KEEP)
            {
                idTemp.Value = strValue;
                idTemp.CheckForArr();
            }

            hashSymbolTable[strId] = idTemp;

            return(true);
        }
Exemple #2
0
        /* This method returns the value of the desired index of the desired table entry, for array entries. You should
         * pass the key of the entry you desire to get the value of, and the index (1 indexing for the array)
         * (index 0 is the size of the array do not change the size of the array). You can check other scopes by using
         * the hashkey(string, string) method.
         */
        /* Variable             Type                Purpose
         * charArray            char[]              it is used as the parameter of string split method
         * id                   string              it hold the key to be referenced
         * idEntry              IDENTIFIER          it hold the returned identier
         * value                int                 it holds the index of the desired element in the array
         * strArray             string[]            it is used to hold the substring generated by string split
         */
        public string get(string id, int value)
        {
            IndexOutOfRangeException e = new IndexOutOfRangeException();

            IDENTIFIER idEntry = new IDENTIFIER((IDENTIFIER)hashSymbolTable[id]);

            if (idEntry.Scope == "NULL")
            {
                throw (e);
            }

            char[] charArray = new char[1];

            charArray[0] = ' ';

            string[] strArray = new string[100];

            strArray = idEntry.Value.Split(charArray);

            try
            {
                return(strArray[value]);
            }
            catch (IndexOutOfRangeException)
            {
                return("NOT_FOUND");
            }
        }
Exemple #3
0
        /* The method returns the value of the desired table entry. for non-array entries.  You should
         * pass the key of the entry you desire to get the value of. You can check other scopes by using
         * the hashkey(string, string) method.
         */
        /* Variable             Type                Purpose
         * id                   string              it hold the key to be referenced
         * idEntry              IDENTIFIER          it hold the returned identier
         */
        public string get(string id)
        {
            IndexOutOfRangeException e = new IndexOutOfRangeException();

            IDENTIFIER idEntry = new IDENTIFIER((IDENTIFIER)hashSymbolTable[id]);

            if (idEntry.Scope == "NULL")
            {
                throw (e);
            }

            return(idEntry.Value);
        }
Exemple #4
0
        //copy constructor

        /* Variable             Type                Purpose
         * idOrg                IDENTIFIER          it is the identifier to be copied
         */
        public IDENTIFIER(IDENTIFIER idOrg)
        {
            try
            {
                Lexeme = idOrg.Lexeme;
                Scope  = idOrg.Scope;
                Token  = idOrg.Token;
                Value  = idOrg.Value;
            }
            catch (NullReferenceException)
            {
                Lexeme = Scope = Token = Value = "NULL";
            }
        }
Exemple #5
0
        /* This method will let you change the token, or array value value of the desired table entry.
         * if you do not wish to change the the token or the value for the string of token or
         * value use the string "KEEP".
         */

        /* for variable destripts see other put method comments
         * Variable             Type                Purpose
         * intValue             int                 stores index to be change in array of desired identifier
         */
        public bool put(string strId, string strToken, int intValue, string strValue)
        {
            IDENTIFIER idTemp = (IDENTIFIER)hashSymbolTable[strId];

            if (idTemp == null || idTemp.Scope == "NULL" && idTemp.Lexeme == "NULL")
            {
                IndexOutOfRangeException e = new IndexOutOfRangeException();

                throw e;
            }

            if (strToken != KEEP)
            {
                idTemp.Token = strToken;
                idTemp.CheckForArr();
            }

            if (strValue != KEEP)
            {
                string[] strArray  = new string[100];
                char[]   charArray = new char[1];

                charArray[0] = ' ';

                strArray = idTemp.Value.Split(charArray);

                try
                {
                    strArray[intValue] = strValue;
                }
                catch (IndexOutOfRangeException)
                {
                    return(false);
                }

                idTemp.Value = "";

                for (int intI = 0; intI < strArray.Length; intI++)
                {
                    idTemp.Value += strArray[intI] + " ";
                }

                //idTemp.Value = idTemp.Value.Substring(1, idTemp.Value.Length - 1);
            }

            hashSymbolTable[strId] = idTemp;

            return(true);
        }
Exemple #6
0
 public void put(IDENTIFIER id, int val)
 {
     hashSymbolTable[id.Lexeme] = val;
 }
Exemple #7
0
 public int get(IDENTIFIER id)
 {
     return((int)hashSymbolTable[id.Lexeme]);
 }
Exemple #8
0
        /* This method will insert the desired lexeme into the table.  The lexeme needs to be stored
         * in an IDENTIFIER, and you should generated the key using hashkey(string) or hashkey(string, string)
         */

        /* Variable             Type                Purpose
         * idLexeme             IDENTIFIER          it is the identifier to be stored in table
         * strKey               string              it is the key
         */
        public void Insert(IDENTIFIER idLexeme, string strKey)
        {
            hashSymbolTable[strKey] = idLexeme;
        }