Autogex 1.3.0 API
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).
Current Features
- 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().
Installation
You can include Autogex in your Java project by adding this dependency to your pom.xml file:
<dependency>
<groupId>it.tugamer89</groupId>
<artifactId>autogex</artifactId>
<version>1.3.0</version>
</dependency>
Note for GitHub Packages: To download packages hosted directly on GitHub, you must have a Personal Access Token (PAT) configured in your local ~/.m2/settings.xml file.
Usage Example
For a complete overview of all classes and methods, see the Official API documentation.
1. The Regex Facade & Visualization
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 it.tugamer89.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!)
2. Manual Automata Construction
For educational purposes or custom needs, you can still manually build and convert models using the Builder pattern.
import it.tugamer89.autogex.models.ENFA;
import it.tugamer89.autogex.algorithms.Converter;
import it.tugamer89.autogex.algorithms.Minimizer;
import it.tugamer89.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: true
License
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.