Example #1
0
        //inorder traversal and evaluation of nodes based on type
        private double Evalroot(opNode localroot)
        {
            opNode sample = new opNode();
            Type   t      = sample.GetType();

            if (!(localroot == null))
            {
                if (t == localroot.lleft.GetType())
                {
                    Evalroot((opNode)localroot.lleft);
                }
                else
                {
                    AuxEval(localroot);
                }
                if (t == localroot.rright.GetType())
                {
                    Evalroot((opNode)localroot.rright);
                }
                else
                {
                    AuxEval(localroot);
                }
            }
            AuxEval(localroot);
            return(localroot.nnumber);
        }
Example #2
0
        //Remade without root
        public void setVar(string varName, double varValue)
        {
            //Put Variables in a Dictionary
            if (variables.ContainsKey(varName))
            {
                variables[varName] = varValue;
            }
            else
            {
                variables.Add(varName, varValue);
            }
            //Check if regex is just a variable like "A1" thus root would be a varnode
            opNode sample = new opNode();
            Type   t      = sample.GetType();

            varNode sample2 = new varNode();
            Type    t2      = sample2.GetType();

            if (root.GetType() == t2)
            {
                sample2 = (varNode)root;
                if (sample2.nname == varName)
                {
                    sample2.nnumber = varValue;
                    root.nnumber    = varValue;
                }
                return;
            }
            else if (root.GetType() == t)
            {
                setVarroot((opNode)this.rroot, varName, varValue);
            }
        }
Example #3
0
        //Made this function as an approach to finding the varNode for setVar type im keeping it here as reference to myself
        private void inorderroot(opNode localroot)
        {
            opNode sample = new opNode();
            Type   t      = sample.GetType();

            if (!(localroot == null))
            {
                if (t == localroot.lleft.GetType())
                {
                    inorderroot((opNode)localroot.lleft);
                }
                else
                {
                    Console.Write("{0} ", localroot.lleft.nnumber);
                    Console.Write("{0} ", localroot.nnumber);
                }
                if (t == localroot.rright.GetType())
                {
                    inorderroot((opNode)localroot.rright);
                }
                else
                {
                    Console.Write("{0} ", localroot.rright.nnumber);
                }
            }
        }
Example #4
0
        //removed root to meet assignment specifications
        public double Eval()
        {
            opNode sample = new opNode();
            Type   t      = sample.GetType();

            //Special case where regex has no operators and is just a variable or number
            if (root.GetType() != t)
            {
                return(root.nnumber);
            }
            else
            {
                return(Evalroot((opNode)this.root));
            }
        }
Example #5
0
        public void inorder()
        {
            opNode sample = new opNode();
            Type   t      = sample.GetType();

            if (root.GetType() != t)
            {
                Console.Write("{0} ", root.nnumber);
                return;
            }
            else
            {
                inorderroot((opNode)this.rroot);
            }
        }
Example #6
0
        //Inorder search of the varNode type, and after found checking is varName matches
        private void setVarroot(opNode localroot, string varName, double varValue)
        {
            opNode sample = new opNode();
            Type   t      = sample.GetType();

            varNode sample2 = new varNode();
            Type    t2      = sample2.GetType();

            if (!(localroot == null))
            {
                if (t == localroot.lleft.GetType())
                {
                    setVarroot((opNode)localroot.lleft, varName, varValue);
                }
                else
                {
                    if (t2 == localroot.lleft.GetType())
                    {
                        sample2 = (varNode)localroot.lleft;
                        if (sample2.nname == varName)
                        {
                            sample2.nnumber = varValue;
                            //localroot.lleft = sample2;
                        }
                    }
                }
                if (t == localroot.rright.GetType())
                {
                    setVarroot((opNode)localroot.rright, varName, varValue);
                }
                else
                {
                    if (t2 == localroot.rright.GetType())
                    {
                        sample2 = (varNode)localroot.rright;
                        if (sample2.nname == varName)
                        {
                            sample2.nnumber = varValue;
                            //localroot.rright = sample2;
                        }
                    }
                }
            }
        }