A fast turing machine simulator with graphviz export functionality
git clone https://git.8pit.net/tmsim.git
1# Input: A binary number. 2# Accepts the following input: { w + reverse(w) | w ∈ {0, 1}^+ } 3 4start: q1; 5accept: q9; 6 7# Move to the end of the tape. As soon as we reached a blank character 8# indicating the end of the tape move left and switch to state q2. 9q1 {10 1 > 1 => q1;11 0 > 0 => q1;1213 $ < $ => q2;14 a < a => q2;15 b < b => q2;16}1718# The purpose of this state is to check the last input symbol on the19# tape. If it is a '0' the symbol is replaced with 'a' if it is a '1' it20# is replaced with 'b'. After the symbol has been replaced the machine21# moves back to the beginning of the tape and does the same thing with22# the first input symbol on the tape. If the first input symbol on the23# tape is not equal to the one encountered at the end the input is24# rejected.25#26# If the last character isn't an input symbol (meaning it's an 'a'27# or 'b') the machine switches to state q7 and verifies that the tape28# consists only of 'a' and 'b' characters.29q2 {30 a | a => q7;31 b | b => q7;3233 0 < a => q3;34 1 < b => q5;35}3637##38# Replacing a 0.39##4041q3 {42 0 < 0 => q3;43 1 < 1 => q3;4445 $ > $ => q4;46 a > a => q4;47 b > b => q4;48}4950q4 {51 0 > a => q1;52}5354##55# Replacing a 1.56##5758q5 {59 0 < 0 => q5;60 1 < 1 => q5;6162 $ > $ => q6;63 a > a => q6;64 b > b => q6;65}6667q6 {68 1 > b => q1;69}7071##72# Verifying the tape content.73##7475# Move to the beginning of the tape and switch to state q8 as soon as76# the first blank character on the left hand side has been encountered.77q7 {78 0 < 0 => q7;79 1 < 1 => q7;80 a < a => q7;81 b < b => q7;82 $ > $ => q8;83}8485# Move to the end of the tape again. If a character is encountered that86# is not an 'a' or a 'b', before the end of the tape is reached, the input87# is rejected.88q8 {89 a > a => q8;90 b > b => q8;91 $ | $ => q9;92}