SEATC 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e9f16975e2e451b7545fffa695b6c993433a391f0bb982c0b2e39a31e99febf7
4
+ data.tar.gz: b403cdc25b0710a485dcab81db6789d2f3739960d9bd808f16664d4862772c13
5
+ SHA512:
6
+ metadata.gz: c7f60542a5ad9957a90a31f0c4057ffd2fb1d94797faf61a17a20b863a2e50332dd21a28a585af13a9eabb3764df13a9c4559ac7b70c7cd4d395088ef644132c
7
+ data.tar.gz: 355e58cca02ba00444f03767b5324236520d0de081c3bfd3bea6228917702ed2c796ff8d2e568ebdf2765c870e875c6efad0c5e342cbd4d29284733f92789ed0
@@ -0,0 +1,8 @@
1
+ require 'rake/testtask'
2
+
3
+ Rake::TestTask.new do |t|
4
+ t.libs << 'test'
5
+ end
6
+
7
+ desc "Run tests"
8
+ task :default => :test
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'SEATC'
4
+ SEATC.analizeFiniteAutomatonFromString(argv[0], argv[1])
@@ -0,0 +1,249 @@
1
+ class State
2
+ @id
3
+ @nombre
4
+ @transitions
5
+ @final
6
+ def initialize(id, nombre, final)
7
+ @id = id
8
+ @nombre = nombre
9
+ @transitions = Hash.new
10
+ @final = final
11
+ end
12
+ def print()
13
+ puts "My ID is #{@id} and I am #{@nombre}"
14
+ end
15
+ def addTrans(char, to)
16
+ @transitions[char] = to
17
+ end
18
+ def transAt(char)
19
+ ret = @transitions[char]
20
+ end
21
+ def final()
22
+ ret = @final
23
+ end
24
+ end
25
+
26
+ class FiniteAutomatonAnalyzer
27
+ def self.getStateID(modified)
28
+ modified.slice! "\t\t<state id=\""
29
+ lastQuota = true
30
+ id = 0
31
+ while(lastQuota)
32
+ id = id * 10
33
+ char = modified[0]
34
+ modified.slice! modified[0]
35
+ lastQuota = (modified[0] != "\"")
36
+ id = id + char.to_i
37
+ end
38
+ id = id
39
+ end
40
+
41
+ def self.getStateName(modified)
42
+ modified.slice! "\" name=\""
43
+ lastQuota = true
44
+ id = ""
45
+ while(lastQuota)
46
+ id = id + modified[0]
47
+ modified.slice! modified[0]
48
+ lastQuota = (modified[0] != "\"")
49
+ end
50
+ id = id
51
+ end
52
+
53
+ def self.readTransInt(modified)
54
+ lastQuota = true
55
+ id = 0
56
+ while(lastQuota)
57
+ id = id * 10
58
+ char = modified[0]
59
+ modified.slice! modified[0]
60
+ lastQuota = (modified[0] != "<")
61
+ id = id + char.to_i
62
+ end
63
+ id = id
64
+
65
+ end
66
+
67
+ def self.validateString(initial, states, line)
68
+ st = initial
69
+ brokenLoop = false
70
+ while(line != "")
71
+ char = line[0]
72
+ line.slice! char
73
+ st = states[st].transAt(char)
74
+ if(st == nil)
75
+ brokenLoop = true
76
+ break
77
+ end
78
+ end
79
+ puts "Ending line is #{line}"
80
+ if(brokenLoop)
81
+ ret = false
82
+ else
83
+ if(states[st].final == 0)
84
+ ret = false
85
+ else
86
+ ret = true
87
+ end
88
+ end
89
+ end
90
+
91
+ #Returns true if the automaton ends in final state, returns false otherwise
92
+ def self.analizeFiniteAutomatonFromFile(sourceFile, testFile)
93
+ file = File.new(sourceFile, "r")
94
+ line = file.read
95
+ file.close
96
+ counter = 1
97
+ lines = line.split("\n")
98
+ for lin in lines
99
+ puts "#{counter}: #{lin}"
100
+ counter = counter + 1
101
+ end
102
+ if lines[0] != "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><!--Created with JFLAP 6.4.--><structure>&#13;"
103
+ puts "Not a JFLAP file"
104
+ end
105
+ # Check if finite automaton
106
+ puts lines[1]
107
+ if lines[1] == "\t<type>fa</type>&#13;"
108
+ puts "Finite automaton"
109
+ else
110
+ puts "Not a finite automaton"
111
+ end
112
+ states = []
113
+ counter = 4
114
+ i = 0
115
+ initialState = nil
116
+ modified = lines[counter]
117
+ while(modified.include? "state")
118
+ final = 0
119
+ aux = counter
120
+ id = getStateID(modified)
121
+ nombre = getStateName(modified)
122
+ puts "Modified string for state is ", modified
123
+ puts id
124
+ puts nombre
125
+ if(lines[counter + 3 ].include? "initial")
126
+ aux = aux + 1
127
+ initialState = id
128
+ end
129
+ if(lines[aux + 3].include? "final")
130
+ final = 1
131
+ aux = aux + 1
132
+ end
133
+ counter = aux + 4
134
+ modified = lines[counter]
135
+ states[id] = State.new(id, nombre, final)
136
+ i = i + 1
137
+ end
138
+ counter = counter + 1
139
+ modified = lines[counter]
140
+ puts states[5]==nil
141
+ while(modified.include? "transition")
142
+ counter = counter + 1
143
+ modified = lines[counter]
144
+ modified.slice! "\t\t\t<from>"
145
+ from = readTransInt(modified)
146
+ counter = counter + 1
147
+ modified = lines[counter]
148
+ modified.slice! "\t\t\t<to>"
149
+ to = readTransInt(modified)
150
+ counter = counter + 1
151
+ modified = lines[counter]
152
+ modified.slice! "\t\t\t<read>"
153
+ trans = modified[0]
154
+ states[from].addTrans(trans, to)
155
+ counter = counter + 2
156
+ modified = lines[counter]
157
+ puts "Lets go from #{from} to #{to} with #{trans}"
158
+ end
159
+ puts "Initial state is #{initialState}"
160
+
161
+ #Validate
162
+ file = File.new(testFile, "r")
163
+ line = file.read
164
+ file.close
165
+ counter = 1
166
+ lines = line.split("\n")
167
+ for lin in lines
168
+ puts "#{counter}: #{lin}"
169
+ valid = validateString(initialState, states, lin)
170
+ puts "Is valid? #{valid}"
171
+ counter = counter + 1
172
+ end
173
+ end
174
+ #Returns true if the automaton ends in final state, returns false otherwise
175
+ def self.analizeFiniteAutomatonFromString(sourceFile, testString)
176
+ file = File.new(sourceFile, "r")
177
+ line = file.read
178
+ file.close
179
+ counter = 1
180
+ lines = line.split("\n")
181
+ for lin in lines
182
+ puts "#{counter}: #{lin}"
183
+ counter = counter + 1
184
+ end
185
+ puts "First line is " + lines[0]
186
+ if !lines[0].include? "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><!--Created with JFLAP 6.4.--><structure>&#13;"
187
+ puts "Not a JFLAP file"
188
+ end
189
+ # Check if finite automaton
190
+ puts lines[1]
191
+ if lines[1].include? "<type>fa</type>&#13;"
192
+ puts "Finite automaton"
193
+ else
194
+ puts "Not a finite automaton"
195
+ end
196
+ states = []
197
+ counter = 4
198
+ i = 0
199
+ initialState = nil
200
+ modified = lines[counter]
201
+ while(modified.include? "state")
202
+ final = 0
203
+ aux = counter
204
+ id = getStateID(modified)
205
+ nombre = getStateName(modified)
206
+ puts "Modified string for state is ", modified
207
+ puts id
208
+ puts nombre
209
+ if(lines[counter + 3 ].include? "initial")
210
+ aux = aux + 1
211
+ initialState = id
212
+ end
213
+ if(lines[aux + 3].include? "final")
214
+ final = 1
215
+ aux = aux + 1
216
+ end
217
+ counter = aux + 4
218
+ modified = lines[counter]
219
+ states[id] = State.new(id, nombre, final)
220
+ i = i + 1
221
+ end
222
+ counter = counter + 1
223
+ modified = lines[counter]
224
+ puts states[5]==nil
225
+ while(modified.include? "transition")
226
+ counter = counter + 1
227
+ modified = lines[counter]
228
+ modified.slice! "\t\t\t<from>"
229
+ from = readTransInt(modified)
230
+ counter = counter + 1
231
+ modified = lines[counter]
232
+ modified.slice! "\t\t\t<to>"
233
+ to = readTransInt(modified)
234
+ counter = counter + 1
235
+ modified = lines[counter]
236
+ modified.slice! "\t\t\t<read>"
237
+ trans = modified[0]
238
+ states[from].addTrans(trans, to)
239
+ counter = counter + 2
240
+ modified = lines[counter]
241
+ puts "Lets go from #{from} to #{to} with #{trans}"
242
+ end
243
+ puts "Initial state is #{initialState}"
244
+
245
+ #Validate
246
+ lin = testString
247
+ valid = validateString(initialState, states, lin)
248
+ end
249
+ end
@@ -0,0 +1,46 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?><!--Created with JFLAP 6.4.--><structure>&#13;
2
+ <type>fa</type>&#13;
3
+ <automaton>&#13;
4
+ <!--The list of states.-->&#13;
5
+ <state id="0" name="q0">&#13;
6
+ <x>75.0</x>&#13;
7
+ <y>102.0</y>&#13;
8
+ <initial/>&#13;
9
+ </state>&#13;
10
+ <state id="1" name="q1">&#13;
11
+ <x>233.0</x>&#13;
12
+ <y>104.0</y>&#13;
13
+ </state>&#13;
14
+ <state id="2" name="q2">&#13;
15
+ <x>396.0</x>&#13;
16
+ <y>101.0</y>&#13;
17
+ <final/>&#13;
18
+ </state>&#13;
19
+ <!--The list of transitions.-->&#13;
20
+ <transition>&#13;
21
+ <from>0</from>&#13;
22
+ <to>0</to>&#13;
23
+ <read>a</read>&#13;
24
+ </transition>&#13;
25
+ <transition>&#13;
26
+ <from>1</from>&#13;
27
+ <to>1</to>&#13;
28
+ <read>b</read>&#13;
29
+ </transition>&#13;
30
+ <transition>&#13;
31
+ <from>2</from>&#13;
32
+ <to>2</to>&#13;
33
+ <read>c</read>&#13;
34
+ </transition>&#13;
35
+ <transition>&#13;
36
+ <from>1</from>&#13;
37
+ <to>2</to>&#13;
38
+ <read>c</read>&#13;
39
+ </transition>&#13;
40
+ <transition>&#13;
41
+ <from>0</from>&#13;
42
+ <to>1</to>&#13;
43
+ <read>b</read>&#13;
44
+ </transition>&#13;
45
+ </automaton>&#13;
46
+ </structure>
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: SEATC
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Salvador Guerra Delgado
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-23 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A gem for development on SEATC, can be used for other system that requires
14
+ automaton analysis
15
+ email: salvador.guerra.delgado2@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - Rakefile
21
+ - bin/Finite Automaton
22
+ - lib/Finite Automaton Analyzer.rb
23
+ - samples/Finite Automaton.jff
24
+ homepage: http://rubygems.org/gems/SEATC
25
+ licenses: []
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.7.4
44
+ signing_key:
45
+ specification_version: 3
46
+ summary: SEATC
47
+ test_files: []