Exemplo n.º 1
0
        public PDAConfig GoChar(PDAConfig pcfg) {
            PDATransformKey qStart;

            //if word is empty, maybe only e-Transform is needed
            if (!string.IsNullOrEmpty(pcfg.word))
                qStart = new PDATransformKey(pcfg.State, pcfg.word[0], pcfg.Stack[^1]);
Exemplo n.º 2
0
        public override bool AcceptWord(string w)
        {
            CheckWordInAlphabet(w);

            int runCount = 0;

            //construct start config
            System.Collections.Generic.IList <PDAConfig> pcfgs;
            if (StartSymbol.HasValue)
            {
                pcfgs = new PDAConfig[] { new PDAConfig(StartState, w, new char[] { StartSymbol.Value }, null) }
            }
            ;
            else
            {
                pcfgs = new PDAConfig[] { new PDAConfig(StartState, w, new char[] { }, null) }
            };

            int HackCounter = 0;

            //while any pcfg exists
            while (pcfgs.Any())
            {
                if (pcfgs.Where(p => p.Stack.Count() == 0 && p.word.Length == 0).Any())
                {
                    return(true);
                }


                pcfgs = GoChar(pcfgs.ToArray());

                // hack!
                if (pcfgs.Count > MAX_RUNS_OR_STACK || runCount > MAX_RUNS_OR_STACK)
                {
                    var pcfgsGood = new System.Collections.Generic.List <PDAConfig>();
                    foreach (var pcfg in pcfgs)
                    {
                        if (pcfg.word.Length < w.Length - HackCounter)
                        {
                            pcfgsGood.Add(pcfg);
                        }
                    }

                    HackCounter++;

                    if (!pcfgsGood.Any() || runCount > MAX_RUNS_OR_STACK)
                    {
                        return(false);
                    }
                    else
                    {
                        Utils.DebugMessage($"overrite PCFGs #{pcfgs.Count}->{pcfgsGood.Count}", this, Uni.Utils.eDebugLogLevel.Verbose);
                        pcfgs = pcfgsGood.ToArray();
                        // throw new PDAStackException($"{runCount}: Stack >= {pcfgs.Length}, abort", this);
                    }
                }

                runCount++;
            }

            return(false);
        }