Exemplo n.º 1
0
        public override bool AcceptWord(string w)
        {
            CheckWordInAlphabet(w);

            var tcfg = new TuringConfigSingleBand(BlankSymbol, w, 0)
            {
                State = StartState
            };
            int  runs  = 0;
            uint lastQ = tcfg.State;

            while (tcfg != null)
            {
                Utils.DebugMessage(tcfg.ToString(), this, Uni.Utils.eDebugLogLevel.Verbose);
                tcfg = GoChar(tcfg);
                if (tcfg != null)
                {
                    lastQ = tcfg.State;
                }
                if (runs > MAX_TURING_RUNS)
                {
                    throw new TuringCycleException($"possible Turing cycle at {runs} with {w} now is: {tcfg.Band.Trim(BlankSymbol)}", this);
                }
                runs++;
                if (IsAcceptedState(lastQ))
                {
                    return(true);
                }
                else if (DiscardState == lastQ)
                {
                    return(false);
                }
            }
            return(false);
        }
Exemplo n.º 2
0
 TuringConfigSingleBand GoChar(TuringConfigSingleBand tcfg)
 {
     if (Transforms.TryGetValue(new TuringKey(tcfg.State, tcfg.CurSymbol), out TuringVal tva))
     {
         tcfg.ReplaceChar(tva.c2, tva.Direction);
         tcfg.State = tva.qNext;
         return(tcfg);
     }
     else
     {
         return(null);
     }
 }
Exemplo n.º 3
0
        public bool AcceptWord(string w, TuringAcceptance acceptance)
        {
            CheckWordInAlphabet(w);

            var tcfg = new TuringConfigSingleBand(BlankSymbol, w, 0)
            {
                State = StartState
            };

            int  runs  = 0;
            uint lastQ = tcfg.State;

            while (tcfg != null && (
                       (!(acceptance.HasFlag(TuringAcceptance.AcceptedState) && IsAcceptedState(lastQ) && tcfg.CleanBand() == "")) ||
                       (!(acceptance.HasFlag(TuringAcceptance.wordConsumed) && tcfg.CleanBand() == "")) ||
                       (!(tcfg != null && (acceptance.HasFlag(TuringAcceptance.Hold))))))
            {
                Utils.DebugMessage(tcfg.ToString(), this, Uni.Utils.eDebugLogLevel.Verbose);
                tcfg = GoChar(tcfg);
                if (tcfg != null)
                {
                    lastQ = tcfg.State;
                }
                if (runs > MAX_TURING_RUNS)
                {
                    throw new TuringCycleException($"possible Turing cycle at {runs} with {w} now is: {tcfg.Band.Trim(BlankSymbol)}", this);
                }
                runs++;
            }

            if (acceptance.HasFlag(TuringAcceptance.AcceptedState) && IsAcceptedState(lastQ) && (tcfg == null || tcfg.CleanBand() == ""))
            {
                return(true);
            }
            else if (tcfg != null && (acceptance.HasFlag(TuringAcceptance.wordConsumed) && tcfg.CleanBand() == ""))
            {
                return(true);
            }
            else if (tcfg != null && (acceptance.HasFlag(TuringAcceptance.Hold)))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 4
0
        public override string GetBandOutput(string w)
        {
            var    tcfg     = new TuringConfigSingleBand(BlankSymbol, w, 0);
            int    runs     = 0;
            string lastBand = tcfg.Band;

            while (tcfg != null && !IsAcceptedState(tcfg.State))
            {
                tcfg = GoChar(tcfg);
                if (tcfg != null)
                {
                    lastBand = tcfg.Band;
                }
                if (runs > MAX_TURING_RUNS)
                {
                    throw new TuringCycleException($"possible Turing cycle at {runs} with {w} now is: {tcfg.Band.Trim(BlankSymbol)}", this);
                }
                runs++;
            }
            return(lastBand.Trim(BlankSymbol));
        }