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 +4 -4
- data/bin/Deterministic Finite Automaton +4 -0
- data/bin/Grammar Analyzer +4 -0
- data/bin/Nondeterministic Finite Automaton +5 -0
- data/bin/Pushdown Automaton +4 -0
- data/bin/Regular Expression +4 -0
- data/bin/Regular Grammar +4 -0
- data/lib/{Finite Automaton Analyzer.rb → Automaton Analyzer.rb } +175 -151
- data/lib/Grammar Analyzer.rb +0 -8
- data/lib/PDA.rb +0 -6
- data/lib/Regular Expression.rb +0 -2
- data/lib/Regular Grammar Analyzer.rb +0 -3
- data/samples/Deterministic Finite Automaton.jff +46 -0
- data/samples/Nondeterministic.jff +49 -0
- metadata +13 -5
- data/bin/Finite Automaton +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8525a42e73d7a9191be39f46c9af7c64f8e3460
|
4
|
+
data.tar.gz: 541d53ecbf327f5664b628b6ca48a5a29674486d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a8050ecdd4cfb8eee5ea46b802ffa0fb5320363d5d01571aca471251ad426a38106666715d2edd4fdafc43b1a52f0286d3cb9c05da779fa086d58225ba02702
|
7
|
+
data.tar.gz: 3f450b998e9e3111ce26083bc7f9dc4ceec353f3846c2295c3f9ef7b8c077946e53cd469e227512023396e702f282660160c7f6b7b48d065ca552439a68eb95a
|
data/bin/Regular Grammar
ADDED
@@ -1,151 +1,175 @@
|
|
1
|
-
class
|
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]
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
def
|
19
|
-
ret = @
|
20
|
-
end
|
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
|
-
|
142
|
-
states[
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
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
|
+
|
data/lib/Grammar Analyzer.rb
CHANGED
@@ -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
data/lib/Regular Expression.rb
CHANGED
@@ -0,0 +1,46 @@
|
|
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>75.0</x>
|
7
|
+
<y>102.0</y>
|
8
|
+
<initial/>
|
9
|
+
</state>
|
10
|
+
<state id="1" name="q1">
|
11
|
+
<x>233.0</x>
|
12
|
+
<y>104.0</y>
|
13
|
+
</state>
|
14
|
+
<state id="2" name="q2">
|
15
|
+
<x>396.0</x>
|
16
|
+
<y>101.0</y>
|
17
|
+
<final/>
|
18
|
+
</state>
|
19
|
+
<!--The list of transitions.-->
|
20
|
+
<transition>
|
21
|
+
<from>0</from>
|
22
|
+
<to>0</to>
|
23
|
+
<read>a</read>
|
24
|
+
</transition>
|
25
|
+
<transition>
|
26
|
+
<from>1</from>
|
27
|
+
<to>1</to>
|
28
|
+
<read>b</read>
|
29
|
+
</transition>
|
30
|
+
<transition>
|
31
|
+
<from>2</from>
|
32
|
+
<to>2</to>
|
33
|
+
<read>c</read>
|
34
|
+
</transition>
|
35
|
+
<transition>
|
36
|
+
<from>1</from>
|
37
|
+
<to>2</to>
|
38
|
+
<read>c</read>
|
39
|
+
</transition>
|
40
|
+
<transition>
|
41
|
+
<from>0</from>
|
42
|
+
<to>1</to>
|
43
|
+
<read>b</read>
|
44
|
+
</transition>
|
45
|
+
</automaton>
|
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
|
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-
|
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
|
-
-
|
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: []
|
data/bin/Finite Automaton
DELETED