public string Run(string input) { int cursor = 0; TuringBrokerStepResult stepresult = new TuringBrokerStepResult(null, '\0', Transition.Right); do { try { stepresult = Step(input[cursor], stepresult.Destination); if (stepresult == null) { break; } input = input.Remove(cursor, 1); input = input.Insert(cursor, stepresult.ReplaceBy.ToString()); if (stepresult.Destination == null) { return(input); } input = stepresult.Destination.RunVertex(input); if (stepresult.To == Transition.Right) { cursor++; if (cursor >= input.Length) { input += "#"; } } else if (stepresult.To == Transition.Left) { cursor--; if (cursor < 0) { input = '#' + input; cursor = 0; } } } catch (Exception ex) { return(""); } } while (stepresult.Destination != null); return(input); }
public TuringBrokerStepResult Step(char condition, Vertex sourcevertex) { if (!Initialized) { throw new InvalidOperationException("Broker should be initialized first"); } if (sourcevertex == null) { return(new TuringBrokerStepResult(GetStartState(), condition, Transition.None)); } foreach (Edge <TuringCondition> e in ContainingMachine.Edges) { TuringBrokerStepResult ConditionResult = ConditionCheckOutput(e, condition); if (e.Source == sourcevertex && (ConditionResult.Destination != null)) { return(ConditionResult); } } return(null); }
async void RunMachineStep(string input) { int cursor = 0; TuringMachineBroker broker = new TuringMachineBroker(ContainingMachine); try { broker.InitializeMachine(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } TuringBrokerStepResult stepresult = new TuringBrokerStepResult(null, '\0', Transition.Right); do { try { await TapeControl.ScrollToItem(cursor, true); stepresult = broker.Step(input[cursor], stepresult.Destination); if (stepresult == null) { return; } await Task.Delay(500); input = input.Remove(cursor, 1); input = input.Insert(cursor, stepresult.ReplaceBy.ToString()); input = stepresult.Destination.RunVertex(input); TapeControl.ChangeInput(input); if (stepresult.To == Transition.Right) { cursor++; if (cursor >= input.Length) { input += "#"; } } else if (stepresult.To == Transition.Left) { cursor--; if (cursor < 0) { input = "#" + input; cursor = 0; await TapeControl.ScrollToItem(1, false); } } stepresult.Destination.InvokeActivation(); } catch (Exception ex) { //SetNotificationText("Error: " + ex.Message); return; } } while (stepresult.Destination != null); TapeControl.ChangeInput(input); }