/Regex-to-NFA-DFA

Convert regex to NFA, DFA and minimize DFA

Primary LanguageJupyter Notebook

Regex to NFA and DFA

The Regex to NFA, DFA, and Minimized DFA Converter is a Python program that converts regular expressions into non-deterministic finite automata (NFA), deterministic finite automata (DFA), and minimized deterministic finite automata (Min DFA). The program reads a regular expression and creates an NFA that recognizes the language defined by the regular expression. It then converts the NFA to a DFA, and finally, it minimizes the DFA to create a Min DFA that is equivalent to the original NFA.

⚒️ Supported Rules

  • Alteration: The | character can be used to denote alternation between two expressions. For example: A|B.
  • Concatenation: Expressions can be concatenated together to form a new expression. For example: AB.
  • 1 or More: The + character can be used to indicate that the preceding expression must occur one or more times. For example: A+.
  • 0 or More: The * character can be used to indicate that the preceding expression can occur zero or more times. For example: A*.
  • Optional: The ? character can be used to indicate that the preceding expression is optional. For example: A?.
  • ORing (aka Char/Num classes): Expressions can be ORed together using brackets and the | character to form character or number classes. For example: [ABC] or [345].
  • Ranges: Ranges of characters or numbers can be defined using brackets and the - character. For example: [0-9] or [a-z].
  • Brackets or Grouping: Expressions can be grouped using parentheses to control the order of operations. For example: (ABD)+.

🏁 Get started

git clone https://github.com/gaserashraf/Regex-to-NFA-DFA.git
cd Regex-to-NFA-DFA
$ pip install graphviz
run jupyter notebook

💻 Built using

  • python

⚙️ Project pipeline

alt text

📷 Demo

For regex: ab(b|c)*d+

AST:

s1

NFA:

s1

DFA:

s2

Minimized DFA:

s3