-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransition.java
More file actions
141 lines (120 loc) · 2.73 KB
/
Transition.java
File metadata and controls
141 lines (120 loc) · 2.73 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import java.util.*;
public class Transition extends Turing
{
String[] Q = {"q1","q2","q3","q4","q5","q6","q7","q8","qaccept"};
String state;
public Transition()
{
state = Q[0];
}
public String getState()
{
return state;
}
// WRITE SET OF METHODS DETERMINING WHAT TO WRITE / WHERE TO MOVE DEPENDING
// ON CURRENT STATE AND CURRENT HEAD
public void q1Toq3() // 1 is read at q1, write an 'x' and move R
{
write = "x";
move = "R";
state = Q[2]; // now in state q3
}
public void q1Toq2() // 0 is read at q1, write an 'x' and move R
{
write = "x";
move = "R";
state = Q[1]; // now in state q2
}
public void q3Toq3() // 0 or 1 read at q3, write nothing and move R
{
write = " ";
move = "R";
// no change in state, stays at q3
}
public void q2Toq2() // 0 or 1 read at q2, write nothing and move R
{
write = " ";
move = "R";
// no change in state, stays at q2
}
public void q3Toq5() // # read at q3, write nothing and move R
{
write = " ";
move = "R";
state = Q[4]; // now in state q5
}
public void q2Toq4() // # read at q2, write nothing and move R
{
write = " ";
move = "R";
state = Q[3]; // now in state q4
}
public void q5Toq5() // x read at q5, write nothing and move R
{
write = " ";
move = "R";
// no change in state, stays at q5
}
public void q4Toq4() // x read at q4, write nothing and move R
{
write = " ";
move = "R";
// no change in state, stays at q4
}
public void q5Toq6() // 1 read at q5, write an 'x' and move L
{
write = "x";
move = "L";
state = Q[5]; // now in state q6
}
public void q4Toq6() // 0 read at q4, write an 'x' and move L
{
write = "x";
move = "L";
state = Q[5]; // now in state q6
}
public void q6Toq6() // 0,1 or x read at q6, write nothing and move L
{
write = " ";
move = "L";
// no change in state, stays at q6
}
public void q6Toq7() // # read at q6, write nothing and move L
{
write = " ";
move = "L";
state = Q[6]; // now in state q7
}
public void q7Toq7() // 0 or 1 read at q7, write nothing and move L
{
write = " ";
move = "L";
// no change in state, stays at q7
}
public void q7Toq1() // x read at q7, write nothing and move R
{
write = " ";
move = "R";
state = Q[0]; // goes back to state q1
}
public void q1Toq8() // # read at q1, write nothing and move R
{
write = " ";
move = "R";
state = Q[7]; // now in state q8
}
public void q8Toq8() // x read at q8, write nothing and move R
{
write = " ";
move = "R";
// no change in state, stays at q8
}
public void q8Toqaccept() // _ read at q8, write nothing and move R
{
write = " ";
move = "R";
state = Q[Q.length-1]; // reached final state, qaccept
accept = true;
//System.out.println("Accept!");
}
}