A powerful Java engine for processing Finite State Automata and Regular Expressions.
Autogex is a lightweight, clean, and extensible library built to manipulate, convert, and minimize formal computational models. It strictly implements the theorems of Formal Language Theory, providing an extremely intuitive, thread-safe, and immutability-based "Fluent" API (via the Builder Pattern).
- Regex Compilation: Full pipeline converting string regular expressions into optimized Minimal DFAs via Abstract Syntax Trees (AST) and Thompson's Construction.
- Modeling: Native support for
DFA(Deterministic Finite Automata),NFA(Non-Deterministic), andENFA(ε-NFA with silent transitions). - Conversion: Subset construction algorithm (Rabin-Scott) and ε-transition elimination (
Converter). - Optimization: DFA minimization using the Equivalence Classes algorithm (Moore's partitioning) with preemptive cleanup of unreachable states (
Minimizer). - Visualization: Export any automaton or compiled regex directly to the Graphviz DOT language or Mermaid.js format for native GitHub rendering.
- Execution Tracing (New!): Detailed step-by-step visual debugging of an automaton's state traversal with
automaton.execute(input).getFormattedTrace().
You can include Autogex in your Java project by adding this dependency to your pom.xml file:
<dependency>
<groupId>org.eu.autogex</groupId>
<artifactId>autogex</artifactId>
<version>1.4.0</version>
</dependency>For a complete overview of all classes and methods, see the Official API documentation.
The easiest way to use Autogex is through the Regex facade. It automatically parses the string, builds the AST, converts to a DFA, and minimizes it.
import org.eu.autogex.regex.Regex;
// Compiles the regex into a theoretical Minimal DFA under the hood
Regex regex = new Regex("(a|b)*abb");
System.out.println(regex.matches("abaabb")); // Output: true
// Export the internal Minimal DFA to Graphviz DOT format for rendering!
String dotGraph = regex.toDotGraph();
System.out.println(dotGraph);
// Export the internal Minimal DFA to Mermaid format for native GitHub Markdown rendering!
String mermaidGraph = regex.toMermaidGraph();
System.out.println(mermaidGraph);(You can copy the generated dotGraph string and paste it into WebGraphviz to see your state machine!)
For educational purposes or custom needs, you can still manually build and convert models using the Builder pattern.
import org.eu.autogex.models.ENFA;
import org.eu.autogex.algorithms.Converter;
import org.eu.autogex.algorithms.Minimizer;
import org.eu.autogex.models.DFA;
// Building an ENFA that accepts the language: a*b*
ENFA enfa = new ENFA.Builder()
.addState("q0", true)
.addState("q1", true)
.setInitialState("q0")
.addTransition("q0", 'a', "q0")
.addEpsilonTransition("q0", "q1") // Silent transition
.addTransition("q1", 'b', "q1")
.build();
// Convert the ENFA into a minimal DFA
DFA minimalDfa = Minimizer.minimize(Converter.enfaToDfa(enfa));
System.out.println(minimalDfa.accepts("aaabbb")); // Output: trueAutogex is an open-source project maintained with passion. If you find this library useful for your work, studies, or projects, consider supporting its development!
This project is licensed under the MIT License. Feel free to use, study, modify, and distribute this code, even in commercial projects. See the LICENSE for full details.