-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.tur
More file actions
41 lines (30 loc) · 825 Bytes
/
main.tur
File metadata and controls
41 lines (30 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
; This script come from : https://morphett.info/turing/turing.html.
; This example program checks if the input string is a binary palindrome.
; Input: a string of 0's and 1's, eg '1001001'
; Machine starts in state 0.
; State 0: read the leftmost symbol
0 0 _ r 1o
0 1 _ r 1i
0 _ _ * accept ; Empty input
; State 1o, 1i: find the rightmost symbol
1o _ _ l 2o
1o * * r 1o
1i _ _ l 2i
1i * * r 1i
; State 2o, 2i: check if the rightmost symbol matches the most recently read left-hand symbol
2o 0 _ l 3
2o _ _ * accept
2o * * * reject
2i 1 _ l 3
2i _ _ * accept
2i * * * reject
; State 3, 4: return to left end of remaining input
3 _ _ * accept
3 * * l 4
4 * * l 4
4 _ _ r 0 ; Back to the beginning
accept * : r accept2
accept2 * ) * halt-accept
reject _ : r reject2
reject * _ l reject
reject2 * ( * halt-reject