Formal Definition of a Finite Automaton

node v10.24.1
version: 1.0.0
endpointsharetweet
// the five tuples const Q = states = new Set(['q1', 'q2', 'q3']) const Sigma = alphabet = new Set(['0', '1']) const delta = transitionFunction = (state, symbol) => { const table = { 'q1': { '0': 'q1', '1': 'q2' }, 'q2': { '1': 'q2', '0': 'q3' }, 'q3': { '1': 'q2', '0': 'q2' } } return table[state][symbol] } const q0 = startState = 'q1' const F = finalStates = new Set(['q2'])
const check = (string) => { let arr = string.split("") let currState = q0 for (let i = 0; i < arr.length; i++ ) { currState = delta(currState, arr[i]) } return F.has(currState) ? 'accept' : "reject" }
check('100')
check('1010')
Loading…

no comments

    sign in to comment