# PCASTLI version 2.7 run_machine = function(machine, string, pos) { state = machine.iota nb_trans = length(machine.delta) tape_len = length(string) i = pos while (1) { found_trans = 0 j = 0 while (!found_trans && j < nb_trans) { if (i == tape_len - 1) { tape_len++ setlength(string, tape_len) } if (state == machine.delta[j].init_state && string[i] == machine.delta[j].input_symbol[0]) { found_trans = 1 state = machine.delta[j].new_state if (state == machine.h) return("accepted") if (machine.delta[j].action == "L") { i-- if (i < 0) return("abnormal termination") } else if (machine.delta[j].action == "R") { i++ } else { string[i] = machine.delta[j].action } } j++ } if (!found_trans) return("refused") } }