tmsim

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;
12
13	$ < $ => q2;
14	a < a => q2;
15	b < b => q2;
16}
17
18# The purpose of this state is to check the last input symbol on the
19# tape. If it is a '0' the symbol is replaced with 'a' if it is a '1' it
20# is replaced with 'b'. After the symbol has been replaced the machine
21# moves back to the beginning of the tape and does the same thing with
22# the first input symbol on the tape. If the first input symbol on the
23# tape is not equal to the one encountered at the end the input is
24# 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 tape
28# consists only of 'a' and 'b' characters.
29q2 {
30	a | a => q7;
31	b | b => q7;
32
33	0 < a => q3;
34	1 < b => q5;
35}
36
37##
38# Replacing a 0.
39##
40
41q3 {
42	0 < 0 => q3;
43	1 < 1 => q3;
44
45	$ > $ => q4;
46	a > a => q4;
47	b > b => q4;
48}
49
50q4 {
51	0 > a => q1;
52}
53
54##
55# Replacing a 1.
56##
57
58q5 {
59	0 < 0 => q5;
60	1 < 1 => q5;
61
62	$ > $ => q6;
63	a > a => q6;
64	b > b => q6;
65}
66
67q6 {
68	1 > b => q1;
69}
70
71##
72# Verifying the tape content.
73##
74
75# Move to the beginning of the tape and switch to state q8 as soon as
76# 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}
84
85# Move to the end of the tape again. If a character is encountered that
86# is not an 'a' or a 'b', before the end of the tape is reached, the input
87# is rejected.
88q8 {
89	a > a => q8;
90	b > b => q8;
91	$ | $ => q9;
92}