SEATC 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/Turing Analyzer +4 -0
- data/lib/Grammar Reader.rb +4 -5
- data/lib/Regular Expression.rb +5 -0
- data/lib/Turing Analyzer.rb +254 -0
- data/lib/Turing Reader.rb +10 -0
- data/samples/Regular Expression.jff +1 -1
- data/samples/Turing Machine.jff +70 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9df31347e1f612c2d056fe05ec5cdac6c77e0c2
|
4
|
+
data.tar.gz: d778061e15ef7df2dc031848cba31e8e8ca26826
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 292b192c4599f64afe0182c8315d63e5febfc9cd37a713b8752e63dfc9916c7fa673113b29d6f5b0f6d098817dd4758f3e7774645d9db83197790460e6bf8b14
|
7
|
+
data.tar.gz: 551e165f54254e76219fc3a75cc9a0a50f2490f4d907caf6457a6b5659f23d7b02742dc2337184a0e6c6a40dc3a3192b466ce5cf33be4c40253848134fc22d1f
|
data/bin/Turing Analyzer
ADDED
data/lib/Grammar Reader.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
SYNTAX_ERROR = 1
|
2
|
-
PRODUCTION_ERROR = 2
|
3
|
-
|
4
1
|
class GrammarReader
|
5
|
-
|
2
|
+
SYNTAX_ERROR = 1
|
3
|
+
PRODUCTION_ERROR = 2
|
4
|
+
attr_accessor :error
|
6
5
|
|
7
6
|
def initialize()
|
8
7
|
@error = 0
|
@@ -34,7 +33,7 @@ class GrammarReader
|
|
34
33
|
#returns the Hash containing the productions
|
35
34
|
def createProductions(lines)
|
36
35
|
productions = Hash.new
|
37
|
-
if !lines[0].include? "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><!--Created with JFLAP
|
36
|
+
if !lines[0].include? "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><!--Created with JFLAP"
|
38
37
|
@error = SYNTAX_ERROR
|
39
38
|
return productions
|
40
39
|
end
|
data/lib/Regular Expression.rb
CHANGED
@@ -16,6 +16,11 @@ class RegularExpression
|
|
16
16
|
end
|
17
17
|
regex = lines[3]
|
18
18
|
regex.slice! "\t<expression>"
|
19
|
+
if regex.match " "
|
20
|
+
regex.reverse!
|
21
|
+
regex.slice! " ".reverse
|
22
|
+
regex.reverse!
|
23
|
+
end
|
19
24
|
regex.reverse!
|
20
25
|
regex.slice! "</expression>".reverse
|
21
26
|
regex.reverse!
|
@@ -0,0 +1,254 @@
|
|
1
|
+
require 'thread'
|
2
|
+
load 'Turing Reader.rb'
|
3
|
+
class TuringState
|
4
|
+
attr_accessor :tag, :id, :name, :initial, :final, :transitions
|
5
|
+
def initialize
|
6
|
+
@transitions = Hash.new
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class TuringTransition
|
11
|
+
attr_accessor :to, :write, :move
|
12
|
+
end
|
13
|
+
|
14
|
+
class TuringAnalyzer
|
15
|
+
attr_accessor :reader, :lines, :states, :valid
|
16
|
+
@initial
|
17
|
+
def initialize
|
18
|
+
@reader = TuringReader.new
|
19
|
+
@states = Array.new
|
20
|
+
@initial = nil
|
21
|
+
@valid = false
|
22
|
+
end
|
23
|
+
|
24
|
+
def analyze file, line
|
25
|
+
@lines = @reader.readFile file
|
26
|
+
puts "Valid" if validateJFlap
|
27
|
+
deleteLine
|
28
|
+
puts "Valid" if validateTuringMachine
|
29
|
+
deleteLine
|
30
|
+
createStates
|
31
|
+
position = 0
|
32
|
+
until line[position] != "B"
|
33
|
+
position = position + 1
|
34
|
+
end
|
35
|
+
validate line, @initial, position
|
36
|
+
return @valid
|
37
|
+
end
|
38
|
+
|
39
|
+
def validateJFlap
|
40
|
+
return true if @lines[0].match "JFLAP"
|
41
|
+
return false
|
42
|
+
end
|
43
|
+
|
44
|
+
def validateTuringMachine
|
45
|
+
return true if @lines[0].match "turing"
|
46
|
+
return false
|
47
|
+
end
|
48
|
+
|
49
|
+
def createStates
|
50
|
+
return false if !lines[0].match "automaton"
|
51
|
+
deleteLine
|
52
|
+
if lines[0].match "<!--The list of states.-->"
|
53
|
+
deleteLine
|
54
|
+
else
|
55
|
+
return false
|
56
|
+
end
|
57
|
+
while createState
|
58
|
+
end
|
59
|
+
if lines[0].match "<!--The list of transitions.-->"
|
60
|
+
deleteLine
|
61
|
+
else
|
62
|
+
return false
|
63
|
+
end
|
64
|
+
until createTransition == false
|
65
|
+
end
|
66
|
+
puts @states.to_s
|
67
|
+
end
|
68
|
+
|
69
|
+
def createState
|
70
|
+
state = TuringState.new
|
71
|
+
return false if !lines[0].match "block"
|
72
|
+
deleteTabs
|
73
|
+
lines[0].slice! "<block "
|
74
|
+
# Create id
|
75
|
+
state.id = 0
|
76
|
+
lines[0].slice! "id=\""
|
77
|
+
until lines[0][0] == "\""
|
78
|
+
state.id = state.id * 10
|
79
|
+
state.id = state.id + lines[0][0].to_i
|
80
|
+
lines[0].slice! lines[0][0]
|
81
|
+
end
|
82
|
+
lines[0].slice! "\" "
|
83
|
+
# Create name
|
84
|
+
state.name = ""
|
85
|
+
lines[0].slice! "name=\""
|
86
|
+
until lines[0][0] == "\""
|
87
|
+
state.name = state.name + lines[0][0]
|
88
|
+
lines[0].slice! lines[0][0]
|
89
|
+
end
|
90
|
+
deleteLine
|
91
|
+
# Tags
|
92
|
+
return false if !lines[0].match "tag"
|
93
|
+
deleteLine
|
94
|
+
# X position
|
95
|
+
deleteLine
|
96
|
+
# Y position
|
97
|
+
deleteLine
|
98
|
+
# Initial?
|
99
|
+
state.initial = false
|
100
|
+
if lines[0].match "initial"
|
101
|
+
@initial = state.id if @initial == nil
|
102
|
+
state.initial = true
|
103
|
+
deleteLine
|
104
|
+
end
|
105
|
+
# Final?
|
106
|
+
state.final = false
|
107
|
+
if lines[0].match "final"
|
108
|
+
state.final = true
|
109
|
+
deleteLine
|
110
|
+
end
|
111
|
+
# Check closing bracket
|
112
|
+
return false if !lines[0].match "</block>"
|
113
|
+
deleteLine
|
114
|
+
@states[state.id] = state
|
115
|
+
return true
|
116
|
+
end
|
117
|
+
|
118
|
+
def createTransition
|
119
|
+
from = 0
|
120
|
+
to = 0
|
121
|
+
if lines[0].match "<transition>"
|
122
|
+
deleteLine
|
123
|
+
else
|
124
|
+
return false
|
125
|
+
end
|
126
|
+
# From
|
127
|
+
deleteTabs
|
128
|
+
lines[0].slice! "<from>"
|
129
|
+
until lines[0][0] == "<"
|
130
|
+
from = from * 10
|
131
|
+
from = from + lines[0][0].to_i
|
132
|
+
lines[0].slice! lines[0][0]
|
133
|
+
end
|
134
|
+
deleteLine
|
135
|
+
# To
|
136
|
+
deleteTabs
|
137
|
+
lines[0].slice! "<to>"
|
138
|
+
until lines[0][0] == "<"
|
139
|
+
to = to * 10
|
140
|
+
to = to + lines[0][0].to_i
|
141
|
+
lines[0].slice! lines[0][0]
|
142
|
+
end
|
143
|
+
deleteLine
|
144
|
+
# Read
|
145
|
+
if lines[0].match "<read/>"
|
146
|
+
read = nil
|
147
|
+
else
|
148
|
+
deleteTabs
|
149
|
+
read = 0
|
150
|
+
lines[0].slice! "<read>"
|
151
|
+
until lines[0][0] == "<"
|
152
|
+
read = read * 10
|
153
|
+
read = read + lines[0][0].to_i
|
154
|
+
lines[0].slice! lines[0][0]
|
155
|
+
end
|
156
|
+
end
|
157
|
+
deleteLine
|
158
|
+
# Write
|
159
|
+
if lines[0].match "<write/>"
|
160
|
+
write = nil
|
161
|
+
else
|
162
|
+
deleteTabs
|
163
|
+
write = 0
|
164
|
+
lines[0].slice! "<write>"
|
165
|
+
until lines[0][0] == "<"
|
166
|
+
write = write * 10
|
167
|
+
write = write + lines[0][0].to_i
|
168
|
+
lines[0].slice! lines[0][0]
|
169
|
+
end
|
170
|
+
end
|
171
|
+
deleteLine
|
172
|
+
if lines[0].match "<move>R"
|
173
|
+
move = "R"
|
174
|
+
elsif lines[0].match "<move>L"
|
175
|
+
move = "L"
|
176
|
+
elsif lines[0].match "<move>S"
|
177
|
+
move = "S"
|
178
|
+
else
|
179
|
+
move = nil
|
180
|
+
end
|
181
|
+
if @states[from].transitions[read] == nil
|
182
|
+
@states[from].transitions[read] = Array.new
|
183
|
+
end
|
184
|
+
trans = TuringTransition.new
|
185
|
+
trans.to = to
|
186
|
+
trans.write = write
|
187
|
+
trans.move = move
|
188
|
+
@states[from].transitions[read].push trans
|
189
|
+
deleteLine
|
190
|
+
if lines[0].match "</transition>"
|
191
|
+
deleteLine
|
192
|
+
return true
|
193
|
+
end
|
194
|
+
return false
|
195
|
+
end
|
196
|
+
|
197
|
+
def deleteLine
|
198
|
+
size = @lines.size
|
199
|
+
newLines = Array.new
|
200
|
+
for i in 0...size-1
|
201
|
+
newLines[i] = @lines[i+1]
|
202
|
+
end
|
203
|
+
@lines = newLines
|
204
|
+
end
|
205
|
+
|
206
|
+
def deleteTabs
|
207
|
+
until !lines[0].match "\t"
|
208
|
+
lines[0].slice! "\t"
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
def validate line, actual, position
|
213
|
+
transitions = @states[actual].transitions
|
214
|
+
# Launch no read transition
|
215
|
+
read = line[position]
|
216
|
+
if transitions[nil] != nil
|
217
|
+
transitions[nil].each do |trans|
|
218
|
+
if read == "B"
|
219
|
+
if trans.write == nil
|
220
|
+
line[position] = "B"
|
221
|
+
else
|
222
|
+
line[position] = trans.write
|
223
|
+
end
|
224
|
+
newPos = position - 1 if trans.move == "L"
|
225
|
+
newPos = position + 1 if trans.move == "R"
|
226
|
+
newPos = position if trans.move == "S"
|
227
|
+
nilThread = Thread.new { validate(line, trans.to, newPos)}
|
228
|
+
nilThread.join
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
# Launch read transition / End if no transition
|
233
|
+
read = line[position]
|
234
|
+
if transitions[read] == nil
|
235
|
+
if @valid == false && @states[actual].final == true
|
236
|
+
@valid = true
|
237
|
+
end
|
238
|
+
else
|
239
|
+
transitions[read].each do |trans|
|
240
|
+
if trans.write == nil
|
241
|
+
line[position] = "B"
|
242
|
+
else
|
243
|
+
line[position] = trans.write
|
244
|
+
end
|
245
|
+
newPos = position - 1 if trans.move == "L"
|
246
|
+
newPos = position + 1 if trans.move == "R"
|
247
|
+
newPos = position if trans.move == "S"
|
248
|
+
thread = Thread.new { validate(line, trans.to, newPos)}
|
249
|
+
thread.join
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!--Created with JFLAP 6.4.--><structure>
|
2
|
+
<type>turing</type>
|
3
|
+
<automaton>
|
4
|
+
<!--The list of states.-->
|
5
|
+
<block id="0" name="q0">
|
6
|
+
<tag>Machine0</tag>
|
7
|
+
<x>60.0</x>
|
8
|
+
<y>177.0</y>
|
9
|
+
<initial/>
|
10
|
+
</block>
|
11
|
+
<block id="1" name="q1">
|
12
|
+
<tag>Machine1</tag>
|
13
|
+
<x>185.0</x>
|
14
|
+
<y>75.0</y>
|
15
|
+
</block>
|
16
|
+
<block id="2" name="q2">
|
17
|
+
<tag>Machine2</tag>
|
18
|
+
<x>306.0</x>
|
19
|
+
<y>183.0</y>
|
20
|
+
<final/>
|
21
|
+
</block>
|
22
|
+
<!--The list of transitions.-->
|
23
|
+
<transition>
|
24
|
+
<from>0</from>
|
25
|
+
<to>1</to>
|
26
|
+
<read/>
|
27
|
+
<write/>
|
28
|
+
<move>L</move>
|
29
|
+
</transition>
|
30
|
+
<transition>
|
31
|
+
<from>1</from>
|
32
|
+
<to>1</to>
|
33
|
+
<read>1</read>
|
34
|
+
<write>1</write>
|
35
|
+
<move>L</move>
|
36
|
+
</transition>
|
37
|
+
<transition>
|
38
|
+
<from>1</from>
|
39
|
+
<to>1</to>
|
40
|
+
<read>0</read>
|
41
|
+
<write>0</write>
|
42
|
+
<move>L</move>
|
43
|
+
</transition>
|
44
|
+
<transition>
|
45
|
+
<from>1</from>
|
46
|
+
<to>2</to>
|
47
|
+
<read/>
|
48
|
+
<write/>
|
49
|
+
<move>R</move>
|
50
|
+
</transition>
|
51
|
+
<transition>
|
52
|
+
<from>0</from>
|
53
|
+
<to>0</to>
|
54
|
+
<read>1</read>
|
55
|
+
<write>0</write>
|
56
|
+
<move>R</move>
|
57
|
+
</transition>
|
58
|
+
<transition>
|
59
|
+
<from>0</from>
|
60
|
+
<to>0</to>
|
61
|
+
<read>0</read>
|
62
|
+
<write>1</write>
|
63
|
+
<move>R</move>
|
64
|
+
</transition>
|
65
|
+
<!--The list of automata-->
|
66
|
+
<Machine0/>
|
67
|
+
<Machine2/>
|
68
|
+
<Machine1/>
|
69
|
+
</automaton>
|
70
|
+
</structure>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: SEATC
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Salvador Guerra Delgado
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A gem for development on SEATC, can be used for other system that requires
|
14
14
|
automaton and grammars analysis
|
@@ -24,18 +24,22 @@ files:
|
|
24
24
|
- bin/Pushdown Automaton
|
25
25
|
- bin/Regular Expression
|
26
26
|
- bin/Regular Grammar
|
27
|
+
- bin/Turing Analyzer
|
27
28
|
- lib/Automaton Analyzer.rb
|
28
29
|
- lib/Grammar Analyzer.rb
|
29
30
|
- lib/Grammar Reader.rb
|
30
31
|
- lib/PDA.rb
|
31
32
|
- lib/Regular Expression.rb
|
32
33
|
- lib/Regular Grammar Analyzer.rb
|
34
|
+
- lib/Turing Analyzer.rb
|
35
|
+
- lib/Turing Reader.rb
|
33
36
|
- samples/Deterministic Finite Automaton.jff
|
34
37
|
- samples/Finite Automaton.jff
|
35
38
|
- samples/Nondeterministic.jff
|
36
39
|
- samples/Pushdown.jff
|
37
40
|
- samples/Regular Expression.jff
|
38
41
|
- samples/Regular Grammar.jff
|
42
|
+
- samples/Turing Machine.jff
|
39
43
|
homepage: http://rubygems.org/gems/SEATC
|
40
44
|
licenses:
|
41
45
|
- MIT
|