-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtm.cnt2
123 lines (88 loc) · 2.36 KB
/
tm.cnt2
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#n
# Accepts tape: binary number
# echo '101' | sed -rf tm.cnt2
# This source code is released under MIT License
# Copyright (c) 2016 Peter Cerman (https://github.com/pcerman)
/^>/ !s/^/>/
s/^/00:#/
b start
#---------------------------------------------------------------------
:S0
#---------------------------------------------------------------------
/>[01]/ { s/^..:/R00:/; b next }
/>#/ { s/^..:/L01:/; b next }
b error
#---------------------------------------------------------------------
:S1
#---------------------------------------------------------------------
/>1/ { s/>./>0/
s/^..:/R02:/; b next }
/>0/ { s/>./>1/
s/^..:/L01:/; b next }
b halt
#---------------------------------------------------------------------
:S2
#---------------------------------------------------------------------
/>[01]/ { s/^..:/R02:/; b next }
/>#/ { s/^..:/R03:/; b next }
b error
#---------------------------------------------------------------------
:S3
#---------------------------------------------------------------------
/>o/ { s/^..:/R03:/; b next }
/>#/ { s/>#/>o/
s/^..:/L04:/; b next }
b error
#---------------------------------------------------------------------
:S4
#---------------------------------------------------------------------
/>o/ { s/^..:/L04:/; b next }
/>#/ { s/^..:/L01:/; b next }
b error
#*********************************************************************
#*********************************************************************
:next
/^L.*[^:]>/ { s/^L//; s/(.)>/>\1/; b jump }
/^R.*>../ { s/^R//; s/>(.)/\1>/; b jump }
/^R.*>.$/ { s/^R//; s/>(.)/\1>#/; b jump }
/^R.*>$/ { s/^R//; s/>/#>#/; b jump }
s/^[LR]//
b error
#*********************************************************************
:start
:jump
h;s/>.*/>/;s/[^>]/ /g;s/>/_/;p;g;s/>//;p;g
/^00:/ b S0
/^01:/ b S1
/^02:/ b S2
/^03:/ b S3
/^04:/ b S4
#/^05:/ b S5
#/^06:/ b S6
#/^07:/ b S7
#/^08:/ b S8
#/^09:/ b S9
#/^10:/ b S10
i \
s/^/UNKNOWN STATE: /
p
q 3
#*********************************************************************
:break
i\
s/^/BREAK: /
p
q 2
#*********************************************************************
:error
i \
s/.*/NOT ACCEPTED/
p
q 1
#*********************************************************************
:halt
h;s/[^>]/ /g;s/>/_/;p;g;s/>//;p;g
s/.*/ACCEPTED/
i \
p
q 0