Example #1
0
        private unsafe void Pop(string[] operands)
        {
            int *digit = null;

            GetPointer(operands[0], out digit);
            *digit = STACK.Pop();
        }
Example #2
0
        //OVERRIDE FOR BINARY TREES.
        public virtual void InOrder(ITree <T> tree, Action <Node <T> > act = null)
        {
            Node <T> m = tree.Root();

            if (act == null)
            {
                act = (n) => Console.Write(tree.Value(n).ToString() + " ");
            }

            IStack <Node <T> > STACK;
            IStack <Node <T> > STACK2;

            if (__IsSubclassOfRawGeneric(typeof(S), typeof(Stack <Node <T> >)))
            {
                STACK  = new Stack <Node <T> >(tree.GetCount());
                STACK2 = new Stack <Node <T> >(tree.GetCount());
            }
            else
            {
                STACK  = new S();
                STACK2 = new S();
            }
            while (true)
            {
                if (m != null)
                {
                    STACK.Push(m);
                    m = tree.LeftMostChild(m);//LEFTMOST_CHILD(node,TREE) while current != null current = current.leftson
                }
                else
                {
                    if (STACK.IsEmpty())
                    {
                        return;
                    }
                    //Node<T> c = STACK.Top();
                    //1) 1,2 S: 4. 2)4 3 5 8 S: 4. 3) 4 6 10 S: empty.
                    act(STACK.Top());
                    m = tree.RightSibling(tree.LeftMostChild(STACK.Top()));//right son of the STACK //current = top.rightson
                    STACK.Pop();
                    if (m != null && tree.RightSibling(m) != null)
                    {
                        STACK2.Push(tree.RightSibling(m));//PUSH THIRD CHILD...
                    }

                    if (STACK.IsEmpty() && m == null && !(STACK2.IsEmpty()))
                    {
                        //STACK.Push(STACK2.Top());
                        //STACK2.Pop();
                        m = STACK2.Top();
                        STACK2.Pop();
                    }
                }
            }
        }
Example #3
0
        public void PreOrder(ITree <T> tree, Node <T> st, Action <Node <T> > act = null)
        {
            Node <T> m = st;//SUB_TREE(st,T)

            if (act == null)
            {
                act = (n) => Console.Write(tree.Value(n).ToString() + " ");
            }

            IStack <Node <T> > STACK;

            if (__IsSubclassOfRawGeneric(typeof(S), typeof(Stack <Node <T> >)))
            {
                STACK = new Stack <Node <T> >(tree.GetCount());
            }
            else
            {
                STACK = new S();
            }

            while (true)
            {
                if (m != null)
                {
                    act(m);                    //LABEL(node,TREE)
                    STACK.Push(m);
                    m = tree.LeftMostChild(m); //LEFTMOST_CHILD(node,TREE)
                }
                else
                {
                    if (STACK.IsEmpty())
                    {
                        return;
                    }
                    if (STACK.Top().Equals(st))
                    {
                        return;                         //after root exit.
                    }
                    m = tree.RightSibling(STACK.Top()); //RIGHT_SIBLING(TOP(S),TREE) where TOP(S) is node
                    STACK.Pop();                        //POP(S)
                }
            }
        }
Example #4
0
        public void PostOrder(ITree <T> tree, Action <Node <T> > act = null)
        {
            Node <T> m = tree.Root();//ROOT(T)

            if (act == null)
            {
                act = (n) => Console.Write(tree.Value(n).ToString() + " ");
            }
            IStack <Node <T> > STACK;

            if (__IsSubclassOfRawGeneric(typeof(S), typeof(Stack <Node <T> >)))
            {
                STACK = new Stack <Node <T> >(tree.GetCount());
            }
            else
            {
                STACK = new S();
            }
            while (true)
            {
                if (m != null)
                {
                    //Move action LABEL(node,TREE) to the end.
                    STACK.Push(m);
                    m = tree.LeftMostChild(m);//LEFTMOST_CHILD(node,TREE)
                }
                else
                {
                    if (STACK.IsEmpty())
                    {
                        return;
                    }
                    act(STACK.Top());                   //LABEL(node,TREE)
                    m = tree.RightSibling(STACK.Top()); //RIGHT_SIBLING(TOP(S),TREE) where TOP(S) is node
                    STACK.Pop();                        //POP(S)
                }
            }
        }
Example #5
0
        public unsafe void Xor(string[] operands)
        {
            if (operands.Length == 0)
            {
                int first  = STACK.Pop();
                int second = STACK.Pop();
                first = first ^ second;
                CheckParity(first);
                if (first > 0)
                {
                    sf = 0;
                }
                else
                {
                    sf = 1;
                }
                if (first == 0)
                {
                    zf = 0;
                }
                cf = 0;
                of = 0;
                STACK.Push(first);
                return;
            }

            if (operands.Length == 1)
            {
                int first = 0;

                if (IsNumber(operands[0]))
                {
                    first = int.Parse(operands[0]);
                }
                else
                {
                    int *tmp = null;
                    GetPointer(operands[0], out tmp);
                    first = *tmp;
                }
                eax = eax ^ first;
                CheckParity(eax);
                if (eax > 0)
                {
                    sf = 0;
                }
                else
                {
                    sf = 1;
                }
                if (eax == 0)
                {
                    zf = 0;
                }
                cf = 0;
                of = 0;
                return;
            }

            if (operands.Length == 2)
            {
                int *first = null;
                GetPointer(operands[0], out first);

                if (IsNumber(operands[1]))
                {
                    *first = (*first) ^ int.Parse(operands[1]);
                }
                else
                {
                    int *second = null;
                    GetPointer(operands[1], out second);
                    *first = (*first) ^ (*second);
                }

                CheckParity(*first);
                if (*first > 0)
                {
                    sf = 0;
                }
                else
                {
                    sf = 1;
                }
                if (*first == 0)
                {
                    zf = 0;
                }
                cf = 0;
                of = 0;
                return;
            }

            if (operands.Length == 3)
            {
                int *first = null;
                GetPointer(operands[0], out first);
                int tmp = 0;
                if (IsNumber(operands[1]))
                {
                    tmp = (*first) ^ int.Parse(operands[1]);
                }
                else
                {
                    int *second = null;
                    GetPointer(operands[1], out second);
                    tmp = (*first) ^ (*second);
                }

                int *third = null;
                GetPointer(operands[2], out third);
                *third = tmp;


                CheckParity(tmp);
                if (tmp > 0)
                {
                    sf = 0;
                }
                else
                {
                    sf = 1;
                }
                if (tmp == 0)
                {
                    zf = 0;
                }
                cf = 0;
                of = 0;
                return;
            }
        }
Example #6
0
        private unsafe void Cmp(string[] operands)
        {
            int first  = 0;
            int second = 0;

            if (operands.Length == 0)
            {
                second = STACK.Pop();
                first  = STACK.Pop();
            }
            if (operands.Length == 1)
            {
                first = eax;
                if (IsNumber(operands[0]))
                {
                    second = int.Parse(operands[0]);
                }
                else
                {
                    int *tmpS = null;
                    GetPointer(operands[0], out tmpS);
                    second = *tmpS;
                }
            }


            if (operands.Length == 2)
            {
                if (IsNumber(operands[0]))
                {
                    first = int.Parse(operands[0]);
                }
                else
                {
                    int *tmpF = null;
                    GetPointer(operands[0], out tmpF);
                    first = *tmpF;
                }


                if (IsNumber(operands[1]))
                {
                    second = int.Parse(operands[1]);
                }
                else
                {
                    int *tmpS = null;
                    GetPointer(operands[1], out tmpS);
                    second = *tmpS;
                }
            }


            //JA
            if (first > second)
            {
                cf = 0;
                zf = 0;
                return;
            }


            //JBE
            if (first <= second)
            {
                cf = 1;
                zf = 1;
                return;
            }
        }
Example #7
0
        private unsafe void Sub(string[] operands)
        {
            if (operands.Length == 0)
            {
                int second = STACK.Pop();
                int first  = STACK.Pop();
                STACK.Push(second + first);
                if (STACK.Peek() > 0)
                {
                    sf = 0;
                }
                else
                {
                    sf = 1;
                }
                return;
            }

            if (operands.Length == 1)
            {
                int first = 0;

                if (IsNumber(operands[0]))
                {
                    first = int.Parse(operands[0]);
                }
                else
                {
                    int *tmp = null;
                    GetPointer(operands[0], out tmp);
                    first = *tmp;
                }
                eax -= first;
                if (eax > 0)
                {
                    sf = 0;
                }
                else
                {
                    sf = 1;
                }
                return;
            }

            if (operands.Length == 2)
            {
                int *first = null;
                GetPointer(operands[0], out first);

                if (IsNumber(operands[1]))
                {
                    *first -= int.Parse(operands[1]);
                }
                else
                {
                    int *second = null;
                    GetPointer(operands[1], out second);
                    *first -= (*second);
                }
                if (*first > 0)
                {
                    sf = 0;
                }
                else
                {
                    sf = 1;
                }
                return;
            }

            if (operands.Length == 3)
            {
                int *first = null;
                GetPointer(operands[0], out first);
                int tmp = 0;
                if (IsNumber(operands[1]))
                {
                    tmp = *first - int.Parse(operands[1]);
                }
                else
                {
                    int *second = null;
                    GetPointer(operands[1], out second);
                    tmp = (*first) - (*second);
                }

                int *third = null;
                GetPointer(operands[2], out third);
                *third = tmp;
                if (*third > 0)
                {
                    sf = 0;
                }
                else
                {
                    sf = 1;
                }
                return;
            }
        }