Пример #1
0
        /*******************************************************************************
         ***                      INSERT FUNCTION                                     ***
         ********************************************************************************
         *** DESCRIPTION: This function takes in a node and a string array. Goes and  ***
         *** tests each element in the array using the CheckIfValid functions created ***
         *** below. If all are valid, each element is added to the node and inserted  ***
         *** into the Symbol Table.                                                   ***
         ********************************************************************************
         *** INPUT ARGS: Node root, string[] v                                        ***
         *** OUTPUT ARGS: N/A                                                         ***
         *** IN/OUT ARGS: N/A                                                         ***
         *** RETURN: Node root                                                        ***
         ********************************************************************************/

        public Node_Sym insert(Node_Sym root, string sym, string val, bool r)
        {
            PassTwo p2 = new PassTwo();

            if (root == null)
            {
                bool MFlag = false;
                bool IFlag = true;

                root        = new Node_Sym();
                root.symbol = p2.TrimOp(sym);
                root.value  = val;
                root.rflag  = r;
                root.iflag  = IFlag;
                root.mflag  = MFlag;
            }
            else
            {
                if (sym == root.symbol)
                {
                    Console.WriteLine(ERR_MSG_3, sym);
                    root.mflag = true;
                    return(root);
                }
                else if (sym.CompareTo(root.symbol) < 0)
                {
                    root.left = insert(root.left, sym, val, r);
                }
                else
                {
                    root.right = insert(root.right, sym, val, r);
                }
            }
            return(root);
        }
Пример #2
0
        /*******************************************************************************
         ***                      INSERT FUNCTION                                     ***
         ********************************************************************************
         *** DESCRIPTION: This function takes in a node. It views the symbol table in ***
         *** order from left to right.                                                ***
         ********************************************************************************
         *** INPUT ARGS: Node root                                                    ***
         *** OUTPUT ARGS: N/A                                                         ***
         *** IN/OUT ARGS: N/A                                                         ***
         *** RETURN: null                                                             ***
         ********************************************************************************/

        public Node_Sym view(Node_Sym root)
        {
            PassTwo p2 = new PassTwo();

            if (root == null)
            {
                return(null);
            }
            else
            {
                view(root.left);
                if (root.symbol != null)
                {
                    Console.WriteLine("{0,-10} {1,-10} {2,-10} {3,-10} {4,-10}", p2.TrimOp(root.symbol), root.value, (root.rflag == true) ? 1 : 0, (root.mflag == true) ? 1 : 0, (root.iflag == true) ? 1 : 0);
                }
                view(root.right);
            }
            return(null);
        }
Пример #3
0
        /*******************************************************************************
         ***                      SEARCH FUNCTION                                     ***
         ********************************************************************************
         *** DESCRIPTION: This function takes in a node and a string. It checks to    ***
         *** see if the passed in string is a valid symbol. It then tests to see if   ***
         *** the passed in value exists in the symbol table. If not an error message  ***
         *** is displayed informing the user.                                         ***
         ********************************************************************************
         *** INPUT ARGS: Node root, string v                                          ***
         *** OUTPUT ARGS: N/A                                                         ***
         *** IN/OUT ARGS: N/A                                                         ***
         *** RETURN: Node root                                                        ***
         ********************************************************************************/

        public Node_Sym search(Node_Sym root, string v)
        {
            PassTwo p2 = new PassTwo();

            v = p2.TrimOp(v.ToUpper());

            if (root == null)
            {
                return(null);
            }
            else if (v.CompareTo(root.symbol) < 0)
            {
                return(search(root.left, v));
            }
            else if (v.CompareTo(root.symbol) > 0)
            {
                return(search(root.right, v));
            }

            return(root);
        }