private void FindTerminalSetWithEnd(string terminal, ref List <string> currSet, ref List <string> guideSetForRule, ref bool isFirstRule)
        {
            bool isExist = terminalList.Exists(x => x.terminal == terminal);

            if (isExist)
            {
                TerminalList currTerminalList = terminalList.Find(x => x.terminal.Contains(terminal));
                int          indexAmount      = currTerminalList.index.Count();

                for (int i = 0; i < indexAmount; i++)
                {
                    int           currIndex       = currTerminalList.index[i];
                    Rule          currRule        = grammarList[currIndex];
                    List <string> ruleСomposition = currRule.ruleСomposition;
                    int           elementIndex    = ruleСomposition.FindIndex(x => x == terminal);

                    if (elementIndex < ruleСomposition.Count() - 1)
                    {
                        string nextElement     = ruleСomposition[elementIndex + 1];
                        string newtElementType = DefineStringType(nextElement);

                        bool isEndInSet = false;

                        switch (newtElementType)
                        {
                        case TERMINAL:
                            bool isExist1 = guideSet.Exists(x => x.ruleName == nextElement);
                            if (isExist1)
                            {
                                GuideSet currGuideSet = guideSet.Find(x => x.ruleName == nextElement);

                                foreach (string setElement in currGuideSet.set)
                                {
                                    if (setElement == END)
                                    {
                                        isEndInSet = true;
                                    }

                                    AddNotTerminalToList(setElement, ref currSet);
                                    AddNotTerminalToList(setElement, ref guideSetForRule);
                                }
                            }

                            if (isEndInSet)
                            {
                                FindTerminalSetWithEnd(nextElement, ref currSet, ref guideSetForRule, ref isFirstRule);
                            }

                            break;

                        case NOT_TERMINAL:

                            AddNotTerminalToList(nextElement, ref currSet);
                            AddNotTerminalToList(nextElement, ref guideSetForRule);
                            break;
                        }
                    }
                }
            }
        }
        public void PrintGuideSet()
        {
            int amount1 = guideSet.Count;

            Console.WriteLine("Printing Guide Set...");
            Console.WriteLine("--benig");

            for (int i = 0; i < amount1; i++)
            {
                GuideSet t1 = guideSet[i];
                Console.Write(t1.ruleName);
                Console.Write(" : ");

                int amount2 = t1.set.Count;

                for (int j = 0; j < amount2; j++)
                {
                    Console.Write(t1.set[j]);
                    Console.Write(", ");
                }

                Console.WriteLine();
            }

            Console.WriteLine("--end");
            Console.WriteLine();
        }
        private void OperateRule(Rule rule, ref bool isFirstRule, ref GuideSet currGuideSet,
                                 ref List <string> currSet, string currWord, ref string currName, ref bool isChanges)
        {
            if (rule.ruleName == grammarList[0].ruleName)
            {
                isFirstRule = true;
            }

            List <string> guideSetForRule = new List <string>();
            bool          isNeedToSaveSet = (currName != "") && (currName != rule.ruleName);

            if ((isNeedToSaveSet) && (currSet.Count() != 0))
            {
                currGuideSet.set = currSet;
                string ruleName = currGuideSet.ruleName;
                bool   isExist  = guideSet.Exists(x => x.ruleName == ruleName);
                if (!isExist)
                {
                    guideSet.Add(currGuideSet);
                }
            }

            if (currName != rule.ruleName)
            {
                currName = rule.ruleName;
                currGuideSet.ruleName = currName;
                currSet = new List <string>();
            }

            int indexInComposition = 0;

            currWord = rule.ruleСomposition[indexInComposition];

            Redirect(rule.ruleName, currWord, ref currSet, ref guideSetForRule, ref isFirstRule, indexInComposition);

            int before = rule.guideSet.Count();
            int guideSetForRuleSize = guideSetForRule.Count();

            for (int i = 0; i < guideSetForRuleSize; i++)
            {
                AddNotTerminalToList(guideSetForRule[i], ref rule.guideSet);
                AddNotTerminalToList(guideSetForRule[i], ref rule.guideSet);
            }

            int after = rule.guideSet.Count();

            if (before != after)
            {
                isChanges = true;
            }
        }
        public void DefineGuideSet()
        {
            string        currName     = "";
            string        currWord     = "";
            GuideSet      currGuideSet = new GuideSet();
            List <string> set          = new List <string>();

            currGuideSet.set = set;
            List <string> currSet     = new List <string>();
            bool          isFirstRule = false;
            bool          isChanges   = true;

            while (isChanges)
            {
                isChanges = false;

                foreach (Rule rule in grammarList)
                {
                    OperateRule(rule, ref isFirstRule, ref currGuideSet, ref currSet, currWord, ref currName, ref isChanges);

                    if ((currName != "") && (currSet.Count != 0))
                    {
                        currGuideSet.set = currSet;
                        string ruleName = currGuideSet.ruleName;
                        bool   isExist  = guideSet.Exists(x => x.ruleName == ruleName);
                        if (!isExist)
                        {
                            guideSet.Add(currGuideSet);
                        }
                        else
                        {
                            List <string> setFor   = guideSet.Find(x => x.ruleName == ruleName).set;
                            List <string> startSet = currGuideSet.set;

                            foreach (string element in startSet)
                            {
                                AddNotTerminalToList(element, ref setFor);
                            }
                        }
                    }
                }
            }
        }
        private void FindTerminalSet(string terminal, ref List <string> currSet, ref List <string> guideSetForRule,
                                     ref bool isNeedToCheckNextSymbol)
        {
            bool isExist = guideSet.Exists(x => x.ruleName == terminal);

            if (isExist)
            {
                GuideSet additionSet     = guideSet.Find(x => x.ruleName == terminal);
                int      additionSetSize = additionSet.set.Count();

                for (int j = 0; j < additionSetSize; j++)
                {
                    if (additionSet.set[j] == END)
                    {
                        isNeedToCheckNextSymbol = true;
                    }

                    AddNotTerminalToList(additionSet.set[j], ref currSet);
                    AddNotTerminalToList(additionSet.set[j], ref guideSetForRule);
                }
            }
        }