Reinforz / fauton

An ecosystem of packages to work with automaton and parsers (dfa/nfa/e-nfa/regex/cfg/pda)

Home Page:http://docs.fauton.xyz

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Check that for dfa all transitions must have all the alphabets

Devorein opened this issue · comments

const { DeterministicFiniteAutomaton } = require('fauton');

const startsWithBC = new DeterministicFiniteAutomaton(
	(inputString) => inputString.startsWith('bc'),
	{
		alphabets: ['a', 'b'],
		transitions: {
			A: ['A'],
			B: [null, 'B'],
		},
	}
);

The DFA accepts 2 alphabets a and b but in the transition map for state A, it only indicates where to go when we encounter the symbol a but not for b. This should not be the case for dfa. Even in the 2nd state B, it's gonna transition to null state for symbol a, which is also a violation for DFA. Every state must have an array of state strings that have an equal length as that of the alphabets to ensure we cover all cases. An error should be thrown in this regard