Example #1
0
        private string SkipToNextTermSymb(List <string> ruleListToAddSymbolsFromStack)
        {
            string stackLex = stack.Pop();

            while (stackLex.Equals(SpecialSymbs.NOT_TERMINAL_SYMB))
            {
                ruleListToAddSymbolsFromStack.Add(stackLex);
                stackLex = stack.Pop();
            }

            return(stackLex);
        }
Example #2
0
        static void SymbolsStackTest()
        {
            SymbolsStack s = new SymbolsStack();

            string[] strs = { "1", "2", "3", "4", "5" };

            s.Push(strs[0]);
            s.Push(strs[1]);
            Debug.Assert(s.Lenght == 2);

            string poped = s.Pop();

            Debug.Assert(poped.Equals(strs[1]));
            Debug.Assert(s.Lenght == 1);

            s.Push(strs[1]);
            s.Push(strs[2]);
            Debug.Assert(s.Lenght == 3);
            string getted = s.GetFirstTerminalSymb();

            Debug.Assert(s.Lenght == 3);
            Debug.Assert(getted.Equals(strs[2]));

            s.Push(SpecialSymbs.NOT_TERMINAL_SYMB);
            Debug.Assert(s.Lenght == 4);
            getted = s.GetFirstTerminalSymb();
            Debug.Assert(s.Lenght == 4);
            Debug.Assert(getted.Equals(strs[2]));

            s = new SymbolsStack();
            for (int i = 0; i < 100; i++)
            {
                s.Push(Convert.ToString(i));
            }
            Debug.Assert(s.Lenght == 100);
            for (int i = 99; i >= 0; i--)
            {
                Debug.Assert(Convert.ToString(i).Equals(s.Pop()));
            }
            Debug.Assert(s.Lenght == 0);
        }