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); }
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); } }