fas-js 1.4.0 → 1.6.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.
- package/README.md +7 -4
- package/lib/bundle.js +5 -5
- package/lib/bundle.js.map +1 -1
- package/lib/demo-bundle.global.js.map +1 -0
- package/lib/demo-bundle.js +12 -0
- package/lib/index.cjs +166 -174
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +166 -174
- package/lib/index.js.map +1 -1
- package/package.json +23 -4
package/lib/index.js
CHANGED
|
@@ -92,24 +92,24 @@ var DFAUtils = class {
|
|
|
92
92
|
* Transition function should only contain states in Q, and one transition should exist
|
|
93
93
|
* for each combination of Q x Σ
|
|
94
94
|
*/
|
|
95
|
-
static validateTFunc(
|
|
95
|
+
static validateTFunc(_states2, _paths2, _tfunc2, _alph) {
|
|
96
96
|
const newTFunc = /* @__PURE__ */ new Set();
|
|
97
|
-
for (const _t of
|
|
98
|
-
if (!
|
|
97
|
+
for (const _t of _tfunc2) {
|
|
98
|
+
if (!_states2.has(_t.origin)) {
|
|
99
99
|
console.error("Origin state was invalid: %o", JSON.stringify(_t.origin));
|
|
100
100
|
throw new Error(ErrorCode.ORIGIN_STATE_NOT_FOUND);
|
|
101
101
|
}
|
|
102
|
-
if (!
|
|
102
|
+
if (!_states2.has(_t.dest)) {
|
|
103
103
|
console.error("Dest state was invalid: %o", JSON.stringify(_t.dest));
|
|
104
104
|
throw new Error(ErrorCode.DEST_STATE_NOT_FOUND);
|
|
105
105
|
}
|
|
106
|
-
const pathStateVals = getOrDefault(
|
|
106
|
+
const pathStateVals = getOrDefault(_paths2, _t.origin, /* @__PURE__ */ new Set());
|
|
107
107
|
if (this.isValidInputChar(_t.input, _alph)) {
|
|
108
|
-
if (
|
|
108
|
+
if (_paths2.has(_t.origin) && pathStateVals.has(_t.input)) {
|
|
109
109
|
newTFunc.add(_t);
|
|
110
110
|
pathStateVals.delete(_t.input);
|
|
111
111
|
if (pathStateVals.size === 0) {
|
|
112
|
-
|
|
112
|
+
_paths2.delete(_t.origin);
|
|
113
113
|
}
|
|
114
114
|
} else {
|
|
115
115
|
throw new Error(ErrorCode.DUPLICATE_TRANSITION_OBJECT);
|
|
@@ -118,63 +118,63 @@ var DFAUtils = class {
|
|
|
118
118
|
throw new Error(ErrorCode.INVALID_INPUT_CHAR);
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
|
-
if (
|
|
121
|
+
if (_paths2.size > 0) {
|
|
122
122
|
console.error("Not all FSA paths have a transition specified:");
|
|
123
|
-
for (const [key, val] of
|
|
123
|
+
for (const [key, val] of _paths2) {
|
|
124
124
|
console.error("State %s on input(s): %s", key.name, [...val].join(" "));
|
|
125
125
|
}
|
|
126
126
|
throw new Error(ErrorCode.MISSING_REQUIRED_TRANSITION);
|
|
127
127
|
}
|
|
128
128
|
return newTFunc;
|
|
129
129
|
}
|
|
130
|
-
static createPaths(
|
|
131
|
-
const
|
|
132
|
-
for (const state of
|
|
130
|
+
static createPaths(_states2, _alph) {
|
|
131
|
+
const _paths2 = /* @__PURE__ */ new Map();
|
|
132
|
+
for (const state of _states2) {
|
|
133
133
|
for (const char of _alph.sigma) {
|
|
134
|
-
const pathStateVals = getOrDefault(
|
|
135
|
-
if (
|
|
136
|
-
else
|
|
134
|
+
const pathStateVals = getOrDefault(_paths2, state, /* @__PURE__ */ new Set());
|
|
135
|
+
if (_paths2.has(state)) pathStateVals.add(char);
|
|
136
|
+
else _paths2.set(state, /* @__PURE__ */ new Set([char]));
|
|
137
137
|
}
|
|
138
138
|
}
|
|
139
|
-
return
|
|
139
|
+
return _paths2;
|
|
140
140
|
}
|
|
141
141
|
// Determine digraph order based on start state, then following the chain
|
|
142
|
-
static determineStateOrder(
|
|
142
|
+
static determineStateOrder(_links2, _tfunc2, _states2, _start2, _accepts2) {
|
|
143
143
|
const statesOrder = [];
|
|
144
|
-
|
|
145
|
-
for (const tr of
|
|
146
|
-
const linkStateVals = getOrDefault(
|
|
147
|
-
if (
|
|
148
|
-
else
|
|
144
|
+
_links2 = /* @__PURE__ */ new Map();
|
|
145
|
+
for (const tr of _tfunc2) {
|
|
146
|
+
const linkStateVals = getOrDefault(_links2, tr.origin.name, /* @__PURE__ */ new Set());
|
|
147
|
+
if (_links2.has(tr.origin.name)) linkStateVals.add(tr.dest.name);
|
|
148
|
+
else _links2.set(tr.origin.name, /* @__PURE__ */ new Set([tr.dest.name]));
|
|
149
149
|
}
|
|
150
|
-
this.parseLinks(statesOrder,
|
|
150
|
+
this.parseLinks(statesOrder, _start2.name, _links2);
|
|
151
151
|
const stateArr = [];
|
|
152
|
-
Object.values([...
|
|
152
|
+
Object.values([..._states2]).map((state) => stateArr.push(state.name));
|
|
153
153
|
const deadStates = stateArr.filter((x) => !statesOrder.includes(x));
|
|
154
154
|
if (deadStates.length > 0) {
|
|
155
155
|
console.warn("Dead states detected, removing them and associated transitions: %O", deadStates);
|
|
156
|
-
this.removeDeadStates(deadStates,
|
|
156
|
+
this.removeDeadStates(deadStates, _states2, _accepts2, _tfunc2);
|
|
157
157
|
}
|
|
158
158
|
return statesOrder;
|
|
159
159
|
}
|
|
160
160
|
// Reduce FSA by removing dead states and associated transitions
|
|
161
|
-
static removeDeadStates(deadStates,
|
|
162
|
-
for (const state of
|
|
163
|
-
if (deadStates.indexOf(state.name) !== -1)
|
|
161
|
+
static removeDeadStates(deadStates, _states2, _accepts2, _tfunc2) {
|
|
162
|
+
for (const state of _states2) {
|
|
163
|
+
if (deadStates.indexOf(state.name) !== -1) _states2.delete(state);
|
|
164
164
|
}
|
|
165
|
-
for (const state of
|
|
166
|
-
if (deadStates.indexOf(state.name) !== -1)
|
|
165
|
+
for (const state of _accepts2) {
|
|
166
|
+
if (deadStates.indexOf(state.name) !== -1) _accepts2.delete(state);
|
|
167
167
|
}
|
|
168
|
-
for (const tr of
|
|
169
|
-
if (deadStates.indexOf(tr.origin.name) !== -1 || deadStates.indexOf(tr.dest.name) !== -1)
|
|
168
|
+
for (const tr of _tfunc2) {
|
|
169
|
+
if (deadStates.indexOf(tr.origin.name) !== -1 || deadStates.indexOf(tr.dest.name) !== -1) _tfunc2.delete(tr);
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
// Recursively parse graph while adding to an array in order, beginning with q0
|
|
173
|
-
static parseLinks(arr, name,
|
|
173
|
+
static parseLinks(arr, name, _links2) {
|
|
174
174
|
arr.push(name);
|
|
175
|
-
const nameVal = getOrDefault(
|
|
175
|
+
const nameVal = getOrDefault(_links2, name, /* @__PURE__ */ new Set());
|
|
176
176
|
for (const st of nameVal) {
|
|
177
|
-
if (arr.indexOf(st) === -1) this.parseLinks(arr, st,
|
|
177
|
+
if (arr.indexOf(st) === -1) this.parseLinks(arr, st, _links2);
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
// DFA does not allow empty symbol
|
|
@@ -184,14 +184,14 @@ var DFAUtils = class {
|
|
|
184
184
|
}
|
|
185
185
|
};
|
|
186
186
|
var createDFA = (states, alphabet, transitions, start, accepts) => {
|
|
187
|
-
const
|
|
187
|
+
const _tfunc2 = /* @__PURE__ */ new Set();
|
|
188
188
|
for (const tr of transitions) {
|
|
189
189
|
if (!tr.from || !tr.to || !tr.input) throw new Error(ErrorCode.INVALID_TRANSITION_OBJECT);
|
|
190
190
|
const fromVal = getOrDefault(states, tr.from, null);
|
|
191
191
|
const toVal = getOrDefault(states, tr.to, null);
|
|
192
|
-
|
|
192
|
+
_tfunc2.add(new Transition(fromVal, toVal, tr.input));
|
|
193
193
|
}
|
|
194
|
-
return new DFA(new Set(states.values()), alphabet,
|
|
194
|
+
return new DFA(new Set(states.values()), alphabet, _tfunc2, start, accepts);
|
|
195
195
|
};
|
|
196
196
|
|
|
197
197
|
// src/utils/NFAUtils.ts
|
|
@@ -201,11 +201,11 @@ var NFAUtils = class extends DFAUtils {
|
|
|
201
201
|
return _alph.sigma.indexOf(input) !== -1 || input === "";
|
|
202
202
|
}
|
|
203
203
|
// Follow all ε transitions and add to `state` (origin states)
|
|
204
|
-
static populateEpsilons(
|
|
204
|
+
static populateEpsilons(_tfunc2, state) {
|
|
205
205
|
let cont = true;
|
|
206
206
|
while (cont) {
|
|
207
207
|
cont = false;
|
|
208
|
-
const epsTransitions = Array.from(
|
|
208
|
+
const epsTransitions = Array.from(_tfunc2).filter((obj) => {
|
|
209
209
|
return state.includes(obj.origin) && obj.input === "";
|
|
210
210
|
});
|
|
211
211
|
for (const _t of epsTransitions) {
|
|
@@ -218,24 +218,23 @@ var NFAUtils = class extends DFAUtils {
|
|
|
218
218
|
return state;
|
|
219
219
|
}
|
|
220
220
|
// Validate tfunc according to NFA rules
|
|
221
|
-
static validateTFunc(
|
|
221
|
+
static validateTFunc(_states2, _paths2, _tfunc2, _alph) {
|
|
222
222
|
const newTFunc = /* @__PURE__ */ new Set();
|
|
223
|
-
for (const _t of
|
|
223
|
+
for (const _t of _tfunc2) {
|
|
224
224
|
let skip = false;
|
|
225
|
-
if (!
|
|
225
|
+
if (!_states2.has(_t.origin)) {
|
|
226
226
|
console.error("Origin state was invalid: %o", JSON.stringify(_t.origin));
|
|
227
227
|
throw new Error(ErrorCode.ORIGIN_STATE_NOT_FOUND);
|
|
228
228
|
}
|
|
229
|
-
if (!
|
|
229
|
+
if (!_states2.has(_t.dest)) {
|
|
230
230
|
console.error("Dest state was invalid: %o", JSON.stringify(_t.dest));
|
|
231
231
|
throw new Error(ErrorCode.DEST_STATE_NOT_FOUND);
|
|
232
232
|
}
|
|
233
|
-
const pathStateVals = getOrDefault(_paths, _t.origin, /* @__PURE__ */ new Set());
|
|
234
233
|
for (const _checkT of newTFunc) {
|
|
235
234
|
if (_checkT.origin === _t.origin && _checkT.dest === _t.dest && _checkT.input === _t.input) skip = true;
|
|
236
235
|
}
|
|
237
236
|
if (!skip) {
|
|
238
|
-
if (
|
|
237
|
+
if (_paths2.has(_t.origin)) {
|
|
239
238
|
if (this.isValidInputChar(_t.input, _alph)) {
|
|
240
239
|
newTFunc.add(_t);
|
|
241
240
|
} else {
|
|
@@ -248,7 +247,7 @@ var NFAUtils = class extends DFAUtils {
|
|
|
248
247
|
}
|
|
249
248
|
};
|
|
250
249
|
var createNFA = (states, alphabet, transitions, start, accepts) => {
|
|
251
|
-
const
|
|
250
|
+
const _tfunc2 = /* @__PURE__ */ new Set();
|
|
252
251
|
for (const tr of transitions) {
|
|
253
252
|
if (!tr.from || !tr.to || !tr.input && tr.input !== "")
|
|
254
253
|
throw new Error(ErrorCode.INVALID_TRANSITION_OBJECT);
|
|
@@ -258,9 +257,9 @@ var createNFA = (states, alphabet, transitions, start, accepts) => {
|
|
|
258
257
|
toVal.forEach((_dest) => {
|
|
259
258
|
destStates.push(getOrDefault(states, _dest, null));
|
|
260
259
|
});
|
|
261
|
-
|
|
260
|
+
_tfunc2.add(new NFATransition(fromVal, destStates, tr.input));
|
|
262
261
|
}
|
|
263
|
-
return new NFA(new Set(states.values()), alphabet,
|
|
262
|
+
return new NFA(new Set(states.values()), alphabet, _tfunc2, start, accepts);
|
|
264
263
|
};
|
|
265
264
|
|
|
266
265
|
// src/utils/FSAUtils.ts
|
|
@@ -285,7 +284,7 @@ var FSAUtils = /* @__PURE__ */ (() => {
|
|
|
285
284
|
});
|
|
286
285
|
path = path.concat(_addToPath);
|
|
287
286
|
}
|
|
288
|
-
|
|
287
|
+
const resultArr = [];
|
|
289
288
|
if (path.length > 1) {
|
|
290
289
|
for (const _s of path) resultArr.push(_s.dest);
|
|
291
290
|
} else if (path.length === 1) {
|
|
@@ -296,8 +295,8 @@ var FSAUtils = /* @__PURE__ */ (() => {
|
|
|
296
295
|
const retSet = new Set(populateEpsilons(nfa.getTFunc(), resultArr));
|
|
297
296
|
return retSet;
|
|
298
297
|
}
|
|
299
|
-
function populateEpsilons(
|
|
300
|
-
return NFAUtils.populateEpsilons(
|
|
298
|
+
function populateEpsilons(_tfunc2, state) {
|
|
299
|
+
return NFAUtils.populateEpsilons(_tfunc2, state);
|
|
301
300
|
}
|
|
302
301
|
class FSAUtils2 {
|
|
303
302
|
constructor(v) {
|
|
@@ -319,42 +318,42 @@ var FSAUtils = /* @__PURE__ */ (() => {
|
|
|
319
318
|
return receiveInputDFA(fsa, input, state);
|
|
320
319
|
}
|
|
321
320
|
}
|
|
322
|
-
validateTFunc(
|
|
321
|
+
validateTFunc(_states2, _paths2, _tfunc2, _alph) {
|
|
323
322
|
if (this._type === NFA) {
|
|
324
|
-
return NFAUtils.validateTFunc(
|
|
323
|
+
return NFAUtils.validateTFunc(_states2, _paths2, _tfunc2, _alph);
|
|
325
324
|
} else {
|
|
326
|
-
return DFAUtils.validateTFunc(
|
|
325
|
+
return DFAUtils.validateTFunc(_states2, _paths2, _tfunc2, _alph);
|
|
327
326
|
}
|
|
328
327
|
}
|
|
329
|
-
createPaths(
|
|
330
|
-
return DFAUtils.createPaths(
|
|
328
|
+
createPaths(_states2, _alph) {
|
|
329
|
+
return DFAUtils.createPaths(_states2, _alph);
|
|
331
330
|
}
|
|
332
|
-
determineStateOrder(
|
|
333
|
-
return DFAUtils.determineStateOrder(
|
|
331
|
+
determineStateOrder(_links2, _tfunc2, _states2, _start2, _accepts2) {
|
|
332
|
+
return DFAUtils.determineStateOrder(_links2, _tfunc2, _states2, _start2, _accepts2);
|
|
334
333
|
}
|
|
335
334
|
}
|
|
336
335
|
return FSAUtils2;
|
|
337
336
|
})();
|
|
338
337
|
var createFSA = (states, alphabet, transitions, start, accepts) => {
|
|
339
|
-
const
|
|
338
|
+
const _states2 = /* @__PURE__ */ new Map();
|
|
340
339
|
if (typeof states === "string") {
|
|
341
|
-
|
|
340
|
+
_states2.set(states, new State(states));
|
|
342
341
|
} else if (Array.isArray(states)) {
|
|
343
342
|
for (const state of states) {
|
|
344
|
-
if (!
|
|
343
|
+
if (!_states2.has(state)) _states2.set(state, new State(state));
|
|
345
344
|
}
|
|
346
345
|
} else {
|
|
347
346
|
throw new TypeError(String(states));
|
|
348
347
|
}
|
|
349
|
-
const
|
|
348
|
+
const _alphabet2 = new Alphabet(alphabet);
|
|
350
349
|
if (typeof start !== "string") throw new TypeError(String(start));
|
|
351
|
-
const
|
|
352
|
-
const
|
|
350
|
+
const _start2 = getOrDefault(_states2, start, null);
|
|
351
|
+
const _accepts2 = /* @__PURE__ */ new Set();
|
|
353
352
|
if (typeof accepts === "string") {
|
|
354
|
-
if (
|
|
353
|
+
if (_states2.has(accepts)) _accepts2.add(getOrDefault(_states2, accepts, null));
|
|
355
354
|
} else if (Array.isArray(accepts)) {
|
|
356
355
|
for (const state of accepts) {
|
|
357
|
-
|
|
356
|
+
_accepts2.add(getOrDefault(_states2, state, null));
|
|
358
357
|
}
|
|
359
358
|
} else {
|
|
360
359
|
throw new TypeError(String(accepts));
|
|
@@ -365,130 +364,123 @@ var createFSA = (states, alphabet, transitions, start, accepts) => {
|
|
|
365
364
|
else throw new TypeError(String(transitions));
|
|
366
365
|
for (const tr of transitionList) {
|
|
367
366
|
if (tr.to.indexOf(",") != -1 || tr.input === "")
|
|
368
|
-
return createNFA(
|
|
367
|
+
return createNFA(_states2, _alphabet2, transitionList, _start2, _accepts2);
|
|
369
368
|
}
|
|
370
|
-
return createDFA(
|
|
369
|
+
return createDFA(_states2, _alphabet2, transitionList, _start2, _accepts2);
|
|
371
370
|
};
|
|
372
371
|
|
|
373
372
|
// src/automata/DFA.ts
|
|
374
|
-
var
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
return `digraph fsa {
|
|
373
|
+
var _states, _alphabet, _tfunc, _start, _accepts, _paths, _links, _utils;
|
|
374
|
+
var DFA = class {
|
|
375
|
+
constructor(states, alphabet, tfunc, start, accepts) {
|
|
376
|
+
// Primary FSA attributes
|
|
377
|
+
__privateAdd(this, _states);
|
|
378
|
+
__privateAdd(this, _alphabet);
|
|
379
|
+
__privateAdd(this, _tfunc);
|
|
380
|
+
__privateAdd(this, _start);
|
|
381
|
+
__privateAdd(this, _accepts);
|
|
382
|
+
// Intermediary attributes used in constructor
|
|
383
|
+
__privateAdd(this, _paths);
|
|
384
|
+
// States mapped to each member of Σ, will be empty after constructor returns
|
|
385
|
+
__privateAdd(this, _links, /* @__PURE__ */ new Map());
|
|
386
|
+
// State names mapped to their dest state names
|
|
387
|
+
__privateAdd(this, _utils);
|
|
388
|
+
__privateSet(this, _utils, new FSAUtils(this.constructor));
|
|
389
|
+
if (checkStateDuplicates(states)) throw new Error(ErrorCode.DUPLICATE_STATE_NAMES);
|
|
390
|
+
__privateSet(this, _states, states);
|
|
391
|
+
__privateSet(this, _alphabet, alphabet);
|
|
392
|
+
__privateSet(this, _paths, __privateGet(this, _utils).createPaths(__privateGet(this, _states), __privateGet(this, _alphabet)));
|
|
393
|
+
if (!states.has(start)) throw new Error(ErrorCode.START_STATE_NOT_FOUND);
|
|
394
|
+
__privateSet(this, _start, start);
|
|
395
|
+
if (Object.keys(accepts).length === 0 && accepts.constructor === Object) accepts = /* @__PURE__ */ new Set([]);
|
|
396
|
+
if (!isSubsetOf(accepts, states)) throw new Error(ErrorCode.ACCEPTS_NOT_SUBSET);
|
|
397
|
+
__privateSet(this, _accepts, accepts);
|
|
398
|
+
__privateSet(this, _tfunc, __privateGet(this, _utils).validateTFunc(__privateGet(this, _states), __privateGet(this, _paths), tfunc, __privateGet(this, _alphabet)));
|
|
399
|
+
}
|
|
400
|
+
/*
|
|
401
|
+
* Getters
|
|
402
|
+
*/
|
|
403
|
+
getStates() {
|
|
404
|
+
return __privateGet(this, _states);
|
|
405
|
+
}
|
|
406
|
+
getAlphabet() {
|
|
407
|
+
return __privateGet(this, _alphabet);
|
|
408
|
+
}
|
|
409
|
+
getTFunc() {
|
|
410
|
+
return __privateGet(this, _tfunc);
|
|
411
|
+
}
|
|
412
|
+
getStartState() {
|
|
413
|
+
return __privateGet(this, _start);
|
|
414
|
+
}
|
|
415
|
+
getAcceptStates() {
|
|
416
|
+
return __privateGet(this, _accepts);
|
|
417
|
+
}
|
|
418
|
+
getType() {
|
|
419
|
+
return "DFA";
|
|
420
|
+
}
|
|
421
|
+
generateDigraph() {
|
|
422
|
+
const acceptArr = [];
|
|
423
|
+
for (const state of __privateGet(this, _accepts)) acceptArr.push(state.name);
|
|
424
|
+
const pairs = /* @__PURE__ */ new Map();
|
|
425
|
+
Object.values([...__privateGet(this, _tfunc)]).map(function(t) {
|
|
426
|
+
const key = t.origin.name + t.dest.name;
|
|
427
|
+
let _input = t.input;
|
|
428
|
+
if (_input === "") _input = "\u03B5";
|
|
429
|
+
if (!pairs.has(key)) {
|
|
430
|
+
pairs.set(key, t.origin.name + " -> " + t.dest.name + ' [ label = "' + _input + '" ];');
|
|
431
|
+
} else {
|
|
432
|
+
let _line = getOrDefault(pairs, key, "");
|
|
433
|
+
const _oldinput = _line.split('"')[1];
|
|
434
|
+
const _toAdd = _oldinput.split(",");
|
|
435
|
+
_toAdd.push(_input);
|
|
436
|
+
_toAdd.sort();
|
|
437
|
+
_line = _line.replace('"' + _oldinput + '"', '"' + _toAdd.toString() + '"');
|
|
438
|
+
pairs.set(key, _line);
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
return `digraph fsa {
|
|
444
442
|
${Object.values(
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
443
|
+
__privateGet(this, _utils).determineStateOrder(__privateGet(this, _links), __privateGet(this, _tfunc), __privateGet(this, _states), __privateGet(this, _start), __privateGet(this, _accepts))
|
|
444
|
+
).map(function(str) {
|
|
445
|
+
if (acceptArr.indexOf(str) !== -1) return str + " [shape = doublecircle];";
|
|
446
|
+
else return str;
|
|
447
|
+
}).join("\n ")}
|
|
450
448
|
rankdir=LR;
|
|
451
449
|
node [shape = point ]; qi;
|
|
452
450
|
node [shape = circle];
|
|
453
451
|
qi -> ${__privateGet(this, _start).name};
|
|
454
452
|
${Object.values([...pairs]).map(function([, val]) {
|
|
455
|
-
|
|
456
|
-
|
|
453
|
+
return val;
|
|
454
|
+
}).join("\n ")}
|
|
457
455
|
}
|
|
458
456
|
`;
|
|
459
|
-
}
|
|
460
457
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
})();
|
|
458
|
+
};
|
|
459
|
+
_states = new WeakMap();
|
|
460
|
+
_alphabet = new WeakMap();
|
|
461
|
+
_tfunc = new WeakMap();
|
|
462
|
+
_start = new WeakMap();
|
|
463
|
+
_accepts = new WeakMap();
|
|
464
|
+
_paths = new WeakMap();
|
|
465
|
+
_links = new WeakMap();
|
|
466
|
+
_utils = new WeakMap();
|
|
471
467
|
|
|
472
468
|
// src/automata/NFA.ts
|
|
473
|
-
var NFA =
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
expandedTfunc.add(new Transition(_t.origin, _dest, _t.input));
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
super(states, alphabet, expandedTfunc, start, accepts);
|
|
485
|
-
}
|
|
486
|
-
getType() {
|
|
487
|
-
return "NFA";
|
|
469
|
+
var NFA = class extends DFA {
|
|
470
|
+
constructor(states, alphabet, tfunc, start, accepts) {
|
|
471
|
+
if (!alphabet.sigma.includes("")) alphabet.sigma.push("");
|
|
472
|
+
const expandedTfunc = /* @__PURE__ */ new Set();
|
|
473
|
+
for (const _t of tfunc) {
|
|
474
|
+
_t.dest.forEach((_dest) => {
|
|
475
|
+
expandedTfunc.add(new Transition(_t.origin, _dest, _t.input));
|
|
476
|
+
});
|
|
488
477
|
}
|
|
478
|
+
super(states, alphabet, expandedTfunc, start, accepts);
|
|
489
479
|
}
|
|
490
|
-
|
|
491
|
-
|
|
480
|
+
getType() {
|
|
481
|
+
return "NFA";
|
|
482
|
+
}
|
|
483
|
+
};
|
|
492
484
|
|
|
493
485
|
// src/engine/Simulators.ts
|
|
494
486
|
var simulateFSA = (w, fsa, logging = false, returnEndState = false) => {
|