-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautomata.js
51 lines (45 loc) · 1.48 KB
/
automata.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
46
47
48
49
50
51
'use strict';
let automataCounter = 0;
class Automata {
constructor(start, accepts) {
this._start = start || null;
this._accepts = accepts || [];
this._id = automataCounter++;
}
print() {
let collection = [];
this._print(this._start, collection);
console.log('START: ' + this._start._id);
collection.forEach((child) => {
let spoof = {};
spoof.id = child.getId();
spoof.accepting = child.isAccepting();
spoof.transitions = {};
child.forEachTransition((transitionKey, transitionData) => {
spoof.transitions[transitionKey] = [];
transitionData.forEach((subData) => {
spoof.transitions[transitionKey].push({
target: subData.target.getId()
});
});
});
const util = require('util');
console.log(util.inspect(spoof, false, null));
console.log();
});
}
_print(node, collection) {
for (let i = 0; i < collection.length; ++i) {
if (node._id === collection[i]._id) {
return;
}
}
collection.push(node);
node.forEachTransition((transitionKey, transitionData) => {
transitionData.forEach((childTransition) => {
this._print(childTransition.target, collection);
});
});
}
};
module.exports = Automata;