-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuselessKiller.js
45 lines (36 loc) · 1.21 KB
/
uselessKiller.js
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
const utils = require('./utils')
exports.process = function(aAFD, aT, aNT) {
this.aAFD = aAFD.slice();
this.aNT = aNT.slice();
this.aT = aT;
this.used = Array(["0"]);
let initialState = 0
stateTravel.call(this, initialState)
for (let i = this.aAFD.length - 1; i >= 0; i--) {
if (!utils.check_existence(aNT[i].ruleName, this.used)) {
let AfID = this.aNT.findIndex((el) => el.ruleName == aNT[i].ruleName)
this.aAFD.splice(i, 1)
this.aNT.splice(AfID, 1)
}
}
return {
aAFD: this.aAFD,
aT: this.aT,
aNT: this.aNT
}
function stateTravel(currentState) {
let state = this.aAFD[currentState]
for (let i = 0; i < state.length; i++) {
let nextTransition = state[i].transition;
if (state[i].symbolName != 'ε') {
let AfID = this.aNT.findIndex((el) => el.ruleName == nextTransition)
if (AfID >= 0 && AfID != currentState) {
stateTravel.call(this, AfID)
}
}
if (!utils.check_existence(nextTransition, this.used)) {
this.used.push(nextTransition)
}
}
}
}