public bool CheckInput(string input) { input += "$"; if (!DeterministicCheck()) { return(false); } Stack <char> _stack = new Stack <char>(); _stack.Push('λ'); _stack.Push('z'); DState current = _start; for (int i = 0; i < input.Length; i++) { if (current == null) { return(false); } char inputChar = input[i]; List <TagFormat> tagFormats = null; tagFormats = current.GetTags(inputChar); if (tagFormats == null) { var list = current.GetTags('λ'); if (list != null) { i--; tagFormats = list; } } if (tagFormats == null) { return(false); } foreach (var currentTagFormat in tagFormats.Where(t => t.machine == _stack.Peek())) { if (_stack.Peek() != 'λ') { _stack.Pop(); } PushToStack(_stack, currentTagFormat); current = current.GetNextState(currentTagFormat.GetAllTogether()); break; } } return(current.IsFinal()); }
private IEnumerator DoCheck(string input, Turing turing) { bool result = false; bool isHalt = false; if (!turing.DeterministicCheck()) { isHalt = true; } DState current = turing.GetStartState(); StringBuilder tape = new StringBuilder(input); int head = 0; while (!isHalt) { if (head >= tape.Length || head < 0) { if (head < 0) { head = 0; } tape.Insert(head, '□'); } var next = turing.GetNextState(current, tape[head]); if (next == null) { isHalt = true; result = current.IsFinal(); } else { var tagFormat = current.GetTags(tape[head])[0]; tape[head] = tagFormat.machine; head += tagFormat.machineCommand.ToLower().Contains("r") ? +1 : -1; current = next; } yield return(null); } turing.IsAnswerReady = true; turing.Result = result; _checking = null; }
public bool CheckInput(string inp) { if (DeterministicCheck() == false) { return(false); //DFA needs a Start and must be deterministic depends on alphabet } DState current = _start; for (int i = 0; i < inp.Length; i++) { if (current == null) { Debug.Log("Current Dosent exitst during InputCheck calculation"); return(false); } current = current.GetNextState(inp[i].ToString()); } if (current == null) { return(false); } return(current.IsFinal()); }