fas-js 1.5.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 +6 -4
- package/lib/demo-bundle.global.js.map +1 -1
- package/lib/demo-bundle.js +5 -5
- package/package.json +14 -3
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
Easily create and simulate state machines using this JS library. Import into your own server side or browser based JS application.
|
|
11
11
|
|
|
12
|
-
> **Contributing:** See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
12
|
+
> **Contributing:** See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
13
13
|
|
|
14
14
|

|
|
15
15
|
###### Visualization of an FSA
|
|
@@ -72,7 +72,7 @@ const alph_array = ["0", "1", "up", "down", "*"];
|
|
|
72
72
|
|
|
73
73
|
Input array for DFAs must contain a transition for each alphabet symbol on each origin state. Thus, the size of δ = size of Σ x size of Q. Σ cannot contain an empty string as a symbol for DFAs.
|
|
74
74
|
|
|
75
|
-
For NFAs, the `to` field can contain one or more destination states, comma separated, no spaces between state names. The `input` field can be `""`, indicating an ε (empty) transition.
|
|
75
|
+
For NFAs, the `to` field can contain one or more destination states, comma separated, no spaces between state names. The `input` field can be `""`, indicating an ε (empty) transition. In JSON and simulation, always use `""` for ε; graph labels may display ε (U+03B5). Pass multi-symbol alphabets as a string array (e.g. `["0", "1", "up", "down"]`) so each entry is one symbol — including UTF-8 characters.
|
|
76
76
|
```javascript
|
|
77
77
|
const dfa_tfunc = [
|
|
78
78
|
{ from: "q1", to: "q2", input: "1" },
|
|
@@ -168,9 +168,11 @@ Interactive demos visualize FSAs as you simulate input strings.
|
|
|
168
168
|
|
|
169
169
|
| Version | URL | Notes |
|
|
170
170
|
|---------|-----|-------|
|
|
171
|
-
| **v1.5
|
|
171
|
+
| **v1.5+** | [GitHub Pages demo](https://jml6m.github.io/fas-js/v1.5/) | DFA/NFA simulator — prebuilt examples, simulate/step, graph (`demo/v1.5/`) |
|
|
172
172
|
| **v1.1** | [Redirect](https://jml6m.github.io/fas-js/v1.1/) | Preserved URL → v1.5 |
|
|
173
|
-
| **v1** (legacy) | [ObservableHQ](https://observablehq.com/@jml6m/state-machine-simulator) | Original
|
|
173
|
+
| **v1** (legacy) | [ObservableHQ](https://observablehq.com/@jml6m/state-machine-simulator) | Original notebook |
|
|
174
|
+
|
|
175
|
+
Local: `npm run build && npm run serve:demo` → http://127.0.0.1:3000/v1.5/
|
|
174
176
|
|
|
175
177
|
See [demo/README.md](demo/README.md) for local development and deployment details.
|
|
176
178
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/demo-bundle.ts","../src/globals/errors.ts","../src/components/State.ts","../src/globals/globals.ts","../src/components/Alphabet.ts","../src/components/NFATransition.ts","../src/components/Transition.ts","../src/utils/DFAUtils.ts","../src/utils/NFAUtils.ts","../src/utils/FSAUtils.ts","../src/automata/DFA.ts","../src/automata/NFA.ts","../src/engine/Simulators.ts","../src/languages/Language.ts","../src/languages/fsaHelpers.ts","../src/languages/LanguageOperations.ts","../src/languages/NFAtoDFA.ts","../src/languages/RegularLanguage.ts"],"sourcesContent":["/**\n * Demo-only IIFE entry — extends the public bundle with language classes.\n * Not exported from package.json \"exports\"; copied to demo/v1.5/vendor only.\n */\nexport { createFSA, simulateFSA, stepOnceFSA } from \"./modules\";\nexport { RegularLanguage } from \"./languages\";","export const ErrorCode: Readonly<Record<string, string>> = Object.freeze({\n DUPLICATE_ALPHABET_VALS: \"E-001\",\n DUPLICATE_STATE_NAMES: \"E-002\",\n INVALID_STATE_NAME: \"E-003\",\n START_STATE_NOT_FOUND: \"E-004\",\n ACCEPTS_NOT_SUBSET: \"E-005\",\n ORIGIN_STATE_NOT_FOUND: \"E-006\",\n DEST_STATE_NOT_FOUND: \"E-007\",\n MISSING_REQUIRED_TRANSITION: \"E-008\",\n INVALID_INPUT_CHAR: \"E-009\",\n INPUT_STATE_NOT_FOUND: \"E-010\",\n INVALID_TRANSITION_OBJECT: \"E-011\",\n DUPLICATE_TRANSITION_OBJECT: \"E-012\",\n INVALID_STATE_ARRAY: \"E-013\"\n});","import { ErrorCode } from \"../globals/errors\";\n\nexport class State {\n name: string;\n\n constructor(name: string) {\n this.name = name;\n if (!this.name) throw new Error(ErrorCode.INVALID_STATE_NAME);\n }\n}","import { type State } from \"../components/State\";\n\n// Count number of instances for each string in an array - returns key/val pairs\nexport const count = (names: string[]): Record<string, number> =>\n names.reduce((a, b) => Object.assign(a, { [b]: (a[b] || 0) + 1 }), {} as Record<string, number>);\n\n// Returns keys with value > 1\nexport const duplicates = (dict: Record<string, number>): string[] =>\n Object.keys(dict).filter(a => dict[a] > 1);\n\n// Equality function for Arrays containing primitive typed values\nexport const compare = (\n a1: Array<string | number | boolean>,\n a2: Array<string | number | boolean>\n): boolean => {\n const s1 = new Set(a1);\n const s2 = new Set(a2);\n return s1.size === s2.size && [...s1].every(v => s2.has(v));\n};\n\n// Check for duplicate keys in a Set<State> input\nexport const checkStateDuplicates = (states: Set<State>): boolean => {\n const check: Set<string> = new Set();\n for (const item of states) {\n if (check.has(item.name)) return true;\n check.add(item.name);\n }\n return false;\n};\n\nexport const getOrDefault = <K, V>(map: Map<K, V>, key: K, defaultValue: V): V => {\n const val = map.get(key);\n return val == null ? defaultValue : val;\n};\n\ntype ConstructorLike<T extends object = object> = abstract new (...args: never[]) => T;\n\nexport const instanceOf = <T extends object>(ctor: ConstructorLike<T>, obj: object): obj is T => {\n return obj instanceof ctor || (Boolean(ctor.name) && ctor.name === obj.constructor.name);\n};\n\nexport const isSubsetOf = <T>(subset: Set<T>, superset: Set<T>): boolean => {\n for (const item of subset) {\n if (!superset.has(item)) return false;\n }\n return true;\n};\n\nexport const isSupersetOf = <T>(superset: Set<T>, subset: Set<T>): boolean => {\n return isSubsetOf(subset, superset);\n};","import { ErrorCode } from \"../globals/errors\";\nimport { count, duplicates } from \"../globals/globals\";\n\nexport class Alphabet {\n sigma: string[];\n\n constructor(sigma: string | string[]) {\n if (!Array.isArray(sigma)) {\n if (typeof sigma === \"string\") sigma = [...sigma];\n else throw new TypeError();\n }\n this.sigma = sigma;\n if (duplicates(count(this.sigma)).length > 0) throw new Error(ErrorCode.DUPLICATE_ALPHABET_VALS);\n }\n}","import { type State } from \"./State\";\n\nexport class NFATransition {\n origin: State;\n dest: State[];\n input: string;\n\n constructor(origin: State, dest: State[], input: string) {\n this.origin = origin;\n this.dest = dest;\n this.input = input;\n }\n}","import { type State } from \"./State\";\n\nexport class Transition {\n origin: State;\n dest: State;\n input: string;\n\n constructor(origin: State, dest: State, input: string) {\n this.origin = origin;\n this.dest = dest;\n this.input = input;\n }\n}","import { ErrorCode } from \"../globals/errors\";\nimport { type State, type Alphabet, Transition } from \"../components\";\nimport { DFA } from \"../automata\";\nimport { getOrDefault } from \"../globals/globals\";\n\nexport class DFAUtils {\n /*\n * Transition function should only contain states in Q, and one transition should exist\n * for each combination of Q x Σ\n */\n static validateTFunc(\n _states: Set<State>,\n _paths: Map<State, Set<string>>,\n _tfunc: Set<Transition>,\n _alph: Alphabet\n ): Set<Transition> {\n const newTFunc: Set<Transition> = new Set(); // Will contain only necessary transitions\n\n for (const _t of _tfunc) {\n // Check for valid states\n if (!_states.has(_t.origin)) {\n console.error(\"Origin state was invalid: %o\", JSON.stringify(_t.origin));\n throw new Error(ErrorCode.ORIGIN_STATE_NOT_FOUND);\n }\n if (!_states.has(_t.dest)) {\n console.error(\"Dest state was invalid: %o\", JSON.stringify(_t.dest));\n throw new Error(ErrorCode.DEST_STATE_NOT_FOUND);\n }\n\n const pathStateVals: Set<string> = getOrDefault(_paths, _t.origin, new Set());\n\n // Map transition to a path and remove on match\n if (this.isValidInputChar(_t.input, _alph)) {\n if (_paths.has(_t.origin) && pathStateVals.has(_t.input)) {\n newTFunc.add(_t);\n pathStateVals.delete(_t.input);\n if (pathStateVals.size === 0) {\n _paths.delete(_t.origin);\n }\n } else {\n throw new Error(ErrorCode.DUPLICATE_TRANSITION_OBJECT);\n }\n } else {\n throw new Error(ErrorCode.INVALID_INPUT_CHAR);\n }\n }\n\n if (_paths.size > 0) {\n console.error(\"Not all FSA paths have a transition specified:\");\n for (const [key, val] of _paths) {\n console.error(\"State %s on input(s): %s\", key.name, [...val].join(\" \"));\n }\n throw new Error(ErrorCode.MISSING_REQUIRED_TRANSITION);\n }\n\n return newTFunc;\n }\n\n static createPaths(_states: Set<State>, _alph: Alphabet): Map<State, Set<string>> {\n const _paths: Map<State, Set<string>> = new Map<State, Set<string>>();\n for (const state of _states) {\n for (const char of _alph.sigma) {\n const pathStateVals: Set<string> = getOrDefault(_paths, state, new Set());\n if (_paths.has(state)) pathStateVals.add(char);\n else _paths.set(state, new Set([char]));\n }\n }\n\n return _paths;\n }\n\n // Determine digraph order based on start state, then following the chain\n static determineStateOrder(\n _links: Map<string, Set<string>>,\n _tfunc: Set<Transition>,\n _states: Set<State>,\n _start: State,\n _accepts: Set<State>\n ): string[] {\n const statesOrder: string[] = []; // Ordered state names for digraph\n\n // Map origin state names to dest state names\n _links = new Map();\n for (const tr of _tfunc) {\n const linkStateVals: Set<string> = getOrDefault(_links, tr.origin.name, new Set());\n if (_links.has(tr.origin.name)) linkStateVals.add(tr.dest.name);\n else _links.set(tr.origin.name, new Set([tr.dest.name]));\n }\n\n // Populate state order\n this.parseLinks(statesOrder, _start.name, _links);\n\n // Check for dead states and reduce FSA if necessary\n const stateArr: string[] = [];\n (Object.values([..._states]) as State[]).map((state: State) => stateArr.push(state.name));\n const deadStates = stateArr.filter(x => !statesOrder.includes(x));\n if (deadStates.length > 0) {\n console.warn(\"Dead states detected, removing them and associated transitions: %O\", deadStates);\n this.removeDeadStates(deadStates, _states, _accepts, _tfunc);\n }\n\n return statesOrder;\n }\n\n // Reduce FSA by removing dead states and associated transitions\n static removeDeadStates(\n deadStates: string[],\n _states: Set<State>,\n _accepts: Set<State>,\n _tfunc: Set<Transition>\n ) {\n // Q\n for (const state of _states) {\n if (deadStates.indexOf(state.name) !== -1) _states.delete(state);\n }\n // F\n for (const state of _accepts) {\n if (deadStates.indexOf(state.name) !== -1) _accepts.delete(state);\n }\n // δ\n for (const tr of _tfunc) {\n if (deadStates.indexOf(tr.origin.name) !== -1 || deadStates.indexOf(tr.dest.name) !== -1) _tfunc.delete(tr);\n }\n }\n\n // Recursively parse graph while adding to an array in order, beginning with q0\n static parseLinks(arr: string[], name: string, _links: Map<string, Set<string>>) {\n arr.push(name);\n const nameVal = getOrDefault(_links, name, new Set<string>());\n for (const st of nameVal) {\n if (arr.indexOf(st) === -1) this.parseLinks(arr, st, _links);\n }\n }\n\n // DFA does not allow empty symbol\n static isValidInputChar(input: string, _alph: Alphabet): boolean {\n if (input === \"\") return false;\n return _alph.sigma.indexOf(input) !== -1;\n }\n}\n\nexport interface TransitionInput {\n from: string;\n to: string;\n input: string;\n}\n\n// Global export method for creating DFA\nexport const createDFA = (\n states: Map<string, State>,\n alphabet: Alphabet,\n transitions: TransitionInput[],\n start: State,\n accepts: Set<State>\n): InstanceType<typeof DFA> => {\n // Convert transition array to Set<Transition>\n const _tfunc: Set<Transition> = new Set();\n for (const tr of transitions) {\n if (!tr.from || !tr.to || !tr.input) throw new Error(ErrorCode.INVALID_TRANSITION_OBJECT);\n const fromVal: State = getOrDefault(states, tr.from, null as unknown as State);\n const toVal: State = getOrDefault(states, tr.to, null as unknown as State);\n _tfunc.add(new Transition(fromVal, toVal, tr.input));\n }\n return new DFA(new Set(states.values()), alphabet, _tfunc, start, accepts);\n};","import { DFAUtils } from \"./DFAUtils\";\nimport { NFA } from \"../automata\";\nimport { type State, type Transition, type Alphabet, NFATransition } from \"../components\";\nimport { ErrorCode } from \"../globals/errors\";\nimport { getOrDefault } from \"../globals/globals\";\nimport type { TransitionInput } from \"./DFAUtils\";\n\nexport class NFAUtils extends DFAUtils {\n // NFA inheritly allows for ε (empty string) transition if specified\n static isValidInputChar(input: string, _alph: Alphabet): boolean {\n return _alph.sigma.indexOf(input) !== -1 || input === \"\";\n }\n\n // Follow all ε transitions and add to `state` (origin states)\n static populateEpsilons(_tfunc: Set<Transition>, state: State[]): State[] {\n let cont = true; // continue\n while (cont) {\n cont = false;\n\n // Find all ε from origin set\n const epsTransitions: Transition[] = Array.from(_tfunc).filter(obj => {\n return state.includes(obj.origin) && obj.input === \"\";\n });\n\n // Add new states, break if no new states found\n for (const _t of epsTransitions) {\n if (!state.includes(_t.dest)) {\n state.push(_t.dest);\n cont = true;\n }\n }\n }\n return state;\n }\n\n // Validate tfunc according to NFA rules\n static validateTFunc(\n _states: Set<State>,\n _paths: Map<State, Set<string>>,\n _tfunc: Set<Transition>,\n _alph: Alphabet\n ): Set<Transition> {\n const newTFunc: Set<Transition> = new Set(); // Will contain only necessary transitions\n\n for (const _t of _tfunc) {\n let skip = false;\n\n // Check for valid states\n if (!_states.has(_t.origin)) {\n console.error(\"Origin state was invalid: %o\", JSON.stringify(_t.origin));\n throw new Error(ErrorCode.ORIGIN_STATE_NOT_FOUND);\n }\n if (!_states.has(_t.dest)) {\n console.error(\"Dest state was invalid: %o\", JSON.stringify(_t.dest));\n throw new Error(ErrorCode.DEST_STATE_NOT_FOUND);\n }\n\n // Check for duplicate before adding\n for (const _checkT of newTFunc) {\n if (_checkT.origin === _t.origin && _checkT.dest === _t.dest && _checkT.input === _t.input) skip = true;\n }\n\n // Map transition to a path and remove on match\n if (!skip) {\n if (_paths.has(_t.origin)) {\n if (this.isValidInputChar(_t.input, _alph)) {\n newTFunc.add(_t);\n } else {\n throw new Error(ErrorCode.INVALID_INPUT_CHAR);\n }\n }\n }\n }\n\n return newTFunc;\n }\n}\n\nexport const createNFA = (\n states: Map<string, State>,\n alphabet: Alphabet,\n transitions: TransitionInput[],\n start: State,\n accepts: Set<State>\n): InstanceType<typeof NFA> => {\n // Convert transition array to Set<NFATransition>\n const _tfunc: Set<NFATransition> = new Set();\n for (const tr of transitions) {\n if (!tr.from || !tr.to || (!tr.input && tr.input !== \"\"))\n throw new Error(ErrorCode.INVALID_TRANSITION_OBJECT);\n const fromVal: State = getOrDefault(states, tr.from, null as unknown as State);\n const toVal: string[] = tr.to.split(\",\");\n\n const destStates: State[] = [];\n toVal.forEach(_dest => {\n destStates.push(getOrDefault(states, _dest, null as unknown as State));\n });\n\n _tfunc.add(new NFATransition(fromVal, destStates, tr.input));\n }\n return new NFA(new Set(states.values()), alphabet, _tfunc, start, accepts);\n};","import { ErrorCode } from \"../globals/errors\";\nimport { instanceOf, getOrDefault } from \"../globals/globals\";\nimport { type FSA } from \"../interfaces/FSA\";\nimport { State, type Transition, Alphabet } from \"../components\";\nimport { type DFA, NFA } from \"../automata\";\nimport { DFAUtils, createDFA, type TransitionInput } from \"./DFAUtils\";\nimport { NFAUtils, createNFA } from \"./NFAUtils\";\n\nexport type { TransitionInput };\n\n/*\n * This class will take an input FSA constructor function\n * to determine which util methods need to be called\n */\nexport const FSAUtils = (() => {\n /*\n * Private methods\n */\n function receiveInputDFA(dfa: InstanceType<typeof DFA>, input: string, state: State): State {\n if (dfa.getAlphabet().sigma.indexOf(input) === -1) throw new Error(ErrorCode.INVALID_INPUT_CHAR);\n if (!dfa.getStates().has(state)) throw new Error(ErrorCode.INPUT_STATE_NOT_FOUND);\n\n const path = Array.from(dfa.getTFunc()).find(obj => {\n return obj.origin === state && obj.input === input;\n });\n\n if (path) return path.dest;\n else throw new Error(ErrorCode.INVALID_TRANSITION_OBJECT);\n }\n\n function receiveInputNFA(nfa: InstanceType<typeof NFA>, input: string, state: State[]): Set<State> {\n let path: Transition[] = [];\n if (nfa.getAlphabet().sigma.indexOf(input) === -1) throw new Error(ErrorCode.INVALID_INPUT_CHAR);\n\n // Empty transitions\n state = populateEpsilons(nfa.getTFunc(), state);\n\n // For ε input, return states already determined\n if (input === \"\") return new Set<State>(state);\n\n // Looking at all origin states, based on input char, determine set of destination states\n for (const _s of state) {\n const _addToPath: Transition[] = Array.from(nfa.getTFunc()).filter(obj => {\n return obj.origin === _s && obj.input === input;\n });\n\n path = path.concat(_addToPath);\n }\n\n const resultArr: State[] = [];\n if (path.length > 1) {\n for (const _s of path) resultArr.push(_s.dest);\n } else if (path.length === 1) {\n resultArr.push(path[0].dest);\n } else {\n // No valid transition found, returning empty set\n return new Set<State>();\n }\n\n // Empty transitions on result set\n const retSet: Set<State> = new Set<State>(populateEpsilons(nfa.getTFunc(), resultArr));\n\n return retSet;\n }\n\n function populateEpsilons(_tfunc: Set<Transition>, state: State[]): State[] {\n return NFAUtils.populateEpsilons(_tfunc, state);\n }\n\n class FSAUtils {\n _type: typeof DFA | typeof NFA;\n\n constructor(v: typeof DFA | typeof NFA) {\n this._type = v;\n }\n\n receiveInput(fsa: FSA, input: string, state: State | State[]): State | Set<State> {\n if (instanceOf(NFA, fsa)) {\n if (state instanceof State) return receiveInputNFA(fsa as InstanceType<typeof NFA>, input, [state]);\n else return receiveInputNFA(fsa as InstanceType<typeof NFA>, input, state);\n } else {\n if (Array.isArray(state)) {\n if (state.length > 1) {\n console.error(\"State array can only contain one state for DFAs\");\n throw new Error(ErrorCode.INVALID_STATE_ARRAY);\n } else {\n state = state[0];\n }\n }\n return receiveInputDFA(fsa as InstanceType<typeof DFA>, input, state);\n }\n }\n\n validateTFunc(\n _states: Set<State>,\n _paths: Map<State, Set<string>>,\n _tfunc: Set<Transition>,\n _alph: Alphabet\n ): Set<Transition> {\n if (this._type === NFA) {\n return NFAUtils.validateTFunc(_states, _paths, _tfunc, _alph);\n } else {\n return DFAUtils.validateTFunc(_states, _paths, _tfunc, _alph);\n }\n }\n\n createPaths(_states: Set<State>, _alph: Alphabet): Map<State, Set<string>> {\n return DFAUtils.createPaths(_states, _alph);\n }\n\n determineStateOrder(\n _links: Map<string, Set<string>>,\n _tfunc: Set<Transition>,\n _states: Set<State>,\n _start: State,\n _accepts: Set<State>\n ): string[] {\n return DFAUtils.determineStateOrder(_links, _tfunc, _states, _start, _accepts);\n }\n }\n\n return FSAUtils;\n})();\n\n// Global export method for creating FSA\nexport const createFSA = (\n states: string | string[],\n alphabet: string | string[],\n transitions: TransitionInput | TransitionInput[],\n start: string,\n accepts: string | string[]\n): FSA => {\n // Type check and conversion for states\n const _states: Map<string, State> = new Map();\n if (typeof states === \"string\") {\n _states.set(states, new State(states));\n } else if (Array.isArray(states)) {\n for (const state of states) {\n if (!_states.has(state)) _states.set(state, new State(state));\n }\n } else {\n throw new TypeError(String(states));\n }\n\n // Convert remaining inputs\n const _alphabet = new Alphabet(alphabet);\n if (typeof start !== \"string\") throw new TypeError(String(start));\n const _start: State = getOrDefault(_states, start, null as unknown as State);\n\n const _accepts: Set<State> = new Set();\n if (typeof accepts === \"string\") {\n if (_states.has(accepts)) _accepts.add(getOrDefault(_states, accepts, null as unknown as State));\n } else if (Array.isArray(accepts)) {\n for (const state of accepts) {\n _accepts.add(getOrDefault(_states, state, null as unknown as State));\n }\n } else {\n throw new TypeError(String(accepts));\n }\n\n /*\n * Determine, based on tfunc structure, whether to create a DFA or NFA\n * If the \"to\" field of any member of the tfunc object is comma separated, or any input\n * char is \"\", then create an NFA\n */\n let transitionList: TransitionInput[];\n if (!Array.isArray(transitions) && typeof transitions === \"object\") transitionList = [transitions];\n else if (Array.isArray(transitions)) transitionList = transitions;\n else throw new TypeError(String(transitions));\n\n for (const tr of transitionList) {\n if (tr.to.indexOf(\",\") != -1 || tr.input === \"\")\n return createNFA(_states, _alphabet, transitionList, _start, _accepts);\n }\n return createDFA(_states, _alphabet, transitionList, _start, _accepts);\n};","import { type FSA } from \"../interfaces/FSA\";\nimport { type State, type Alphabet, type Transition } from \"../components\";\nimport { ErrorCode } from \"../globals/errors\";\nimport { checkStateDuplicates, getOrDefault, isSubsetOf } from \"../globals/globals\";\nimport { FSAUtils } from \"../utils\";\n\nexport class DFA implements FSA {\n // Primary FSA attributes\n #states: Set<State>;\n #alphabet: Alphabet;\n #tfunc: Set<Transition>;\n #start: State;\n #accepts: Set<State>;\n\n // Intermediary attributes used in constructor\n #paths: Map<State, Set<string>>; // States mapped to each member of Σ, will be empty after constructor returns\n #links: Map<string, Set<string>> = new Map(); // State names mapped to their dest state names\n #utils: InstanceType<typeof FSAUtils>;\n\n constructor(\n states: Set<State>,\n alphabet: Alphabet,\n tfunc: Set<Transition>,\n start: State,\n accepts: Set<State> | Record<string, never>\n ) {\n // initialize utils\n this.#utils = new FSAUtils(this.constructor as typeof DFA);\n\n // states validations\n if (checkStateDuplicates(states)) throw new Error(ErrorCode.DUPLICATE_STATE_NAMES);\n this.#states = states;\n\n this.#alphabet = alphabet;\n\n // Create paths map\n this.#paths = this.#utils.createPaths(this.#states, this.#alphabet);\n\n // Start/Accept validations\n if (!states.has(start)) throw new Error(ErrorCode.START_STATE_NOT_FOUND);\n this.#start = start;\n if (Object.keys(accepts).length === 0 && accepts.constructor === Object) accepts = new Set([]); // Allow for {}\n if (!isSubsetOf(accepts as Set<State>, states)) throw new Error(ErrorCode.ACCEPTS_NOT_SUBSET);\n this.#accepts = accepts as Set<State>;\n\n // TFunc validations\n this.#tfunc = this.#utils.validateTFunc(this.#states, this.#paths, tfunc, this.#alphabet);\n }\n\n /*\n * Getters\n */\n getStates(): Set<State> {\n return this.#states;\n }\n getAlphabet(): Alphabet {\n return this.#alphabet;\n }\n getTFunc(): Set<Transition> {\n return this.#tfunc;\n }\n getStartState(): State {\n return this.#start;\n }\n getAcceptStates(): Set<State> {\n return this.#accepts;\n }\n getType(): string {\n return \"DFA\";\n }\n\n generateDigraph(): string {\n // Prep outputs\n const acceptArr: string[] = [];\n for (const state of this.#accepts) acceptArr.push(state.name);\n\n // Duplicate origin/dest combinations should share a line\n const pairs: Map<string, string> = new Map();\n (Object.values([...this.#tfunc]) as Transition[]).map(function (t: Transition) {\n const key: string = t.origin.name + t.dest.name;\n let _input: string = t.input;\n if (_input === \"\") _input = \"ε\";\n if (!pairs.has(key)) {\n pairs.set(key, t.origin.name + \" -> \" + t.dest.name + ' [ label = \"' + _input + '\" ];');\n } else {\n /*\n * To edit an existing line, split out the input(s), convert to number, sort them ascending, and add the new one\n */\n let _line: string = getOrDefault(pairs, key, \"\");\n const _oldinput: string = _line.split('\"')[1];\n const _toAdd: string[] = _oldinput.split(\",\");\n _toAdd.push(_input);\n _toAdd.sort();\n _line = _line.replace('\"' + _oldinput + '\"', '\"' + _toAdd.toString() + '\"');\n pairs.set(key, _line);\n }\n });\n\n // return template literal\n return `digraph fsa {\n ${(Object.values(\n this.#utils.determineStateOrder(this.#links, this.#tfunc, this.#states, this.#start, this.#accepts)\n ) as string[])\n .map(function (str: string) {\n if (acceptArr.indexOf(str) !== -1) return str + \" [shape = doublecircle];\";\n else return str;\n })\n .join(\"\\n\\t\")}\n rankdir=LR;\n node [shape = point ]; qi;\n node [shape = circle];\n qi -> ${this.#start.name};\n ${(Object.values([...pairs]) as [string, string][])\n .map(function ([, val]) {\n return val;\n })\n .join(\"\\n\\t\")}\n }\n `;\n }\n}","import { DFA } from \"./DFA\";\nimport { type State, type Alphabet, type NFATransition, Transition } from \"../components\";\n\nexport class NFA extends DFA {\n constructor(\n states: Set<State>,\n alphabet: Alphabet,\n tfunc: Set<NFATransition>,\n start: State,\n accepts: Set<State> | Record<string, never>\n ) {\n // Implicitly add ε to alphabet\n if (!alphabet.sigma.includes(\"\")) alphabet.sigma.push(\"\");\n\n // If NFATransition has multiple dest states, break them up into separate Transitions\n const expandedTfunc: Set<Transition> = new Set<Transition>();\n for (const _t of tfunc) {\n _t.dest.forEach(_dest => {\n expandedTfunc.add(new Transition(_t.origin, _dest, _t.input));\n });\n }\n\n super(states, alphabet, expandedTfunc, start, accepts);\n }\n\n getType(): string {\n return \"NFA\";\n }\n}","import { type FSA } from \"../interfaces/FSA\";\nimport { State } from \"../components/State\";\nimport { DFA, NFA } from \"../automata\";\nimport { FSAUtils } from \"../utils\";\nimport { ErrorCode } from \"../globals/errors\";\nimport { instanceOf } from \"../globals/globals\";\n\nexport const simulateFSA = (\n w: string | string[],\n fsa: FSA,\n logging: boolean = false,\n returnEndState: boolean = false\n): boolean | string | string[] => {\n if (instanceOf(NFA, fsa)) {\n return simulateNFA(w, fsa as InstanceType<typeof NFA>, new FSAUtils(NFA), logging, returnEndState);\n } else {\n return simulateDFA(w, fsa as InstanceType<typeof DFA>, new FSAUtils(DFA), logging, returnEndState);\n }\n};\n\nexport const stepOnceFSA = (\n w: string,\n qin: string | string[],\n fsa: FSA,\n logging: boolean = false\n): string | string[] => {\n if (typeof w !== \"string\") {\n if (logging) console.error(\"Input w was invalid type: %O\", w);\n throw new TypeError();\n }\n if (typeof qin !== \"string\" && !Array.isArray(qin)) {\n if (logging) console.error(\"Input state was invalid type: %O\", qin);\n throw new TypeError();\n }\n\n // Step once\n if (logging) console.log(\"Input Processing Started\");\n let prevState: State | State[] = [];\n if (typeof qin === \"string\") {\n for (const state of fsa.getStates().values()) {\n if (qin === state.name) prevState = state;\n }\n if (!prevState || (Array.isArray(prevState) && prevState.length === 0))\n throw new Error(ErrorCode.INVALID_STATE_NAME);\n } else {\n prevState = [];\n for (const state of fsa.getStates().values()) {\n if (qin.includes(state.name)) prevState.push(state);\n }\n if (prevState.length !== qin.length) {\n throw new Error(ErrorCode.INVALID_STATE_NAME);\n }\n }\n\n let newState: State | State[];\n if (instanceOf(NFA, fsa)) newState = [...(new FSAUtils(NFA).receiveInput(fsa, w, prevState) as Set<State>)];\n else newState = new FSAUtils(DFA).receiveInput(fsa, w, prevState) as State;\n\n if (logging) console.log(\"%o x '%s' -> %o\", JSON.stringify(prevState), w, JSON.stringify(newState));\n if (logging) console.log(\"Input Processing Ended\");\n\n if (newState instanceof State) return newState.name;\n else {\n const retArray: string[] = [];\n for (const _s of newState) {\n retArray.push(_s.name);\n }\n return retArray;\n }\n};\n\n/*\n * Private methods\n */\nfunction simulateDFA(\n w: string | string[],\n dfa: InstanceType<typeof DFA>,\n utils: InstanceType<typeof FSAUtils>,\n logging: boolean,\n returnEndState: boolean\n): boolean | string {\n if (logging) console.log(\"Beginning DFA Simulation\");\n\n //Accept either string or string[] for w\n if (!Array.isArray(w)) {\n if (typeof w === \"string\") w = [...w];\n else {\n if (logging) console.error(\"Input w was invalid type: %O\", w);\n throw new TypeError();\n }\n }\n\n // Step through the DFA\n if (logging) console.log(\"Input Processing Started\");\n let currentState: State = dfa.getStartState();\n for (const char of w) {\n const prevState: State = currentState;\n currentState = utils.receiveInput(dfa, char, prevState) as State;\n if (logging) console.log(\"%o x '%s' -> %o\", JSON.stringify(prevState), char, JSON.stringify(currentState));\n }\n if (logging) console.log(\"Input Processing Ended\");\n\n // Check for acceptance\n if (dfa.getAcceptStates().has(currentState)) {\n if (logging) console.log(\"Input Accepted!\");\n if (returnEndState) return currentState.name;\n else return true;\n } else {\n if (logging) console.log(\"Input Rejected!\");\n if (returnEndState) return currentState.name;\n else return false;\n }\n}\n\nfunction simulateNFA(\n w: string | string[],\n nfa: InstanceType<typeof NFA>,\n utils: InstanceType<typeof FSAUtils>,\n logging: boolean,\n returnEndState: boolean\n): boolean | string[] {\n if (logging) console.log(\"Beginning NFA Simulation\");\n\n //Accept either string or string[] for w\n if (!(w instanceof Array)) {\n if (typeof w === \"string\") {\n if (w === \"\") w = [\"\"];\n else w = [...w];\n } else {\n if (logging) console.error(\"Input w was invalid type: %O\", w);\n throw new TypeError();\n }\n }\n\n if (logging) console.log(\"Input Processing Started\");\n let currentState: State[] = [nfa.getStartState()];\n for (const char of w) {\n const prevState: State[] = currentState;\n currentState = [...(utils.receiveInput(nfa, char, currentState) as Set<State>)];\n if (logging) console.log(\"%o x '%s' -> %o\", JSON.stringify(prevState), char, JSON.stringify(currentState));\n }\n if (logging) console.log(\"Input Processing Ended\");\n\n /*\n * Check for acceptance or rejection.\n * If returnEndState:\n * If accept, return all final accept states.\n * If reject, return all final states or if no final state return empty string\n */\n const retObj: string[] = [];\n for (const _accState of nfa.getAcceptStates()) {\n if (currentState.includes(_accState)) {\n if (!returnEndState) {\n if (logging) console.log(\"Input Accepted!\");\n return true;\n }\n retObj.push(_accState.name);\n }\n }\n if (retObj.length > 0) {\n if (logging) console.log(\"Input Accepted!\");\n return retObj;\n }\n\n if (logging) console.log(\"Input Rejected!\");\n if (returnEndState) {\n if (currentState.length > 0) {\n for (const _cState of currentState) retObj.push(_cState.name);\n }\n return retObj;\n } else {\n return false;\n }\n}","/**\n * Base class for formal languages characterized by membership testing.\n *\n * L(M) = { w | M accepts w } for automaton-backed subclasses such as\n * {@link RegularLanguage}. Future non-regular language types (e.g. context-free)\n * should extend this class directly, not {@link RegularLanguage}.\n */\nexport abstract class Language {\n abstract contains(word: string): boolean;\n\n /** Alphabet symbols (ε excluded). */\n abstract getAlphabetSymbols(): string[];\n\n /** Discriminator, e.g. `regular` — used before v2 adds further classes. */\n abstract getClassification(): string;\n}","import { type FSA } from \"../interfaces/FSA\";\nimport type { TransitionInput } from \"../utils/DFAUtils\";\n\nexport type FSADefinition = {\n states: string[];\n alphabet: string[];\n transitions: TransitionInput[];\n start: string;\n accepts: string[];\n};\n\nexport function languageAlphabetSymbols(fsa: FSA): string[] {\n return fsa\n .getAlphabet()\n .sigma.filter(symbol => symbol !== \"\")\n .sort();\n}\n\nexport function mergeAlphabets(a: string[], b: string[]): string[] {\n const merged = new Set([...a, ...b]);\n return [...merged].sort();\n}\n\nexport function exportFSADefinition(fsa: FSA): FSADefinition {\n const states = [...fsa.getStates()].map(state => state.name).sort();\n const alphabet = languageAlphabetSymbols(fsa);\n const accepts = [...fsa.getAcceptStates()].map(state => state.name).sort();\n const start = fsa.getStartState().name;\n\n const grouped = new Map<string, Set<string>>();\n for (const transition of fsa.getTFunc()) {\n const key = `${transition.origin.name}\\0${transition.input}`;\n const bucket = grouped.get(key) ?? new Set<string>();\n bucket.add(transition.dest.name);\n grouped.set(key, bucket);\n }\n\n const transitions: TransitionInput[] = [];\n for (const [key, destinations] of grouped) {\n const [from, input] = key.split(\"\\0\");\n transitions.push({\n from,\n to: [...destinations].sort().join(\",\"),\n input,\n });\n }\n\n transitions.sort((left, right) => {\n const byFrom = left.from.localeCompare(right.from);\n if (byFrom !== 0) return byFrom;\n return left.input.localeCompare(right.input);\n });\n\n return { states, alphabet, transitions, start, accepts };\n}\n\nexport function cloneDefinitionWithPrefix(definition: FSADefinition, prefix: string): FSADefinition {\n const mapName = (name: string) => `${prefix}${name}`;\n\n return {\n states: definition.states.map(mapName),\n alphabet: [...definition.alphabet],\n start: mapName(definition.start),\n accepts: definition.accepts.map(mapName),\n transitions: definition.transitions.map(transition => ({\n from: mapName(transition.from),\n to: transition.to\n .split(\",\")\n .map(part => mapName(part.trim()))\n .join(\",\"),\n input: transition.input,\n })),\n };\n}\n\nimport { createFSA } from \"../utils/FSAUtils\";\n\nexport function buildFromDefinition(definition: FSADefinition) {\n return createFSA(\n definition.states,\n definition.alphabet,\n definition.transitions,\n definition.start,\n definition.accepts\n );\n}","import type { TransitionInput } from \"../utils/DFAUtils\";\nimport { cloneDefinitionWithPrefix, mergeAlphabets } from \"./fsaHelpers\";\nimport type { FSADefinition } from \"./fsaHelpers\";\n\nfunction unionDefinitions(left: FSADefinition, right: FSADefinition): FSADefinition {\n const leftClone = cloneDefinitionWithPrefix(left, \"L1_\");\n const rightClone = cloneDefinitionWithPrefix(right, \"L2_\");\n const start = \"union_start\";\n const states = [start, ...leftClone.states, ...rightClone.states];\n const transitions: TransitionInput[] = [\n { from: start, to: leftClone.start, input: \"\" },\n { from: start, to: rightClone.start, input: \"\" },\n ...leftClone.transitions,\n ...rightClone.transitions,\n ];\n\n return {\n states,\n alphabet: mergeAlphabets(leftClone.alphabet, rightClone.alphabet),\n transitions,\n start,\n accepts: [...leftClone.accepts, ...rightClone.accepts],\n };\n}\n\nfunction concatDefinitions(left: FSADefinition, right: FSADefinition): FSADefinition {\n const leftClone = cloneDefinitionWithPrefix(left, \"C1_\");\n const rightClone = cloneDefinitionWithPrefix(right, \"C2_\");\n const bridgeTransitions: TransitionInput[] = [];\n\n for (const accept of leftClone.accepts) {\n bridgeTransitions.push({ from: accept, to: rightClone.start, input: \"\" });\n }\n\n return {\n states: [...leftClone.states, ...rightClone.states],\n alphabet: mergeAlphabets(leftClone.alphabet, rightClone.alphabet),\n transitions: [...leftClone.transitions, ...rightClone.transitions, ...bridgeTransitions],\n start: leftClone.start,\n accepts: [...rightClone.accepts],\n };\n}\n\nfunction kleeneStarDefinition(source: FSADefinition): FSADefinition {\n const clone = cloneDefinitionWithPrefix(source, \"K_\");\n const hub = \"star_hub\";\n const bridgeTransitions: TransitionInput[] = [\n { from: hub, to: clone.start, input: \"\" },\n ];\n\n for (const accept of clone.accepts) {\n bridgeTransitions.push({ from: accept, to: hub, input: \"\" });\n bridgeTransitions.push({ from: accept, to: clone.start, input: \"\" });\n }\n\n return {\n states: [hub, ...clone.states],\n alphabet: [...clone.alphabet],\n transitions: [...clone.transitions, ...bridgeTransitions],\n start: hub,\n accepts: [hub, ...clone.accepts],\n };\n}\n\nexport const LanguageOperations = {\n unionDefinitions,\n concatDefinitions,\n kleeneStarDefinition,\n};","import { type State } from \"../components/State\";\nimport { type FSA } from \"../interfaces/FSA\";\nimport { NFA } from \"../automata\";\nimport { instanceOf } from \"../globals/globals\";\nimport type { TransitionInput } from \"../utils/DFAUtils\";\nimport { languageAlphabetSymbols } from \"./fsaHelpers\";\n\nfunction epsilonClosure(states: State[], fsa: FSA): State[] {\n const closure = new Map<string, State>();\n const stack: State[] = [];\n\n for (const state of states) {\n closure.set(state.name, state);\n stack.push(state);\n }\n\n while (stack.length > 0) {\n const current = stack.pop() as State;\n for (const transition of fsa.getTFunc()) {\n if (transition.origin === current && transition.input === \"\") {\n if (!closure.has(transition.dest.name)) {\n closure.set(transition.dest.name, transition.dest);\n stack.push(transition.dest);\n }\n }\n }\n }\n\n return [...closure.values()].sort((left, right) => left.name.localeCompare(right.name));\n}\n\nfunction move(states: State[], symbol: string, fsa: FSA): State[] {\n const moved = new Map<string, State>();\n\n for (const state of states) {\n for (const transition of fsa.getTFunc()) {\n if (transition.origin === state && transition.input === symbol) {\n moved.set(transition.dest.name, transition.dest);\n }\n }\n }\n\n return [...moved.values()].sort((left, right) => left.name.localeCompare(right.name));\n}\n\nfunction stateSetKey(states: State[]): string {\n return states.map(state => state.name).join(\",\");\n}\n\nexport function subsetConstruction(nfa: FSA): {\n states: string[];\n alphabet: string[];\n transitions: TransitionInput[];\n start: string;\n accepts: string[];\n} {\n if (!instanceOf(NFA, nfa)) {\n throw new TypeError(\"subsetConstruction requires an NFA\");\n }\n\n const alphabet = languageAlphabetSymbols(nfa);\n const acceptNames = new Set([...nfa.getAcceptStates()].map(state => state.name));\n const startSet = epsilonClosure([nfa.getStartState()], nfa);\n\n const setRegistry = new Map<string, string>();\n const setMembers = new Map<string, State[]>();\n const transitions: TransitionInput[] = [];\n\n const nameSet = (states: State[]): string => {\n const key = stateSetKey(states);\n if (!setRegistry.has(key)) {\n const name = `d${setRegistry.size}`;\n setRegistry.set(key, name);\n setMembers.set(name, states);\n }\n return setRegistry.get(key) as string;\n };\n\n const startName = nameSet(startSet);\n const worklist: State[][] = [startSet];\n const seen = new Set<string>([stateSetKey(startSet)]);\n\n let deadAdded = false;\n const deadName = \"dead\";\n\n while (worklist.length > 0) {\n const currentSet = worklist.pop() as State[];\n const currentName = nameSet(currentSet);\n\n for (const symbol of alphabet) {\n const moved = move(currentSet, symbol, nfa);\n const closed = moved.length > 0 ? epsilonClosure(moved, nfa) : [];\n let targetName: string;\n\n if (closed.length === 0) {\n if (!deadAdded) {\n deadAdded = true;\n setMembers.set(deadName, []);\n for (const deadSymbol of alphabet) {\n transitions.push({ from: deadName, to: deadName, input: deadSymbol });\n }\n }\n targetName = deadName;\n } else {\n const key = stateSetKey(closed);\n targetName = nameSet(closed);\n if (!seen.has(key)) {\n seen.add(key);\n worklist.push(closed);\n }\n }\n\n transitions.push({ from: currentName, to: targetName, input: symbol });\n }\n }\n\n const states = [...setMembers.keys()];\n if (deadAdded && !states.includes(deadName)) {\n states.push(deadName);\n }\n\n const accepts = [...setMembers.entries()]\n .filter(([, members]) => members.some(state => acceptNames.has(state.name)))\n .map(([name]) => name);\n\n return {\n states,\n alphabet,\n transitions,\n start: startName,\n accepts,\n };\n}","import { type FSA } from \"../interfaces/FSA\";\nimport { Language } from \"./Language\";\nimport { simulateFSA } from \"../engine/Simulators\";\nimport { ErrorCode } from \"../globals/errors\";\nimport { NFA } from \"../automata\";\nimport { instanceOf } from \"../globals/globals\";\nimport {\n buildFromDefinition,\n exportFSADefinition,\n languageAlphabetSymbols,\n} from \"./fsaHelpers\";\nimport { LanguageOperations } from \"./LanguageOperations\";\nimport { subsetConstruction } from \"./NFAtoDFA\";\n\nexport class RegularLanguage extends Language {\n #automaton: FSA;\n\n constructor(automaton: FSA) {\n super();\n this.#automaton = automaton;\n }\n\n getClassification(): string {\n return \"regular\";\n }\n\n static fromAutomaton(automaton: FSA): RegularLanguage {\n return new RegularLanguage(automaton);\n }\n\n contains(word: string): boolean {\n try {\n return Boolean(simulateFSA(word, this.#automaton));\n } catch (error) {\n if (error instanceof Error && error.message === ErrorCode.INVALID_INPUT_CHAR) {\n return false;\n }\n throw error;\n }\n }\n\n getAutomaton(): FSA {\n return this.#automaton;\n }\n\n getAlphabetSymbols(): string[] {\n return languageAlphabetSymbols(this.#automaton);\n }\n\n toDefinition() {\n return exportFSADefinition(this.#automaton);\n }\n\n union(other: RegularLanguage): RegularLanguage {\n const definition = LanguageOperations.unionDefinitions(this.toDefinition(), other.toDefinition());\n return RegularLanguage.fromAutomaton(buildFromDefinition(definition));\n }\n\n concat(other: RegularLanguage): RegularLanguage {\n const definition = LanguageOperations.concatDefinitions(this.toDefinition(), other.toDefinition());\n return RegularLanguage.fromAutomaton(buildFromDefinition(definition));\n }\n\n kleeneStar(): RegularLanguage {\n const definition = LanguageOperations.kleeneStarDefinition(this.toDefinition());\n return RegularLanguage.fromAutomaton(buildFromDefinition(definition));\n }\n\n toDFA(): RegularLanguage {\n if (!instanceOf(NFA, this.#automaton)) {\n return this;\n }\n\n const definition = subsetConstruction(this.#automaton);\n return RegularLanguage.fromAutomaton(buildFromDefinition(definition));\n }\n}"],"mappings":"oxBAAA,IAAAA,GAAA,GAAAC,GA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,EAAM,aAAa,CAAC,EAChG,OAAOZ,EAAgB,cAAce,EAAoBF,CAAU,CAAC,CACtE,CAEA,OAAOD,EAAyC,CAC9C,IAAMC,EAAaC,EAAmB,kBAAkB,KAAK,aAAa,EAAGF,EAAM,aAAa,CAAC,EACjG,OAAOZ,EAAgB,cAAce,EAAoBF,CAAU,CAAC,CACtE,CAEA,YAA8B,CAC5B,IAAMA,EAAaC,EAAmB,qBAAqB,KAAK,aAAa,CAAC,EAC9E,OAAOd,EAAgB,cAAce,EAAoBF,CAAU,CAAC,CACtE,CAEA,OAAyB,CACvB,GAAI,CAACG,EAAWC,EAAKV,EAAA,KAAKR,EAAU,EAClC,OAAO,KAGT,IAAMc,EAAaK,GAAmBX,EAAA,KAAKR,EAAU,EACrD,OAAOC,EAAgB,cAAce,EAAoBF,CAAU,CAAC,CACtE,CACF,EA7DEd,EAAA,YADK,IAAMoB,EAANnB","names":["demo_bundle_exports","__export","RegularLanguage","createFSA","simulateFSA","stepOnceFSA","ErrorCode","State","name","ErrorCode","count","names","a","b","duplicates","dict","checkStateDuplicates","states","check","item","getOrDefault","map","key","defaultValue","val","instanceOf","ctor","obj","isSubsetOf","subset","superset","Alphabet","sigma","duplicates","count","ErrorCode","NFATransition","origin","dest","input","Transition","origin","dest","input","DFAUtils","_states","_paths","_tfunc","_alph","newTFunc","_t","ErrorCode","pathStateVals","getOrDefault","key","val","state","char","_links","_start","_accepts","statesOrder","tr","linkStateVals","stateArr","deadStates","x","arr","name","nameVal","st","input","createDFA","states","alphabet","transitions","start","accepts","fromVal","toVal","Transition","DFA","NFAUtils","DFAUtils","input","_alph","_tfunc","state","cont","epsTransitions","obj","_t","_states","_paths","newTFunc","skip","ErrorCode","_checkT","createNFA","states","alphabet","transitions","start","accepts","tr","fromVal","getOrDefault","toVal","destStates","_dest","NFATransition","NFA","FSAUtils","receiveInputDFA","dfa","input","state","ErrorCode","path","obj","receiveInputNFA","nfa","populateEpsilons","_s","_addToPath","resultArr","_tfunc","NFAUtils","v","fsa","instanceOf","NFA","State","_states","_paths","_alph","DFAUtils","_links","_start","_accepts","createFSA","states","alphabet","transitions","start","accepts","_alphabet","Alphabet","getOrDefault","transitionList","tr","createNFA","createDFA","_states","_alphabet","_tfunc","_start","_accepts","_paths","_links","_utils","DFA","states","alphabet","tfunc","start","accepts","__privateAdd","__privateSet","FSAUtils","checkStateDuplicates","ErrorCode","__privateGet","isSubsetOf","acceptArr","state","pairs","t","key","_input","_line","getOrDefault","_oldinput","_toAdd","str","val","NFA","DFA","states","alphabet","tfunc","start","accepts","expandedTfunc","_t","_dest","Transition","simulateFSA","w","fsa","logging","returnEndState","instanceOf","NFA","simulateNFA","FSAUtils","simulateDFA","DFA","stepOnceFSA","qin","prevState","state","ErrorCode","newState","State","retArray","_s","dfa","utils","currentState","char","nfa","retObj","_accState","_cState","Language","languageAlphabetSymbols","fsa","symbol","mergeAlphabets","a","b","exportFSADefinition","states","state","alphabet","accepts","start","grouped","transition","key","bucket","transitions","destinations","from","input","left","right","byFrom","cloneDefinitionWithPrefix","definition","prefix","mapName","name","part","buildFromDefinition","createFSA","unionDefinitions","left","right","leftClone","cloneDefinitionWithPrefix","rightClone","start","states","transitions","mergeAlphabets","concatDefinitions","bridgeTransitions","accept","kleeneStarDefinition","source","clone","hub","LanguageOperations","epsilonClosure","states","fsa","closure","stack","state","current","transition","left","right","move","symbol","moved","stateSetKey","subsetConstruction","nfa","instanceOf","NFA","alphabet","languageAlphabetSymbols","acceptNames","startSet","setRegistry","setMembers","transitions","nameSet","key","name","startName","worklist","seen","deadAdded","deadName","currentSet","currentName","closed","targetName","deadSymbol","accepts","members","_automaton","_RegularLanguage","Language","automaton","__privateAdd","__privateSet","word","simulateFSA","__privateGet","error","ErrorCode","languageAlphabetSymbols","exportFSADefinition","other","definition","LanguageOperations","buildFromDefinition","instanceOf","NFA","subsetConstruction","RegularLanguage"]}
|
|
1
|
+
{"version":3,"sources":["../src/demo-bundle.ts","../src/globals/errors.ts","../src/components/State.ts","../src/globals/globals.ts","../src/components/Alphabet.ts","../src/components/NFATransition.ts","../src/components/Transition.ts","../src/utils/DFAUtils.ts","../src/utils/NFAUtils.ts","../src/utils/FSAUtils.ts","../src/automata/DFA.ts","../src/automata/NFA.ts","../src/engine/Simulators.ts"],"sourcesContent":["/**\n * Demo-only IIFE entry — public FSA API for the browser demo.\n * Not exported from package.json \"exports\"; copied to demo/v1.5/vendor only.\n */\nexport { createFSA, simulateFSA, stepOnceFSA } from \"./modules\";","export const ErrorCode: Readonly<Record<string, string>> = Object.freeze({\n DUPLICATE_ALPHABET_VALS: \"E-001\",\n DUPLICATE_STATE_NAMES: \"E-002\",\n INVALID_STATE_NAME: \"E-003\",\n START_STATE_NOT_FOUND: \"E-004\",\n ACCEPTS_NOT_SUBSET: \"E-005\",\n ORIGIN_STATE_NOT_FOUND: \"E-006\",\n DEST_STATE_NOT_FOUND: \"E-007\",\n MISSING_REQUIRED_TRANSITION: \"E-008\",\n INVALID_INPUT_CHAR: \"E-009\",\n INPUT_STATE_NOT_FOUND: \"E-010\",\n INVALID_TRANSITION_OBJECT: \"E-011\",\n DUPLICATE_TRANSITION_OBJECT: \"E-012\",\n INVALID_STATE_ARRAY: \"E-013\"\n});","import { ErrorCode } from \"../globals/errors\";\n\nexport class State {\n name: string;\n\n constructor(name: string) {\n this.name = name;\n if (!this.name) throw new Error(ErrorCode.INVALID_STATE_NAME);\n }\n}","import { type State } from \"../components/State\";\n\n// Count number of instances for each string in an array - returns key/val pairs\nexport const count = (names: string[]): Record<string, number> =>\n names.reduce((a, b) => Object.assign(a, { [b]: (a[b] || 0) + 1 }), {} as Record<string, number>);\n\n// Returns keys with value > 1\nexport const duplicates = (dict: Record<string, number>): string[] =>\n Object.keys(dict).filter(a => dict[a] > 1);\n\n// Equality function for Arrays containing primitive typed values\nexport const compare = (\n a1: Array<string | number | boolean>,\n a2: Array<string | number | boolean>\n): boolean => {\n const s1 = new Set(a1);\n const s2 = new Set(a2);\n return s1.size === s2.size && [...s1].every(v => s2.has(v));\n};\n\n// Check for duplicate keys in a Set<State> input\nexport const checkStateDuplicates = (states: Set<State>): boolean => {\n const check: Set<string> = new Set();\n for (const item of states) {\n if (check.has(item.name)) return true;\n check.add(item.name);\n }\n return false;\n};\n\nexport const getOrDefault = <K, V>(map: Map<K, V>, key: K, defaultValue: V): V => {\n const val = map.get(key);\n return val == null ? defaultValue : val;\n};\n\ntype ConstructorLike<T extends object = object> = abstract new (...args: never[]) => T;\n\nexport const instanceOf = <T extends object>(ctor: ConstructorLike<T>, obj: object): obj is T => {\n return obj instanceof ctor || (Boolean(ctor.name) && ctor.name === obj.constructor.name);\n};\n\nexport const isSubsetOf = <T>(subset: Set<T>, superset: Set<T>): boolean => {\n for (const item of subset) {\n if (!superset.has(item)) return false;\n }\n return true;\n};\n\nexport const isSupersetOf = <T>(superset: Set<T>, subset: Set<T>): boolean => {\n return isSubsetOf(subset, superset);\n};","import { ErrorCode } from \"../globals/errors\";\nimport { count, duplicates } from \"../globals/globals\";\n\nexport class Alphabet {\n sigma: string[];\n\n constructor(sigma: string | string[]) {\n if (!Array.isArray(sigma)) {\n if (typeof sigma === \"string\") sigma = [...sigma];\n else throw new TypeError();\n }\n this.sigma = sigma;\n if (duplicates(count(this.sigma)).length > 0) throw new Error(ErrorCode.DUPLICATE_ALPHABET_VALS);\n }\n}","import { type State } from \"./State\";\n\nexport class NFATransition {\n origin: State;\n dest: State[];\n input: string;\n\n constructor(origin: State, dest: State[], input: string) {\n this.origin = origin;\n this.dest = dest;\n this.input = input;\n }\n}","import { type State } from \"./State\";\n\nexport class Transition {\n origin: State;\n dest: State;\n input: string;\n\n constructor(origin: State, dest: State, input: string) {\n this.origin = origin;\n this.dest = dest;\n this.input = input;\n }\n}","import { ErrorCode } from \"../globals/errors\";\nimport { type State, type Alphabet, Transition } from \"../components\";\nimport { DFA } from \"../automata\";\nimport { getOrDefault } from \"../globals/globals\";\n\nexport class DFAUtils {\n /*\n * Transition function should only contain states in Q, and one transition should exist\n * for each combination of Q x Σ\n */\n static validateTFunc(\n _states: Set<State>,\n _paths: Map<State, Set<string>>,\n _tfunc: Set<Transition>,\n _alph: Alphabet\n ): Set<Transition> {\n const newTFunc: Set<Transition> = new Set(); // Will contain only necessary transitions\n\n for (const _t of _tfunc) {\n // Check for valid states\n if (!_states.has(_t.origin)) {\n console.error(\"Origin state was invalid: %o\", JSON.stringify(_t.origin));\n throw new Error(ErrorCode.ORIGIN_STATE_NOT_FOUND);\n }\n if (!_states.has(_t.dest)) {\n console.error(\"Dest state was invalid: %o\", JSON.stringify(_t.dest));\n throw new Error(ErrorCode.DEST_STATE_NOT_FOUND);\n }\n\n const pathStateVals: Set<string> = getOrDefault(_paths, _t.origin, new Set());\n\n // Map transition to a path and remove on match\n if (this.isValidInputChar(_t.input, _alph)) {\n if (_paths.has(_t.origin) && pathStateVals.has(_t.input)) {\n newTFunc.add(_t);\n pathStateVals.delete(_t.input);\n if (pathStateVals.size === 0) {\n _paths.delete(_t.origin);\n }\n } else {\n throw new Error(ErrorCode.DUPLICATE_TRANSITION_OBJECT);\n }\n } else {\n throw new Error(ErrorCode.INVALID_INPUT_CHAR);\n }\n }\n\n if (_paths.size > 0) {\n console.error(\"Not all FSA paths have a transition specified:\");\n for (const [key, val] of _paths) {\n console.error(\"State %s on input(s): %s\", key.name, [...val].join(\" \"));\n }\n throw new Error(ErrorCode.MISSING_REQUIRED_TRANSITION);\n }\n\n return newTFunc;\n }\n\n static createPaths(_states: Set<State>, _alph: Alphabet): Map<State, Set<string>> {\n const _paths: Map<State, Set<string>> = new Map<State, Set<string>>();\n for (const state of _states) {\n for (const char of _alph.sigma) {\n const pathStateVals: Set<string> = getOrDefault(_paths, state, new Set());\n if (_paths.has(state)) pathStateVals.add(char);\n else _paths.set(state, new Set([char]));\n }\n }\n\n return _paths;\n }\n\n // Determine digraph order based on start state, then following the chain\n static determineStateOrder(\n _links: Map<string, Set<string>>,\n _tfunc: Set<Transition>,\n _states: Set<State>,\n _start: State,\n _accepts: Set<State>\n ): string[] {\n const statesOrder: string[] = []; // Ordered state names for digraph\n\n // Map origin state names to dest state names\n _links = new Map();\n for (const tr of _tfunc) {\n const linkStateVals: Set<string> = getOrDefault(_links, tr.origin.name, new Set());\n if (_links.has(tr.origin.name)) linkStateVals.add(tr.dest.name);\n else _links.set(tr.origin.name, new Set([tr.dest.name]));\n }\n\n // Populate state order\n this.parseLinks(statesOrder, _start.name, _links);\n\n // Check for dead states and reduce FSA if necessary\n const stateArr: string[] = [];\n (Object.values([..._states]) as State[]).map((state: State) => stateArr.push(state.name));\n const deadStates = stateArr.filter(x => !statesOrder.includes(x));\n if (deadStates.length > 0) {\n console.warn(\"Dead states detected, removing them and associated transitions: %O\", deadStates);\n this.removeDeadStates(deadStates, _states, _accepts, _tfunc);\n }\n\n return statesOrder;\n }\n\n // Reduce FSA by removing dead states and associated transitions\n static removeDeadStates(\n deadStates: string[],\n _states: Set<State>,\n _accepts: Set<State>,\n _tfunc: Set<Transition>\n ) {\n // Q\n for (const state of _states) {\n if (deadStates.indexOf(state.name) !== -1) _states.delete(state);\n }\n // F\n for (const state of _accepts) {\n if (deadStates.indexOf(state.name) !== -1) _accepts.delete(state);\n }\n // δ\n for (const tr of _tfunc) {\n if (deadStates.indexOf(tr.origin.name) !== -1 || deadStates.indexOf(tr.dest.name) !== -1) _tfunc.delete(tr);\n }\n }\n\n // Recursively parse graph while adding to an array in order, beginning with q0\n static parseLinks(arr: string[], name: string, _links: Map<string, Set<string>>) {\n arr.push(name);\n const nameVal = getOrDefault(_links, name, new Set<string>());\n for (const st of nameVal) {\n if (arr.indexOf(st) === -1) this.parseLinks(arr, st, _links);\n }\n }\n\n // DFA does not allow empty symbol\n static isValidInputChar(input: string, _alph: Alphabet): boolean {\n if (input === \"\") return false;\n return _alph.sigma.indexOf(input) !== -1;\n }\n}\n\nexport interface TransitionInput {\n from: string;\n to: string;\n input: string;\n}\n\n// Global export method for creating DFA\nexport const createDFA = (\n states: Map<string, State>,\n alphabet: Alphabet,\n transitions: TransitionInput[],\n start: State,\n accepts: Set<State>\n): InstanceType<typeof DFA> => {\n // Convert transition array to Set<Transition>\n const _tfunc: Set<Transition> = new Set();\n for (const tr of transitions) {\n if (!tr.from || !tr.to || !tr.input) throw new Error(ErrorCode.INVALID_TRANSITION_OBJECT);\n const fromVal: State = getOrDefault(states, tr.from, null as unknown as State);\n const toVal: State = getOrDefault(states, tr.to, null as unknown as State);\n _tfunc.add(new Transition(fromVal, toVal, tr.input));\n }\n return new DFA(new Set(states.values()), alphabet, _tfunc, start, accepts);\n};","import { DFAUtils } from \"./DFAUtils\";\nimport { NFA } from \"../automata\";\nimport { type State, type Transition, type Alphabet, NFATransition } from \"../components\";\nimport { ErrorCode } from \"../globals/errors\";\nimport { getOrDefault } from \"../globals/globals\";\nimport type { TransitionInput } from \"./DFAUtils\";\n\nexport class NFAUtils extends DFAUtils {\n // NFA inheritly allows for ε (empty string) transition if specified\n static isValidInputChar(input: string, _alph: Alphabet): boolean {\n return _alph.sigma.indexOf(input) !== -1 || input === \"\";\n }\n\n // Follow all ε transitions and add to `state` (origin states)\n static populateEpsilons(_tfunc: Set<Transition>, state: State[]): State[] {\n let cont = true; // continue\n while (cont) {\n cont = false;\n\n // Find all ε from origin set\n const epsTransitions: Transition[] = Array.from(_tfunc).filter(obj => {\n return state.includes(obj.origin) && obj.input === \"\";\n });\n\n // Add new states, break if no new states found\n for (const _t of epsTransitions) {\n if (!state.includes(_t.dest)) {\n state.push(_t.dest);\n cont = true;\n }\n }\n }\n return state;\n }\n\n // Validate tfunc according to NFA rules\n static validateTFunc(\n _states: Set<State>,\n _paths: Map<State, Set<string>>,\n _tfunc: Set<Transition>,\n _alph: Alphabet\n ): Set<Transition> {\n const newTFunc: Set<Transition> = new Set(); // Will contain only necessary transitions\n\n for (const _t of _tfunc) {\n let skip = false;\n\n // Check for valid states\n if (!_states.has(_t.origin)) {\n console.error(\"Origin state was invalid: %o\", JSON.stringify(_t.origin));\n throw new Error(ErrorCode.ORIGIN_STATE_NOT_FOUND);\n }\n if (!_states.has(_t.dest)) {\n console.error(\"Dest state was invalid: %o\", JSON.stringify(_t.dest));\n throw new Error(ErrorCode.DEST_STATE_NOT_FOUND);\n }\n\n // Check for duplicate before adding\n for (const _checkT of newTFunc) {\n if (_checkT.origin === _t.origin && _checkT.dest === _t.dest && _checkT.input === _t.input) skip = true;\n }\n\n // Map transition to a path and remove on match\n if (!skip) {\n if (_paths.has(_t.origin)) {\n if (this.isValidInputChar(_t.input, _alph)) {\n newTFunc.add(_t);\n } else {\n throw new Error(ErrorCode.INVALID_INPUT_CHAR);\n }\n }\n }\n }\n\n return newTFunc;\n }\n}\n\nexport const createNFA = (\n states: Map<string, State>,\n alphabet: Alphabet,\n transitions: TransitionInput[],\n start: State,\n accepts: Set<State>\n): InstanceType<typeof NFA> => {\n // Convert transition array to Set<NFATransition>\n const _tfunc: Set<NFATransition> = new Set();\n for (const tr of transitions) {\n if (!tr.from || !tr.to || (!tr.input && tr.input !== \"\"))\n throw new Error(ErrorCode.INVALID_TRANSITION_OBJECT);\n const fromVal: State = getOrDefault(states, tr.from, null as unknown as State);\n const toVal: string[] = tr.to.split(\",\");\n\n const destStates: State[] = [];\n toVal.forEach(_dest => {\n destStates.push(getOrDefault(states, _dest, null as unknown as State));\n });\n\n _tfunc.add(new NFATransition(fromVal, destStates, tr.input));\n }\n return new NFA(new Set(states.values()), alphabet, _tfunc, start, accepts);\n};","import { ErrorCode } from \"../globals/errors\";\nimport { instanceOf, getOrDefault } from \"../globals/globals\";\nimport { type FSA } from \"../interfaces/FSA\";\nimport { State, type Transition, Alphabet } from \"../components\";\nimport { type DFA, NFA } from \"../automata\";\nimport { DFAUtils, createDFA, type TransitionInput } from \"./DFAUtils\";\nimport { NFAUtils, createNFA } from \"./NFAUtils\";\n\nexport type { TransitionInput };\n\n/*\n * This class will take an input FSA constructor function\n * to determine which util methods need to be called\n */\nexport const FSAUtils = (() => {\n /*\n * Private methods\n */\n function receiveInputDFA(dfa: InstanceType<typeof DFA>, input: string, state: State): State {\n if (dfa.getAlphabet().sigma.indexOf(input) === -1) throw new Error(ErrorCode.INVALID_INPUT_CHAR);\n if (!dfa.getStates().has(state)) throw new Error(ErrorCode.INPUT_STATE_NOT_FOUND);\n\n const path = Array.from(dfa.getTFunc()).find(obj => {\n return obj.origin === state && obj.input === input;\n });\n\n if (path) return path.dest;\n else throw new Error(ErrorCode.INVALID_TRANSITION_OBJECT);\n }\n\n function receiveInputNFA(nfa: InstanceType<typeof NFA>, input: string, state: State[]): Set<State> {\n let path: Transition[] = [];\n if (nfa.getAlphabet().sigma.indexOf(input) === -1) throw new Error(ErrorCode.INVALID_INPUT_CHAR);\n\n // Empty transitions\n state = populateEpsilons(nfa.getTFunc(), state);\n\n // For ε input, return states already determined\n if (input === \"\") return new Set<State>(state);\n\n // Looking at all origin states, based on input char, determine set of destination states\n for (const _s of state) {\n const _addToPath: Transition[] = Array.from(nfa.getTFunc()).filter(obj => {\n return obj.origin === _s && obj.input === input;\n });\n\n path = path.concat(_addToPath);\n }\n\n const resultArr: State[] = [];\n if (path.length > 1) {\n for (const _s of path) resultArr.push(_s.dest);\n } else if (path.length === 1) {\n resultArr.push(path[0].dest);\n } else {\n // No valid transition found, returning empty set\n return new Set<State>();\n }\n\n // Empty transitions on result set\n const retSet: Set<State> = new Set<State>(populateEpsilons(nfa.getTFunc(), resultArr));\n\n return retSet;\n }\n\n function populateEpsilons(_tfunc: Set<Transition>, state: State[]): State[] {\n return NFAUtils.populateEpsilons(_tfunc, state);\n }\n\n class FSAUtils {\n _type: typeof DFA | typeof NFA;\n\n constructor(v: typeof DFA | typeof NFA) {\n this._type = v;\n }\n\n receiveInput(fsa: FSA, input: string, state: State | State[]): State | Set<State> {\n if (instanceOf(NFA, fsa)) {\n if (state instanceof State) return receiveInputNFA(fsa as InstanceType<typeof NFA>, input, [state]);\n else return receiveInputNFA(fsa as InstanceType<typeof NFA>, input, state);\n } else {\n if (Array.isArray(state)) {\n if (state.length > 1) {\n console.error(\"State array can only contain one state for DFAs\");\n throw new Error(ErrorCode.INVALID_STATE_ARRAY);\n } else {\n state = state[0];\n }\n }\n return receiveInputDFA(fsa as InstanceType<typeof DFA>, input, state);\n }\n }\n\n validateTFunc(\n _states: Set<State>,\n _paths: Map<State, Set<string>>,\n _tfunc: Set<Transition>,\n _alph: Alphabet\n ): Set<Transition> {\n if (this._type === NFA) {\n return NFAUtils.validateTFunc(_states, _paths, _tfunc, _alph);\n } else {\n return DFAUtils.validateTFunc(_states, _paths, _tfunc, _alph);\n }\n }\n\n createPaths(_states: Set<State>, _alph: Alphabet): Map<State, Set<string>> {\n return DFAUtils.createPaths(_states, _alph);\n }\n\n determineStateOrder(\n _links: Map<string, Set<string>>,\n _tfunc: Set<Transition>,\n _states: Set<State>,\n _start: State,\n _accepts: Set<State>\n ): string[] {\n return DFAUtils.determineStateOrder(_links, _tfunc, _states, _start, _accepts);\n }\n }\n\n return FSAUtils;\n})();\n\n// Global export method for creating FSA\nexport const createFSA = (\n states: string | string[],\n alphabet: string | string[],\n transitions: TransitionInput | TransitionInput[],\n start: string,\n accepts: string | string[]\n): FSA => {\n // Type check and conversion for states\n const _states: Map<string, State> = new Map();\n if (typeof states === \"string\") {\n _states.set(states, new State(states));\n } else if (Array.isArray(states)) {\n for (const state of states) {\n if (!_states.has(state)) _states.set(state, new State(state));\n }\n } else {\n throw new TypeError(String(states));\n }\n\n // Convert remaining inputs\n const _alphabet = new Alphabet(alphabet);\n if (typeof start !== \"string\") throw new TypeError(String(start));\n const _start: State = getOrDefault(_states, start, null as unknown as State);\n\n const _accepts: Set<State> = new Set();\n if (typeof accepts === \"string\") {\n if (_states.has(accepts)) _accepts.add(getOrDefault(_states, accepts, null as unknown as State));\n } else if (Array.isArray(accepts)) {\n for (const state of accepts) {\n _accepts.add(getOrDefault(_states, state, null as unknown as State));\n }\n } else {\n throw new TypeError(String(accepts));\n }\n\n /*\n * Determine, based on tfunc structure, whether to create a DFA or NFA\n * If the \"to\" field of any member of the tfunc object is comma separated, or any input\n * char is \"\", then create an NFA\n */\n let transitionList: TransitionInput[];\n if (!Array.isArray(transitions) && typeof transitions === \"object\") transitionList = [transitions];\n else if (Array.isArray(transitions)) transitionList = transitions;\n else throw new TypeError(String(transitions));\n\n for (const tr of transitionList) {\n if (tr.to.indexOf(\",\") != -1 || tr.input === \"\")\n return createNFA(_states, _alphabet, transitionList, _start, _accepts);\n }\n return createDFA(_states, _alphabet, transitionList, _start, _accepts);\n};","import { type FSA } from \"../interfaces/FSA\";\nimport { type State, type Alphabet, type Transition } from \"../components\";\nimport { ErrorCode } from \"../globals/errors\";\nimport { checkStateDuplicates, getOrDefault, isSubsetOf } from \"../globals/globals\";\nimport { FSAUtils } from \"../utils\";\n\nexport class DFA implements FSA {\n // Primary FSA attributes\n #states: Set<State>;\n #alphabet: Alphabet;\n #tfunc: Set<Transition>;\n #start: State;\n #accepts: Set<State>;\n\n // Intermediary attributes used in constructor\n #paths: Map<State, Set<string>>; // States mapped to each member of Σ, will be empty after constructor returns\n #links: Map<string, Set<string>> = new Map(); // State names mapped to their dest state names\n #utils: InstanceType<typeof FSAUtils>;\n\n constructor(\n states: Set<State>,\n alphabet: Alphabet,\n tfunc: Set<Transition>,\n start: State,\n accepts: Set<State> | Record<string, never>\n ) {\n // initialize utils\n this.#utils = new FSAUtils(this.constructor as typeof DFA);\n\n // states validations\n if (checkStateDuplicates(states)) throw new Error(ErrorCode.DUPLICATE_STATE_NAMES);\n this.#states = states;\n\n this.#alphabet = alphabet;\n\n // Create paths map\n this.#paths = this.#utils.createPaths(this.#states, this.#alphabet);\n\n // Start/Accept validations\n if (!states.has(start)) throw new Error(ErrorCode.START_STATE_NOT_FOUND);\n this.#start = start;\n if (Object.keys(accepts).length === 0 && accepts.constructor === Object) accepts = new Set([]); // Allow for {}\n if (!isSubsetOf(accepts as Set<State>, states)) throw new Error(ErrorCode.ACCEPTS_NOT_SUBSET);\n this.#accepts = accepts as Set<State>;\n\n // TFunc validations\n this.#tfunc = this.#utils.validateTFunc(this.#states, this.#paths, tfunc, this.#alphabet);\n }\n\n /*\n * Getters\n */\n getStates(): Set<State> {\n return this.#states;\n }\n getAlphabet(): Alphabet {\n return this.#alphabet;\n }\n getTFunc(): Set<Transition> {\n return this.#tfunc;\n }\n getStartState(): State {\n return this.#start;\n }\n getAcceptStates(): Set<State> {\n return this.#accepts;\n }\n getType(): string {\n return \"DFA\";\n }\n\n generateDigraph(): string {\n // Prep outputs\n const acceptArr: string[] = [];\n for (const state of this.#accepts) acceptArr.push(state.name);\n\n // Duplicate origin/dest combinations should share a line\n const pairs: Map<string, string> = new Map();\n (Object.values([...this.#tfunc]) as Transition[]).map(function (t: Transition) {\n const key: string = t.origin.name + t.dest.name;\n let _input: string = t.input;\n if (_input === \"\") _input = \"ε\";\n if (!pairs.has(key)) {\n pairs.set(key, t.origin.name + \" -> \" + t.dest.name + ' [ label = \"' + _input + '\" ];');\n } else {\n /*\n * To edit an existing line, split out the input(s), convert to number, sort them ascending, and add the new one\n */\n let _line: string = getOrDefault(pairs, key, \"\");\n const _oldinput: string = _line.split('\"')[1];\n const _toAdd: string[] = _oldinput.split(\",\");\n _toAdd.push(_input);\n _toAdd.sort();\n _line = _line.replace('\"' + _oldinput + '\"', '\"' + _toAdd.toString() + '\"');\n pairs.set(key, _line);\n }\n });\n\n // return template literal\n return `digraph fsa {\n ${(Object.values(\n this.#utils.determineStateOrder(this.#links, this.#tfunc, this.#states, this.#start, this.#accepts)\n ) as string[])\n .map(function (str: string) {\n if (acceptArr.indexOf(str) !== -1) return str + \" [shape = doublecircle];\";\n else return str;\n })\n .join(\"\\n\\t\")}\n rankdir=LR;\n node [shape = point ]; qi;\n node [shape = circle];\n qi -> ${this.#start.name};\n ${(Object.values([...pairs]) as [string, string][])\n .map(function ([, val]) {\n return val;\n })\n .join(\"\\n\\t\")}\n }\n `;\n }\n}","import { DFA } from \"./DFA\";\nimport { type State, type Alphabet, type NFATransition, Transition } from \"../components\";\n\nexport class NFA extends DFA {\n constructor(\n states: Set<State>,\n alphabet: Alphabet,\n tfunc: Set<NFATransition>,\n start: State,\n accepts: Set<State> | Record<string, never>\n ) {\n // Implicitly add ε to alphabet\n if (!alphabet.sigma.includes(\"\")) alphabet.sigma.push(\"\");\n\n // If NFATransition has multiple dest states, break them up into separate Transitions\n const expandedTfunc: Set<Transition> = new Set<Transition>();\n for (const _t of tfunc) {\n _t.dest.forEach(_dest => {\n expandedTfunc.add(new Transition(_t.origin, _dest, _t.input));\n });\n }\n\n super(states, alphabet, expandedTfunc, start, accepts);\n }\n\n getType(): string {\n return \"NFA\";\n }\n}","import { type FSA } from \"../interfaces/FSA\";\nimport { State } from \"../components/State\";\nimport { DFA, NFA } from \"../automata\";\nimport { FSAUtils } from \"../utils\";\nimport { ErrorCode } from \"../globals/errors\";\nimport { instanceOf } from \"../globals/globals\";\n\nexport const simulateFSA = (\n w: string | string[],\n fsa: FSA,\n logging: boolean = false,\n returnEndState: boolean = false\n): boolean | string | string[] => {\n if (instanceOf(NFA, fsa)) {\n return simulateNFA(w, fsa as InstanceType<typeof NFA>, new FSAUtils(NFA), logging, returnEndState);\n } else {\n return simulateDFA(w, fsa as InstanceType<typeof DFA>, new FSAUtils(DFA), logging, returnEndState);\n }\n};\n\nexport const stepOnceFSA = (\n w: string,\n qin: string | string[],\n fsa: FSA,\n logging: boolean = false\n): string | string[] => {\n if (typeof w !== \"string\") {\n if (logging) console.error(\"Input w was invalid type: %O\", w);\n throw new TypeError();\n }\n if (typeof qin !== \"string\" && !Array.isArray(qin)) {\n if (logging) console.error(\"Input state was invalid type: %O\", qin);\n throw new TypeError();\n }\n\n // Step once\n if (logging) console.log(\"Input Processing Started\");\n let prevState: State | State[] = [];\n if (typeof qin === \"string\") {\n for (const state of fsa.getStates().values()) {\n if (qin === state.name) prevState = state;\n }\n if (!prevState || (Array.isArray(prevState) && prevState.length === 0))\n throw new Error(ErrorCode.INVALID_STATE_NAME);\n } else {\n prevState = [];\n for (const state of fsa.getStates().values()) {\n if (qin.includes(state.name)) prevState.push(state);\n }\n if (prevState.length !== qin.length) {\n throw new Error(ErrorCode.INVALID_STATE_NAME);\n }\n }\n\n let newState: State | State[];\n if (instanceOf(NFA, fsa)) newState = [...(new FSAUtils(NFA).receiveInput(fsa, w, prevState) as Set<State>)];\n else newState = new FSAUtils(DFA).receiveInput(fsa, w, prevState) as State;\n\n if (logging) console.log(\"%o x '%s' -> %o\", JSON.stringify(prevState), w, JSON.stringify(newState));\n if (logging) console.log(\"Input Processing Ended\");\n\n if (newState instanceof State) return newState.name;\n else {\n const retArray: string[] = [];\n for (const _s of newState) {\n retArray.push(_s.name);\n }\n return retArray;\n }\n};\n\n/*\n * Private methods\n */\nfunction simulateDFA(\n w: string | string[],\n dfa: InstanceType<typeof DFA>,\n utils: InstanceType<typeof FSAUtils>,\n logging: boolean,\n returnEndState: boolean\n): boolean | string {\n if (logging) console.log(\"Beginning DFA Simulation\");\n\n //Accept either string or string[] for w\n if (!Array.isArray(w)) {\n if (typeof w === \"string\") w = [...w];\n else {\n if (logging) console.error(\"Input w was invalid type: %O\", w);\n throw new TypeError();\n }\n }\n\n // Step through the DFA\n if (logging) console.log(\"Input Processing Started\");\n let currentState: State = dfa.getStartState();\n for (const char of w) {\n const prevState: State = currentState;\n currentState = utils.receiveInput(dfa, char, prevState) as State;\n if (logging) console.log(\"%o x '%s' -> %o\", JSON.stringify(prevState), char, JSON.stringify(currentState));\n }\n if (logging) console.log(\"Input Processing Ended\");\n\n // Check for acceptance\n if (dfa.getAcceptStates().has(currentState)) {\n if (logging) console.log(\"Input Accepted!\");\n if (returnEndState) return currentState.name;\n else return true;\n } else {\n if (logging) console.log(\"Input Rejected!\");\n if (returnEndState) return currentState.name;\n else return false;\n }\n}\n\nfunction simulateNFA(\n w: string | string[],\n nfa: InstanceType<typeof NFA>,\n utils: InstanceType<typeof FSAUtils>,\n logging: boolean,\n returnEndState: boolean\n): boolean | string[] {\n if (logging) console.log(\"Beginning NFA Simulation\");\n\n //Accept either string or string[] for w\n if (!(w instanceof Array)) {\n if (typeof w === \"string\") {\n if (w === \"\") w = [\"\"];\n else w = [...w];\n } else {\n if (logging) console.error(\"Input w was invalid type: %O\", w);\n throw new TypeError();\n }\n }\n\n if (logging) console.log(\"Input Processing Started\");\n let currentState: State[] = [nfa.getStartState()];\n for (const char of w) {\n const prevState: State[] = currentState;\n currentState = [...(utils.receiveInput(nfa, char, currentState) as Set<State>)];\n if (logging) console.log(\"%o x '%s' -> %o\", JSON.stringify(prevState), char, JSON.stringify(currentState));\n }\n if (logging) console.log(\"Input Processing Ended\");\n\n /*\n * Check for acceptance or rejection.\n * If returnEndState:\n * If accept, return all final accept states.\n * If reject, return all final states or if no final state return empty string\n */\n const retObj: string[] = [];\n for (const _accState of nfa.getAcceptStates()) {\n if (currentState.includes(_accState)) {\n if (!returnEndState) {\n if (logging) console.log(\"Input Accepted!\");\n return true;\n }\n retObj.push(_accState.name);\n }\n }\n if (retObj.length > 0) {\n if (logging) console.log(\"Input Accepted!\");\n return retObj;\n }\n\n if (logging) console.log(\"Input Rejected!\");\n if (returnEndState) {\n if (currentState.length > 0) {\n for (const _cState of currentState) retObj.push(_cState.name);\n }\n return retObj;\n } else {\n return false;\n }\n}"],"mappings":"owBAAA,IAAAA,GAAA,GAAAC,EAAAD,GAAA,eAAAE,EAAA,gBAAAC,EAAA,gBAAAC,ICAO,IAAMC,EAA8C,OAAO,OAAO,CACvE,wBAAyB,QACzB,sBAAuB,QACvB,mBAAoB,QACpB,sBAAuB,QACvB,mBAAoB,QACpB,uBAAwB,QACxB,qBAAsB,QACtB,4BAA6B,QAC7B,mBAAoB,QACpB,sBAAuB,QACvB,0BAA2B,QAC3B,4BAA6B,QAC7B,oBAAqB,OACvB,CAAC,ECZM,IAAMC,EAAN,KAAY,CAGjB,YAAYC,EAAc,CAExB,GADA,KAAK,KAAOA,EACR,CAAC,KAAK,KAAM,MAAM,IAAI,MAAMC,EAAU,kBAAkB,CAC9D,CACF,ECNO,I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iBAAiB,EACtCC,EAAuBkB,EAAa,KAC5B,GAEhB,CAEA,SAASf,GACPN,EACAuB,EACAH,EACAlB,EACAC,EACoB,CAIpB,GAHID,GAAS,QAAQ,IAAI,0BAA0B,EAG/C,EAAEF,aAAa,OACjB,GAAI,OAAOA,GAAM,SACXA,IAAM,GAAIA,EAAI,CAAC,EAAE,EAChBA,EAAI,CAAC,GAAGA,CAAC,MAEd,OAAIE,GAAS,QAAQ,MAAM,+BAAgCF,CAAC,EACtD,IAAI,UAIVE,GAAS,QAAQ,IAAI,0BAA0B,EACnD,IAAImB,EAAwB,CAACE,EAAI,cAAc,CAAC,EAChD,QAAWD,KAAQtB,EAAG,CACpB,IAAMY,EAAqBS,EAC3BA,EAAe,CAAC,GAAID,EAAM,aAAaG,EAAKD,EAAMD,CAAY,CAAgB,EAC1EnB,GAAS,QAAQ,IAAI,kBAAmB,KAAK,UAAUU,CAAS,EAAGU,EAAM,KAAK,UAAUD,CAAY,CAAC,CAC3G,CACInB,GAAS,QAAQ,IAAI,wBAAwB,EAQjD,IAAMsB,EAAmB,CAAC,EAC1B,QAAWC,KAAaF,EAAI,gBAAgB,EAC1C,GAAIF,EAAa,SAASI,CAAS,EAAG,CACpC,GAAI,CAACtB,EACH,OAAID,GAAS,QAAQ,IAAI,iBAAiB,EACnC,GAETsB,EAAO,KAAKC,EAAU,IAAI,CAC5B,CAEF,GAAID,EAAO,OAAS,EAClB,OAAItB,GAAS,QAAQ,IAAI,iBAAiB,EACnCsB,EAIT,GADItB,GAAS,QAAQ,IAAI,iBAAiB,EACtCC,EAAgB,CAClB,GAAIkB,EAAa,OAAS,EACxB,QAAWK,KAAWL,EAAcG,EAAO,KAAKE,EAAQ,IAAI,EAE9D,OAAOF,CACT,KACE,OAAO,EAEX","names":["demo_bundle_exports","__export","createFSA","simulateFSA","stepOnceFSA","ErrorCode","State","name","ErrorCode","count","names","a","b","duplicates","dict","checkStateDuplicates","states","check","item","getOrDefault","map","key","defaultValue","val","instanceOf","ctor","obj","isSubsetOf","subset","superset","Alphabet","sigma","duplicates","count","ErrorCode","NFATransition","origin","dest","input","Transition","origin","dest","input","DFAUtils","_states","_paths","_tfunc","_alph","newTFunc","_t","ErrorCode","pathStateVals","getOrDefault","key","val","state","char","_links","_start","_accepts","statesOrder","tr","linkStateVals","stateArr","deadStates","x","arr","name","nameVal","st","input","createDFA","states","alphabet","transitions","start","accepts","fromVal","toVal","Transition","DFA","NFAUtils","DFAUtils","input","_alph","_tfunc","state","cont","epsTransitions","obj","_t","_states","_paths","newTFunc","skip","ErrorCode","_checkT","createNFA","states","alphabet","transitions","start","accepts","tr","fromVal","getOrDefault","toVal","destStates","_dest","NFATransition","NFA","FSAUtils","receiveInputDFA","dfa","input","state","ErrorCode","path","obj","receiveInputNFA","nfa","populateEpsilons","_s","_addToPath","resultArr","_tfunc","NFAUtils","v","fsa","instanceOf","NFA","State","_states","_paths","_alph","DFAUtils","_links","_start","_accepts","createFSA","states","alphabet","transitions","start","accepts","_alphabet","Alphabet","getOrDefault","transitionList","tr","createNFA","createDFA","_states","_alphabet","_tfunc","_start","_accepts","_paths","_links","_utils","DFA","states","alphabet","tfunc","start","accepts","__privateAdd","__privateSet","FSAUtils","checkStateDuplicates","ErrorCode","__privateGet","isSubsetOf","acceptArr","state","pairs","t","key","_input","_line","getOrDefault","_oldinput","_toAdd","str","val","NFA","DFA","states","alphabet","tfunc","start","accepts","expandedTfunc","_t","_dest","Transition","simulateFSA","w","fsa","logging","returnEndState","instanceOf","NFA","simulateNFA","FSAUtils","simulateDFA","DFA","stepOnceFSA","qin","prevState","state","ErrorCode","newState","State","retArray","_s","dfa","utils","currentState","char","nfa","retObj","_accState","_cState"]}
|
package/lib/demo-bundle.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
"use strict";var fasJs=(()=>{var
|
|
2
|
-
${Object.values(
|
|
1
|
+
"use strict";var fasJs=(()=>{var C=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var W=Object.prototype.hasOwnProperty;var k=o=>{throw TypeError(o)};var X=(o,t)=>{for(var r in t)C(o,r,{get:t[r],enumerable:!0})},Z=(o,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Y(t))!W.call(o,s)&&s!==r&&C(o,s,{get:()=>t[s],enumerable:!(i=Q(t,s))||i.enumerable});return o};var q=o=>Z(C({},"__esModule",{value:!0}),o);var j=(o,t,r)=>t.has(o)||k("Cannot "+r);var f=(o,t,r)=>(j(o,t,"read from private field"),r?r.call(o):t.get(o)),T=(o,t,r)=>t.has(o)?k("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(o):t.set(o,r),h=(o,t,r,i)=>(j(o,t,"write to private field"),i?i.call(o,r):t.set(o,r),r);var rt={};X(rt,{createFSA:()=>V,simulateFSA:()=>L,stepOnceFSA:()=>M});var p=Object.freeze({DUPLICATE_ALPHABET_VALS:"E-001",DUPLICATE_STATE_NAMES:"E-002",INVALID_STATE_NAME:"E-003",START_STATE_NOT_FOUND:"E-004",ACCEPTS_NOT_SUBSET:"E-005",ORIGIN_STATE_NOT_FOUND:"E-006",DEST_STATE_NOT_FOUND:"E-007",MISSING_REQUIRED_TRANSITION:"E-008",INVALID_INPUT_CHAR:"E-009",INPUT_STATE_NOT_FOUND:"E-010",INVALID_TRANSITION_OBJECT:"E-011",DUPLICATE_TRANSITION_OBJECT:"E-012",INVALID_STATE_ARRAY:"E-013"});var m=class{constructor(t){if(this.name=t,!this.name)throw new Error(p.INVALID_STATE_NAME)}};var J=o=>o.reduce((t,r)=>Object.assign(t,{[r]:(t[r]||0)+1}),{}),B=o=>Object.keys(o).filter(t=>o[t]>1);var H=o=>{let t=new Set;for(let r of o){if(t.has(r.name))return!0;t.add(r.name)}return!1},u=(o,t,r)=>{let i=o.get(t);return i??r},D=(o,t)=>t instanceof o||!!o.name&&o.name===t.constructor.name,z=(o,t)=>{for(let r of o)if(!t.has(r))return!1;return!0};var v=class{constructor(t){if(!Array.isArray(t))if(typeof t=="string")t=[...t];else throw new TypeError;if(this.sigma=t,B(J(this.sigma)).length>0)throw new Error(p.DUPLICATE_ALPHABET_VALS)}};var U=class{constructor(t,r,i){this.origin=t,this.dest=r,this.input=i}};var _=class{constructor(t,r,i){this.origin=t,this.dest=r,this.input=i}};var d=class{static validateTFunc(t,r,i,s){let e=new Set;for(let n of i){if(!t.has(n.origin))throw console.error("Origin state was invalid: %o",JSON.stringify(n.origin)),new Error(p.ORIGIN_STATE_NOT_FOUND);if(!t.has(n.dest))throw console.error("Dest state was invalid: %o",JSON.stringify(n.dest)),new Error(p.DEST_STATE_NOT_FOUND);let a=u(r,n.origin,new Set);if(this.isValidInputChar(n.input,s))if(r.has(n.origin)&&a.has(n.input))e.add(n),a.delete(n.input),a.size===0&&r.delete(n.origin);else throw new Error(p.DUPLICATE_TRANSITION_OBJECT);else throw new Error(p.INVALID_INPUT_CHAR)}if(r.size>0){console.error("Not all FSA paths have a transition specified:");for(let[n,a]of r)console.error("State %s on input(s): %s",n.name,[...a].join(" "));throw new Error(p.MISSING_REQUIRED_TRANSITION)}return e}static createPaths(t,r){let i=new Map;for(let s of t)for(let e of r.sigma){let n=u(i,s,new Set);i.has(s)?n.add(e):i.set(s,new Set([e]))}return i}static determineStateOrder(t,r,i,s,e){let n=[];t=new Map;for(let c of r){let l=u(t,c.origin.name,new Set);t.has(c.origin.name)?l.add(c.dest.name):t.set(c.origin.name,new Set([c.dest.name]))}this.parseLinks(n,s.name,t);let a=[];Object.values([...i]).map(c=>a.push(c.name));let S=a.filter(c=>!n.includes(c));return S.length>0&&(console.warn("Dead states detected, removing them and associated transitions: %O",S),this.removeDeadStates(S,i,e,r)),n}static removeDeadStates(t,r,i,s){for(let e of r)t.indexOf(e.name)!==-1&&r.delete(e);for(let e of i)t.indexOf(e.name)!==-1&&i.delete(e);for(let e of s)(t.indexOf(e.origin.name)!==-1||t.indexOf(e.dest.name)!==-1)&&s.delete(e)}static parseLinks(t,r,i){t.push(r);let s=u(i,r,new Set);for(let e of s)t.indexOf(e)===-1&&this.parseLinks(t,e,i)}static isValidInputChar(t,r){return t===""?!1:r.sigma.indexOf(t)!==-1}},G=(o,t,r,i,s)=>{let e=new Set;for(let n of r){if(!n.from||!n.to||!n.input)throw new Error(p.INVALID_TRANSITION_OBJECT);let a=u(o,n.from,null),S=u(o,n.to,null);e.add(new _(a,S,n.input))}return new g(new Set(o.values()),t,e,i,s)};var b=class extends d{static isValidInputChar(t,r){return r.sigma.indexOf(t)!==-1||t===""}static populateEpsilons(t,r){let i=!0;for(;i;){i=!1;let s=Array.from(t).filter(e=>r.includes(e.origin)&&e.input==="");for(let e of s)r.includes(e.dest)||(r.push(e.dest),i=!0)}return r}static validateTFunc(t,r,i,s){let e=new Set;for(let n of i){let a=!1;if(!t.has(n.origin))throw console.error("Origin state was invalid: %o",JSON.stringify(n.origin)),new Error(p.ORIGIN_STATE_NOT_FOUND);if(!t.has(n.dest))throw console.error("Dest state was invalid: %o",JSON.stringify(n.dest)),new Error(p.DEST_STATE_NOT_FOUND);for(let S of e)S.origin===n.origin&&S.dest===n.dest&&S.input===n.input&&(a=!0);if(!a&&r.has(n.origin))if(this.isValidInputChar(n.input,s))e.add(n);else throw new Error(p.INVALID_INPUT_CHAR)}return e}},K=(o,t,r,i,s)=>{let e=new Set;for(let n of r){if(!n.from||!n.to||!n.input&&n.input!=="")throw new Error(p.INVALID_TRANSITION_OBJECT);let a=u(o,n.from,null),S=n.to.split(","),c=[];S.forEach(l=>{c.push(u(o,l,null))}),e.add(new U(a,c,n.input))}return new A(new Set(o.values()),t,e,i,s)};var I=(()=>{function o(s,e,n){if(s.getAlphabet().sigma.indexOf(e)===-1)throw new Error(p.INVALID_INPUT_CHAR);if(!s.getStates().has(n))throw new Error(p.INPUT_STATE_NOT_FOUND);let a=Array.from(s.getTFunc()).find(S=>S.origin===n&&S.input===e);if(a)return a.dest;throw new Error(p.INVALID_TRANSITION_OBJECT)}function t(s,e,n){let a=[];if(s.getAlphabet().sigma.indexOf(e)===-1)throw new Error(p.INVALID_INPUT_CHAR);if(n=r(s.getTFunc(),n),e==="")return new Set(n);for(let l of n){let $=Array.from(s.getTFunc()).filter(P=>P.origin===l&&P.input===e);a=a.concat($)}let S=[];if(a.length>1)for(let l of a)S.push(l.dest);else if(a.length===1)S.push(a[0].dest);else return new Set;return new Set(r(s.getTFunc(),S))}function r(s,e){return b.populateEpsilons(s,e)}class i{constructor(e){this._type=e}receiveInput(e,n,a){if(D(A,e))return a instanceof m?t(e,n,[a]):t(e,n,a);if(Array.isArray(a)){if(a.length>1)throw console.error("State array can only contain one state for DFAs"),new Error(p.INVALID_STATE_ARRAY);a=a[0]}return o(e,n,a)}validateTFunc(e,n,a,S){return this._type===A?b.validateTFunc(e,n,a,S):d.validateTFunc(e,n,a,S)}createPaths(e,n){return d.createPaths(e,n)}determineStateOrder(e,n,a,S,c){return d.determineStateOrder(e,n,a,S,c)}}return i})(),V=(o,t,r,i,s)=>{let e=new Map;if(typeof o=="string")e.set(o,new m(o));else if(Array.isArray(o))for(let l of o)e.has(l)||e.set(l,new m(l));else throw new TypeError(String(o));let n=new v(t);if(typeof i!="string")throw new TypeError(String(i));let a=u(e,i,null),S=new Set;if(typeof s=="string")e.has(s)&&S.add(u(e,s,null));else if(Array.isArray(s))for(let l of s)S.add(u(e,l,null));else throw new TypeError(String(s));let c;if(!Array.isArray(r)&&typeof r=="object")c=[r];else if(Array.isArray(r))c=r;else throw new TypeError(String(r));for(let l of c)if(l.to.indexOf(",")!=-1||l.input==="")return K(e,n,c,a,S);return G(e,n,c,a,S)};var y,w,E,N,O,x,R,F,g=class{constructor(t,r,i,s,e){T(this,y);T(this,w);T(this,E);T(this,N);T(this,O);T(this,x);T(this,R,new Map);T(this,F);if(h(this,F,new I(this.constructor)),H(t))throw new Error(p.DUPLICATE_STATE_NAMES);if(h(this,y,t),h(this,w,r),h(this,x,f(this,F).createPaths(f(this,y),f(this,w))),!t.has(s))throw new Error(p.START_STATE_NOT_FOUND);if(h(this,N,s),Object.keys(e).length===0&&e.constructor===Object&&(e=new Set([])),!z(e,t))throw new Error(p.ACCEPTS_NOT_SUBSET);h(this,O,e),h(this,E,f(this,F).validateTFunc(f(this,y),f(this,x),i,f(this,w)))}getStates(){return f(this,y)}getAlphabet(){return f(this,w)}getTFunc(){return f(this,E)}getStartState(){return f(this,N)}getAcceptStates(){return f(this,O)}getType(){return"DFA"}generateDigraph(){let t=[];for(let i of f(this,O))t.push(i.name);let r=new Map;return Object.values([...f(this,E)]).map(function(i){let s=i.origin.name+i.dest.name,e=i.input;if(e===""&&(e="\u03B5"),!r.has(s))r.set(s,i.origin.name+" -> "+i.dest.name+' [ label = "'+e+'" ];');else{let n=u(r,s,""),a=n.split('"')[1],S=a.split(",");S.push(e),S.sort(),n=n.replace('"'+a+'"','"'+S.toString()+'"'),r.set(s,n)}}),`digraph fsa {
|
|
2
|
+
${Object.values(f(this,F).determineStateOrder(f(this,R),f(this,E),f(this,y),f(this,N),f(this,O))).map(function(i){return t.indexOf(i)!==-1?i+" [shape = doublecircle];":i}).join(`
|
|
3
3
|
`)}
|
|
4
4
|
rankdir=LR;
|
|
5
5
|
node [shape = point ]; qi;
|
|
6
6
|
node [shape = circle];
|
|
7
|
-
qi -> ${
|
|
8
|
-
${Object.values([...
|
|
7
|
+
qi -> ${f(this,N).name};
|
|
8
|
+
${Object.values([...r]).map(function([,i]){return i}).join(`
|
|
9
9
|
`)}
|
|
10
10
|
}
|
|
11
|
-
`}};
|
|
11
|
+
`}};y=new WeakMap,w=new WeakMap,E=new WeakMap,N=new WeakMap,O=new WeakMap,x=new WeakMap,R=new WeakMap,F=new WeakMap;var A=class extends g{constructor(t,r,i,s,e){r.sigma.includes("")||r.sigma.push("");let n=new Set;for(let a of i)a.dest.forEach(S=>{n.add(new _(a.origin,S,a.input))});super(t,r,n,s,e)}getType(){return"NFA"}};var L=(o,t,r=!1,i=!1)=>D(A,t)?et(o,t,new I(A),r,i):tt(o,t,new I(g),r,i),M=(o,t,r,i=!1)=>{if(typeof o!="string")throw i&&console.error("Input w was invalid type: %O",o),new TypeError;if(typeof t!="string"&&!Array.isArray(t))throw i&&console.error("Input state was invalid type: %O",t),new TypeError;i&&console.log("Input Processing Started");let s=[];if(typeof t=="string"){for(let n of r.getStates().values())t===n.name&&(s=n);if(!s||Array.isArray(s)&&s.length===0)throw new Error(p.INVALID_STATE_NAME)}else{s=[];for(let n of r.getStates().values())t.includes(n.name)&&s.push(n);if(s.length!==t.length)throw new Error(p.INVALID_STATE_NAME)}let e;if(D(A,r)?e=[...new I(A).receiveInput(r,o,s)]:e=new I(g).receiveInput(r,o,s),i&&console.log("%o x '%s' -> %o",JSON.stringify(s),o,JSON.stringify(e)),i&&console.log("Input Processing Ended"),e instanceof m)return e.name;{let n=[];for(let a of e)n.push(a.name);return n}};function tt(o,t,r,i,s){if(i&&console.log("Beginning DFA Simulation"),!Array.isArray(o))if(typeof o=="string")o=[...o];else throw i&&console.error("Input w was invalid type: %O",o),new TypeError;i&&console.log("Input Processing Started");let e=t.getStartState();for(let n of o){let a=e;e=r.receiveInput(t,n,a),i&&console.log("%o x '%s' -> %o",JSON.stringify(a),n,JSON.stringify(e))}return i&&console.log("Input Processing Ended"),t.getAcceptStates().has(e)?(i&&console.log("Input Accepted!"),s?e.name:!0):(i&&console.log("Input Rejected!"),s?e.name:!1)}function et(o,t,r,i,s){if(i&&console.log("Beginning NFA Simulation"),!(o instanceof Array))if(typeof o=="string")o===""?o=[""]:o=[...o];else throw i&&console.error("Input w was invalid type: %O",o),new TypeError;i&&console.log("Input Processing Started");let e=[t.getStartState()];for(let a of o){let S=e;e=[...r.receiveInput(t,a,e)],i&&console.log("%o x '%s' -> %o",JSON.stringify(S),a,JSON.stringify(e))}i&&console.log("Input Processing Ended");let n=[];for(let a of t.getAcceptStates())if(e.includes(a)){if(!s)return i&&console.log("Input Accepted!"),!0;n.push(a.name)}if(n.length>0)return i&&console.log("Input Accepted!"),n;if(i&&console.log("Input Rejected!"),s){if(e.length>0)for(let a of e)n.push(a.name);return n}else return!1}return q(rt);})();
|
|
12
12
|
//# sourceMappingURL=demo-bundle.global.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fas-js",
|
|
3
3
|
"description": "Finate State Automata JS Solutions",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.6.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.cjs",
|
|
7
7
|
"module": "./lib/index.js",
|
|
@@ -25,14 +25,20 @@
|
|
|
25
25
|
"prebuild": "node scripts/prebuild.mjs",
|
|
26
26
|
"postbuild": "node scripts/postbuild.mjs",
|
|
27
27
|
"clean": "node scripts/prebuild.mjs",
|
|
28
|
-
"prepublishOnly": "npm run build && npm test",
|
|
28
|
+
"prepublishOnly": "npm run guard:theorem && npm run build && npm test",
|
|
29
29
|
"typecheck": "tsc --noEmit",
|
|
30
30
|
"lint": "eslint src",
|
|
31
31
|
"lint:fix": "eslint src --fix",
|
|
32
|
+
"guard:theorem": "node scripts/check-theorem-annotations.mjs",
|
|
33
|
+
"free-port": "node scripts/free-port.mjs 3200",
|
|
34
|
+
"preserve:demo": "node scripts/free-port.mjs 3200",
|
|
32
35
|
"serve:demo": "node scripts/serve-demo.mjs",
|
|
33
36
|
"test:demo": "npm run build && cross-env NODE_OPTIONS=--import=tsx mocha \"test/demo.spec.js\"",
|
|
34
|
-
"test": "
|
|
37
|
+
"test:presets": "cross-env NODE_OPTIONS=--import=tsx mocha \"test/demo-presets-golden.spec.js\"",
|
|
38
|
+
"test:languages": "cross-env NODE_OPTIONS=--import=tsx mocha \"test/languages.spec.js\"",
|
|
39
|
+
"test": "npm run guard:theorem && npm run typecheck && npm run lint && npm run build && npm run check:security && cross-env NODE_OPTIONS=--import=tsx c8 mocha \"test/**/*.spec.js\"",
|
|
35
40
|
"audit:ci": "npm audit --audit-level=high",
|
|
41
|
+
"check:security": "node scripts/check-public-api.mjs && node scripts/check-npm-pack.mjs",
|
|
36
42
|
"git:reset": "git reset --hard HEAD && git clean -fd",
|
|
37
43
|
"npm:reinstall": "node scripts/reinstall.js"
|
|
38
44
|
},
|
|
@@ -78,5 +84,10 @@
|
|
|
78
84
|
],
|
|
79
85
|
"engines": {
|
|
80
86
|
"node": ">=18"
|
|
87
|
+
},
|
|
88
|
+
"overrides": {
|
|
89
|
+
"diff": "^8.0.3",
|
|
90
|
+
"serialize-javascript": "^7.0.5",
|
|
91
|
+
"esbuild": "^0.28.1"
|
|
81
92
|
}
|
|
82
93
|
}
|