void initiateRules() { bool start = false; string finalState = "F"; MachineRule mr; List <string> set_state = new List <string>(); List <string> alphabets; List <string> tape = new List <string>(); List <MachineRule> machine_rules = new List <MachineRule>(); List <string> start_state = new List <string>(); List <string> accept_state = new List <string>(); List <string> halt_state = new List <string>(); List <string> reject_state = new List <string>(); accept_state.Add(finalState); halt_state.Add(finalState); List <string> alphabetsReadWrite = new List <string>(); tape.Add("~"); for (int i = 1; program.Length > i; i++) { switch (i % lastChar) { case 1: state = program[i].ToString(); if (!start) { start = true; //start_state[i - 1] = state; start_state.Add(state); set_state.Add(state); prevState = state; } if (prevState != state) { //set_state[l] = prevState; //l++; set_state.Add(state); reject_state.Add(state); //if (state == "F") //{ // //reject_state[k] = state; // //k++; // reject_state.Add(state); //} } //if (!(program.Length > i++)) //{ // accept_state[j] = state; // halt_state[j] = state; // j++; //} //else break; case 3: readSymbol = program[i].ToString(); alphabetsReadWrite.Add(readSymbol); //m++; break; case 5: nextState = program[i].ToString(); break; case 7: nextSymbol = program[i].ToString(); //alphabetsReadWrite[m] = readSymbol; //m++; alphabetsReadWrite.Add(readSymbol); break; case 9: if (Convert.ToChar(program[i].ToString()) == '<') { direction = "L"; } else { direction = "R"; } mr = new MachineRule(state, readSymbol, nextSymbol, direction, nextState); machine_rules.Add(mr); prevState = state; break; } } set_state.Add(finalState); alphabets = alphabetsReadWrite; alphabets.Distinct().ToArray(); MachineTuple machineTuple = new MachineTuple( set_state.ToArray(), alphabets.ToArray(), tape.ToArray(), machine_rules, start_state.ToArray(), accept_state.ToArray(), halt_state.ToArray(), reject_state.ToArray()); mainMachine = new Machine("Machine", machineTuple, "Language"); }
public Machine(string machine_name, MachineTuple machine_tuple, string machine_language) { machineName = machine_name; machineTuple = machine_tuple; machineLanguage = machine_language; }