Class NFA

java.lang.Object
icyllis.arc3d.compiler.lex.NFA

public class NFA extends Object
A nondeterministic finite automaton for matching regular expressions. The NFA is initialized with a number of regular expressions, and then matches a string against all of them simultaneously.
  • Constructor Summary

    Constructors
    Constructor
    Description
    NFA()
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    add(NFAState state)
    Adds a new state to the NFA, returning its index.
    void
    add(RegexNode node)
    Adds a new regular expression to the set of expressions matched by this automaton.
    get(int index)
    Gets a NFA state from its index.
    int
    Matches a string against all of the regexes added to this NFA.
    it.unimi.dsi.fastutil.ints.IntList
    replace(int index, it.unimi.dsi.fastutil.ints.IntList shadow)
    When we transition to the NFA state which is given by index, we instead transition to all of the shadow states.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • NFA

      public NFA()
  • Method Details

    • add

      public void add(@Nonnull RegexNode node)
      Adds a new regular expression to the set of expressions matched by this automaton.
    • add

      public int add(NFAState state)
      Adds a new state to the NFA, returning its index.
    • get

      public NFAState get(int index)
      Gets a NFA state from its index.
    • replace

      public it.unimi.dsi.fastutil.ints.IntList replace(int index, it.unimi.dsi.fastutil.ints.IntList shadow)
      When we transition to the NFA state which is given by index, we instead transition to all of the shadow states.
    • match

      public int match(@Nonnull String s)
      Matches a string against all of the regexes added to this NFA. Returns the index of the first (in addRegex order) matching expression, or -1 if no match. This is relatively slow and used only for debugging purposes; the NFA should be converted to a DFA before actual use.