Click or drag to resize
NFA Class

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 Regexand Match.

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.

Inheritance Hierarchy
SystemObject
  Algs4NetNFA

Namespace: Algs4Net
Assembly: Algs4Net (in Algs4Net.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public class NFA

The NFA type exposes the following members.

Constructors
  NameDescription
Public methodNFA
Initializes the NFA from the specified regular expression.
Top
Methods
  NameDescription
Public methodStatic memberMainTest
Demo test the NFA data type.
Public methodRecognizes
Returns true if the text is matched by the regular expression.
Top
Remarks

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

This class is a C# port from the original Java class NFA implementation by the respective authors.

See Also