1.0.0 • Published 6 years ago

automatamata v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
6 years ago

automatamata

Javascript classes for working with DFA's and NFA's

DFA (Deterministic Finite Automata)

The main attraction. Defined using a definition object, which has the following structure:

const definition = {
  language: ["0", "1"], // an array of strings representing symbols in the language
  initialState: "a", // the starting state
  acceptingStates: ["b"], // an array of strings representing the accepting states
  states: {
    a: {
        "0": "a",
        "1": "b"
    },
    b: {
      "0": "b",
      "1": "b"
    }
  } // an object describing state transitions
}

DFA is constructed as follows:

const dfa = new DFA(definition)

The definition object is validated when the dfa is constructed, and an error is thrown if it is invalid.

  • accepts - true if the given string is accepted by the DFA
  • languageIsEmpty - true if the language defined by the DFA is empty - that is, none of the accepting states are reachable from the starting state
  • toDiGraph - construct a digraph from the DFA's state transitions