public TuringInfo(string[][][] tab, string[] alph, string[] stat, string[] comm) { this._table = tab; this._alphabet = alph; this._comments = comm; this._states = stat; codes = TuringToPost.Encode(alph); // кодировка this._dicStates = new Dictionary <string, int>(); this.ImproveTable(); // заменяем все символы замены стоп клеток на символ алфавита соответствующего столбца for (int i = 0; i < _states.Length; i++) { try { _dicStates.Add(_states[i], i); } catch { throw new ArgumentException("Команды с одинаковыми именами недопустимы"); } } }
public string[,] GeneratePostProgram() { TuringToPost t = new TuringToPost(codes[this.Alphabet[0]].Length); List <int> st = new List <int>(); // индексы состояний List <int> refern = new List <int>(); //индексы, в которые будем пихать отсылки int fir = this.Table.Length; // колв-о комманд (строк в таблице) int sec = this.Table[0].Length; // 3 по идее int thi = this.Table[0][0].Length; // кол-во столбцов for (int i = 0; i < fir; i++) // генерим программу без отсылок { st.Add(t.Prog.Count + 1); // добавляем индекс состояния for (int j = 0; j < thi; j++) { if (Table[i][0][j] == "" && Table[i][1][j] == "") { continue; // если состояние не описано } string alph = codes[Alphabet[j]], stt = codes[Table[i][0][j]], mover = Table[i][1][j]; int count = this.calcStLen(alph, stt, mover); // длина для неудачной отсылки // неверные отсылки, длину надо прибавлять к текущему состоянию t.Check(alph, t.Prog.Count + 3 * t.Length + 1, t.Prog.Count + count + 1); t.Replace(alph, stt); if (mover == "r") { t.MoveRight(); } else if (mover == "l") { t.MoveLeft(); } else if (mover == "halt") { t.Stop(); } refern.Add(t.Prog.Count - 1); } } t.Stop(); // остановка в конце по сут не нужна, но последняя отсылка указывает на несуществующую команду for (int i = 0, k = 0; i < fir; i++) // генерим отсылки { for (int j = 0; j < thi; j++) { if (this.Table[i][2][j] == "") { continue; } int statind = this.DicStates[this.Table[i][2][j]]; int what = refern[k++]; int where = st[statind]; if (t.Prog[what][0] != PostCommands.Stop) { t.Prog[what][1] = where.ToString(); } } } string[,] outst = new string[t.Prog.Count, t.Prog[0].Length]; for (int i = 0; i < outst.GetLength(0); i++) { for (int j = 0; j < outst.GetLength(1); j++) { outst[i, j] = t.Prog[i][j]; } } return(outst); }