Example #1
0
        private void CFGReductionPhase2(CFG cfg)
        {
            HashSet <ILetterOrVariable> allReachableTransitions = new HashSet <ILetterOrVariable>();

            allReachableTransitions.Add(cfg.StartVariable);
            int transitionLength = 0;

            while (transitionLength != allReachableTransitions.Count())
            {
                transitionLength = allReachableTransitions.Count();

                HashSet <ILetterOrVariable> allReachableTransitionsCopy = new HashSet <ILetterOrVariable>(allReachableTransitions);
                foreach (ILetterOrVariable reachableTransition in allReachableTransitionsCopy)
                {
                    if (reachableTransition.IsVariable())
                    {
                        foreach (List <ILetterOrVariable> varOrLetList in cfg.AllTransitions[reachableTransition.ToString()].ToVariablesOrLetters)
                        {
                            foreach (ILetterOrVariable varOrLet in varOrLetList)
                            {
                                allReachableTransitions.Add(varOrLet);
                            }
                        }
                    }
                }
            }

            cfg.PruneNotIncludedVariablesAndSymbol(allReachableTransitions);
        }