类 NFA


  • public class NFA
    extends java.lang.Object
    The NFA class provides a data type for creating a nondeterministic finite state automaton (NFA) from a regular expression and testing whether a given string is matched by that regular expression. It supports the following operations: concatenation, closure, binary or, and parentheses. It does not support mutiway or, character classes, metacharacters (either in the text or pattern), capturing capabilities, greedy or relucantant modifiers, and other features in industrial-strength implementations such as Pattern and Matcher.

    This implementation builds the NFA using a digraph and a stack and simulates the NFA using digraph search (see the textbook for details). The constructor takes time proportional to m, where m is the number of characters in the regular expression. The recognizes method takes time proportional to m n, where n is the number of characters in the text.

    For additional documentation, see Section 5.4 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

    • 构造器概要

      构造器 
      构造器 说明
      NFA​(java.lang.String regexp)
      Initializes the NFA from the specified regular expression.
    • 方法概要

      修饰符和类型 方法 说明
      static void main​(java.lang.String[] args)
      Unit tests the NFA data type.
      boolean recognizes​(java.lang.String txt)
      Returns true if the text is matched by the regular expression.
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 构造器详细资料

      • NFA

        public NFA​(java.lang.String regexp)
        Initializes the NFA from the specified regular expression.
        参数:
        regexp - the regular expression
    • 方法详细资料

      • recognizes

        public boolean recognizes​(java.lang.String txt)
        Returns true if the text is matched by the regular expression.
        参数:
        txt - the text
        返回:
        true if the text is matched by the regular expression, false otherwise
      • main

        public static void main​(java.lang.String[] args)
        Unit tests the NFA data type.
        参数:
        args - the command-line arguments