SEATC 0.0.7 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e3d86a00d3c0b567233c815e7425b4b4fcd28601
4
- data.tar.gz: 7314721e15b797049082e3b639352cd01e53ac74
3
+ metadata.gz: e8525a42e73d7a9191be39f46c9af7c64f8e3460
4
+ data.tar.gz: 541d53ecbf327f5664b628b6ca48a5a29674486d
5
5
  SHA512:
6
- metadata.gz: 05b5e5b80cf9c273632dabb64bb3e38306cd4d7e52c85c93f8668901a4ba1f3979a6872d34d671cb9790256f807de92c56da1794e3167fff6ffc90fbdbdc0ca3
7
- data.tar.gz: 0dec9032efe2cd1af5762dc254689f320e79b6f5a6485e41b2af26cbdcc25c6bdde7d7b83b4022ed05c5401a5f48697c2bf490a7e391c51b766f00cb1d1db60a
6
+ metadata.gz: 5a8050ecdd4cfb8eee5ea46b802ffa0fb5320363d5d01571aca471251ad426a38106666715d2edd4fdafc43b1a52f0286d3cb9c05da779fa086d58225ba02702
7
+ data.tar.gz: 3f450b998e9e3111ce26083bc7f9dc4ceec353f3846c2295c3f9ef7b8c077946e53cd469e227512023396e702f282660160c7f6b7b48d065ca552439a68eb95a
@@ -0,0 +1,4 @@
1
+ require 'Automaton Analyzer'
2
+
3
+ faa = AutomatonAnalyzer.new true
4
+ puts faa.analyze("../samples/Deterministic Finite Automaton.jff", "abc")
@@ -0,0 +1,4 @@
1
+ require 'Grammar Analyzer'
2
+
3
+ grammar = GrammarAnalyzer.new
4
+ puts grammar.analyze("../samples/Regular Grammar.jff", "aaaa")
@@ -0,0 +1,5 @@
1
+ require 'Automaton Analyzer'
2
+
3
+
4
+ faa = AutomatonAnalyzer.new false
5
+ puts faa.analyze("../samples/Nondeterministic.jff", "ab")
@@ -0,0 +1,4 @@
1
+ require 'PDA'
2
+
3
+ ndfa= PDAAnalyzer.new
4
+ puts ndfa.analyze("../samples/Pushdown.jff", "aabb")
@@ -0,0 +1,4 @@
1
+ require 'Regular Expression'
2
+
3
+ regex = RegularExpression.new
4
+ puts regex.analyze("../samples/Regular Expression.jff", "ab")
@@ -0,0 +1,4 @@
1
+ require 'Regular Grammar Analyzer'
2
+
3
+ rg = RegularGrammar.new
4
+ rg.analyze("../samples/Regular Grammar.jff", "aaaaaaa")
@@ -1,151 +1,175 @@
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 addTrans(char, to)
13
- @transitions[char] = to
14
- end
15
- def transAt(char)
16
- ret = @transitions[char]
17
- end
18
- def final()
19
- ret = @final
20
- end
21
- end
22
-
23
- class FiniteAutomatonAnalyzer
24
- def self.getStateID(modified)
25
- modified.slice! "\t\t<state id=\""
26
- lastQuota = true
27
- id = 0
28
- while(lastQuota)
29
- id = id * 10
30
- char = modified[0]
31
- modified.slice! modified[0]
32
- lastQuota = (modified[0] != "\"")
33
- id = id + char.to_i
34
- end
35
- id = id
36
- end
37
-
38
- def self.getStateName(modified)
39
- modified.slice! "\" name=\""
40
- lastQuota = true
41
- id = ""
42
- while(lastQuota)
43
- id = id + modified[0]
44
- modified.slice! modified[0]
45
- lastQuota = (modified[0] != "\"")
46
- end
47
- id = id
48
- end
49
-
50
- def self.readTransInt(modified)
51
- lastQuota = true
52
- id = 0
53
- while(lastQuota)
54
- id = id * 10
55
- char = modified[0]
56
- modified.slice! modified[0]
57
- lastQuota = (modified[0] != "<")
58
- id = id + char.to_i
59
- end
60
- id = id
61
-
62
- end
63
-
64
- def self.validateString(initial, states, line)
65
- st = initial
66
- brokenLoop = false
67
- while(line != "")
68
- char = line[0]
69
- line.slice! char
70
- st = states[st].transAt(char)
71
- if(st == nil)
72
- brokenLoop = true
73
- break
74
- end
75
- end
76
- if(brokenLoop)
77
- ret = false
78
- else
79
- if(states[st].final == 0)
80
- ret = false
81
- else
82
- ret = true
83
- end
84
- end
85
- end
86
-
87
- #Returns true if the automaton ends in final state, returns false otherwise
88
- def self.analizeFiniteAutomatonFromString(sourceFile, testString)
89
- file = File.new(sourceFile, "r")
90
- line = file.read
91
- file.close
92
- counter = 1
93
- lines = line.split("\n")
94
- for lin in lines
95
- counter = counter + 1
96
- end
97
- if !lines[0].match? "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>"
98
- return false
99
- end
100
- # Check if finite automaton
101
- if !lines[1].include? "<type>fa</type>&#13;"
102
- return false
103
- end
104
- states = []
105
- counter = 4
106
- i = 0
107
- initialState = nil
108
- modified = lines[counter]
109
- while(modified.include? "state")
110
- final = 0
111
- aux = counter
112
- id = getStateID(modified)
113
- nombre = getStateName(modified)
114
- if(lines[counter + 3 ].include? "initial")
115
- aux = aux + 1
116
- initialState = id
117
- end
118
- if(lines[aux + 3].include? "final")
119
- final = 1
120
- aux = aux + 1
121
- end
122
- counter = aux + 4
123
- modified = lines[counter]
124
- states[id] = State.new(id, nombre, final)
125
- i = i + 1
126
- end
127
- counter = counter + 1
128
- modified = lines[counter]
129
- while(modified.include? "transition")
130
- counter = counter + 1
131
- modified = lines[counter]
132
- modified.slice! "\t\t\t<from>"
133
- from = readTransInt(modified)
134
- counter = counter + 1
135
- modified = lines[counter]
136
- modified.slice! "\t\t\t<to>"
137
- to = readTransInt(modified)
138
- counter = counter + 1
139
- modified = lines[counter]
140
- modified.slice! "\t\t\t<read>"
141
- trans = modified[0]
142
- states[from].addTrans(trans, to)
143
- counter = counter + 2
144
- modified = lines[counter]
145
- end
146
-
147
- #Validate
148
- lin = testString
149
- valid = validateString(initialState, states, lin)
150
- end
151
- end
1
+ class AutomatonState
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 addTrans(char, to)
13
+ if @transitions[char] == nil
14
+ @transitions[char] = Hash.new
15
+ end
16
+ @transitions[char][to] = to
17
+ end
18
+ def transAt(char)
19
+ ret = @transitions[char]
20
+ end
21
+ def getTrans
22
+ return @transitions
23
+ end
24
+ def getName
25
+ return @nombre
26
+ end
27
+ def final()
28
+ ret = @final
29
+ end
30
+ end
31
+
32
+ class AutomatonAnalyzer
33
+ attr_accessor :valid, :deterministic
34
+ def initialize(deterministic)
35
+ @deterministic = deterministic
36
+ end
37
+ def isDeterministic(states)
38
+ return false if !@deterministic
39
+ states.each do |estado|
40
+ transiciones = estado.getTrans
41
+ transiciones.each do |transition|
42
+ return false if estado.transAt(transition[0]).length > 1
43
+ end
44
+ end
45
+ end
46
+ def getStateID(modified)
47
+ modified.slice! "\t\t<state id=\""
48
+ lastQuota = true
49
+ id = 0
50
+ while(lastQuota)
51
+ id = id * 10
52
+ char = modified[0]
53
+ modified.slice! modified[0]
54
+ lastQuota = (modified[0] != "\"")
55
+ id = id + char.to_i
56
+ end
57
+ id = id
58
+ end
59
+
60
+ def getStateName(modified)
61
+ modified.slice! "\" name=\""
62
+ lastQuota = true
63
+ id = ""
64
+ while(lastQuota)
65
+ id = id + modified[0]
66
+ modified.slice! modified[0]
67
+ lastQuota = (modified[0] != "\"")
68
+ end
69
+ id = id
70
+ end
71
+
72
+ def readTransInt(modified)
73
+ lastQuota = true
74
+ id = 0
75
+ while(lastQuota)
76
+ id = id * 10
77
+ char = modified[0]
78
+ modified.slice! modified[0]
79
+ lastQuota = (modified[0] != "<")
80
+ id = id + char.to_i
81
+ end
82
+ id = id
83
+
84
+ end
85
+
86
+ def validateString(initial, states, line)
87
+ st = initial
88
+ usedLine = String.new line
89
+ if(usedLine != "")
90
+ char = usedLine[0]
91
+ usedLine.slice! char
92
+ sts = states[st].transAt(char)
93
+ if sts != nil
94
+ sts.each do |transition|
95
+ v = validateString(transition[0], states, usedLine)
96
+ end
97
+ end
98
+ else
99
+ if(states[st].final == 1)
100
+ @valid = true
101
+ end
102
+ end
103
+ end
104
+
105
+ #Returns true if the automaton ends in final state, returns false otherwise
106
+ def analyze(sourceFile, testString)
107
+ file = File.new(sourceFile, "r")
108
+ line = file.read
109
+ file.close
110
+ counter = 1
111
+ lines = line.split("\n")
112
+ for lin in lines
113
+ counter = counter + 1
114
+ end
115
+ if !lines[0].include? "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><!--Created with JFLAP 6.4.--><structure>"
116
+ return false
117
+ end
118
+ # Check if finite automaton
119
+ if !lines[1].match "<type>fa</type>"
120
+ return false
121
+ end
122
+ states = []
123
+ counter = 4
124
+ i = 0
125
+ initialState = nil
126
+ modified = lines[counter]
127
+ while(modified.include? "state")
128
+ final = 0
129
+ aux = counter
130
+ id = getStateID(modified)
131
+ nombre = getStateName(modified)
132
+ if(lines[counter + 3 ].include? "initial")
133
+ aux = aux + 1
134
+ initialState = id
135
+ end
136
+ if(lines[aux + 3].include? "final")
137
+ final = 1
138
+ aux = aux + 1
139
+ end
140
+ counter = aux + 4
141
+ modified = lines[counter]
142
+ states[id] = AutomatonState.new(id, nombre, final)
143
+ i = i + 1
144
+ end
145
+ counter = counter + 1
146
+ modified = lines[counter]
147
+ while(modified.include? "transition")
148
+ counter = counter + 1
149
+ modified = lines[counter]
150
+ modified.slice! "\t\t\t<from>"
151
+ from = readTransInt(modified)
152
+ counter = counter + 1
153
+ modified = lines[counter]
154
+ modified.slice! "\t\t\t<to>"
155
+ to = readTransInt(modified)
156
+ counter = counter + 1
157
+ modified = lines[counter]
158
+ modified.slice! "\t\t\t<read>"
159
+ trans = modified[0]
160
+ states[from].addTrans(trans, to)
161
+ counter = counter + 2
162
+ modified = lines[counter]
163
+ end
164
+ #Validate
165
+ lin = testString
166
+ return false if(@deterministic && !isDeterministic(states))
167
+ valid = validateString(initialState, states, lin)
168
+ if @valid
169
+ ret = true
170
+ else
171
+ ret = false
172
+ end
173
+ end
174
+ end
175
+
@@ -31,19 +31,14 @@ class GrammarAnalyzer
31
31
  for i in 0...p.length
32
32
  s = s + 1 if !isNT(p[i])
33
33
  end
34
- # puts s <= line.length
35
34
  return s <= line.length
36
35
  end
37
36
 
38
37
  def analyzer(prod, line, prods)
39
- #puts "Analyzing " + prod
40
38
  while canContinue(prod, line)
41
39
  if prod.length == 0
42
40
  if line.length == 0
43
41
  @valid = true
44
- #println "Exito"
45
- else
46
- #println "Error"
47
42
  end
48
43
  return
49
44
  end
@@ -58,7 +53,6 @@ class GrammarAnalyzer
58
53
  removeFirst line
59
54
  removeFirst prod
60
55
  else
61
- # println "Error en el analisis"
62
56
  return
63
57
  end
64
58
  end
@@ -76,5 +70,3 @@ class GrammarAnalyzer
76
70
 
77
71
  end
78
72
 
79
- ga = GrammarAnalyzer.new
80
- puts ga.analyze("../samples/Regular Grammar.jff", "aaaa")
data/lib/PDA.rb CHANGED
@@ -219,9 +219,3 @@ class PDAAnalyzer
219
219
  end
220
220
  end
221
221
  end
222
-
223
- ndfa= PDAAnalyzer.new
224
- puts ndfa.analyze("../samples/Pushdown.jff", "aabb")
225
-
226
- <% ndfa= PDAAnalyzer.new %>
227
- <% res = ndfa.analyze("../samples/Pushdown.jff", "aabb") %>
@@ -30,5 +30,3 @@ class RegularExpression
30
30
  end
31
31
  end
32
32
  end
33
- regex = RegularExpression.new
34
- puts regex.analyze("../samples/Regular Expression.jff", "ab")
@@ -178,6 +178,3 @@ class RegularGrammar
178
178
  return @valid
179
179
  end
180
180
  end
181
-
182
- rg = RegularGrammar.new
183
- rg.analyze("../samples/Regular Grammar.jff", "aaaaaaa")
@@ -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>
@@ -0,0 +1,49 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?><!--Created with JFLAP 6.4.--><structure>
2
+ <type>fa</type>
3
+ <automaton>
4
+ <!--The list of states.-->
5
+ <state id="0" name="q0">
6
+ <x>66.0</x>
7
+ <y>95.0</y>
8
+ <initial/>
9
+ </state>
10
+ <state id="1" name="q1">
11
+ <x>297.0</x>
12
+ <y>69.0</y>
13
+ </state>
14
+ <state id="2" name="q2">
15
+ <x>267.0</x>
16
+ <y>211.0</y>
17
+ </state>
18
+ <state id="3" name="q3">
19
+ <x>486.0</x>
20
+ <y>160.0</y>
21
+ <final/>
22
+ </state>
23
+ <state id="4" name="q4">
24
+ <x>486.0</x>
25
+ <y>264.0</y>
26
+ </state>
27
+ <!--The list of transitions.-->
28
+ <transition>
29
+ <from>2</from>
30
+ <to>3</to>
31
+ <read>c</read>
32
+ </transition>
33
+ <transition>
34
+ <from>0</from>
35
+ <to>2</to>
36
+ <read>a</read>
37
+ </transition>
38
+ <transition>
39
+ <from>1</from>
40
+ <to>3</to>
41
+ <read>b</read>
42
+ </transition>
43
+ <transition>
44
+ <from>0</from>
45
+ <to>1</to>
46
+ <read>a</read>
47
+ </transition>
48
+ </automaton>
49
+ </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.0.7
4
+ version: 0.1.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-06-04 00:00:00.000000000 Z
11
+ date: 2018-06-14 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
@@ -18,19 +18,27 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - Rakefile
21
- - bin/Finite Automaton
22
- - lib/Finite Automaton Analyzer.rb
21
+ - bin/Deterministic Finite Automaton
22
+ - bin/Grammar Analyzer
23
+ - bin/Nondeterministic Finite Automaton
24
+ - bin/Pushdown Automaton
25
+ - bin/Regular Expression
26
+ - bin/Regular Grammar
27
+ - lib/Automaton Analyzer.rb
23
28
  - lib/Grammar Analyzer.rb
24
29
  - lib/Grammar Reader.rb
25
30
  - lib/PDA.rb
26
31
  - lib/Regular Expression.rb
27
32
  - lib/Regular Grammar Analyzer.rb
33
+ - samples/Deterministic Finite Automaton.jff
28
34
  - samples/Finite Automaton.jff
35
+ - samples/Nondeterministic.jff
29
36
  - samples/Pushdown.jff
30
37
  - samples/Regular Expression.jff
31
38
  - samples/Regular Grammar.jff
32
39
  homepage: http://rubygems.org/gems/SEATC
33
- licenses: []
40
+ licenses:
41
+ - MIT
34
42
  metadata: {}
35
43
  post_install_message:
36
44
  rdoc_options: []
@@ -1,4 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'SEATC'
4
- SEATC.analizeFiniteAutomatonFromString(argv[0], argv[1])