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