Beispiel #1
0
        private bool CFGReduction(CFG cfg)
        {
            int transAmountStartCFG = cfg.ReturnTotalTransitionAmount();

            CFGReductionPhase1(cfg);
            CFGReductionPhase2(cfg);

            if (transAmountStartCFG != cfg.ReturnTotalTransitionAmount())
            {
                return(true);
            }
            return(false);
        }
Beispiel #2
0
        private bool SubstituteEmptyTransitions(CFG cfg)
        {
            int transAmountStartCFG = cfg.ReturnTotalTransitionAmount();

            foreach (KeyValuePair <string, CFGVariable> epsilonVariable in cfg.AllTransitions)
            {
                List <List <ILetterOrVariable> > pruneList   = new List <List <ILetterOrVariable> >();
                List <List <ILetterOrVariable> > transitions = epsilonVariable.Value.ToVariablesOrLetters;
                bool blockDeletion = false;
                int  startCount    = transitions.Count;
                for (int i = 0; i < startCount; i++)
                {
                    if (transitions[i].Count == 1 && transitions[i][0].ToString().Equals("_"))
                    {
                        pruneList.Add(transitions[i]);
                        foreach (KeyValuePair <string, CFGVariable> variable in cfg.AllTransitions)
                        {
                            List <List <ILetterOrVariable> > addList = new List <List <ILetterOrVariable> >();
                            foreach (List <ILetterOrVariable> transition in variable.Value.ToVariablesOrLetters)
                            {
                                if (transition.Contains(epsilonVariable.Value))
                                {
                                    if (variable.Value == epsilonVariable.Value)
                                    {
                                        blockDeletion = true;
                                    }
                                    addList.AddRange(CreateNewEpsilonTransitions(transition, epsilonVariable.Value, cfg));
                                }
                            }
                            variable.Value.ToVariablesOrLetters.AddRange(addList);
                        }
                    }
                }
                foreach (List <ILetterOrVariable> prune in pruneList)
                {
                    if (!blockDeletion)
                    {
                        epsilonVariable.Value.ToVariablesOrLetters.Remove(prune);
                    }
                }
            }
            CleanCFG(cfg);
            int newAMount = cfg.ReturnTotalTransitionAmount();

            if (transAmountStartCFG != cfg.ReturnTotalTransitionAmount())
            {
                return(true);
            }
            return(false);
        }