Skip to content

Tugamer89/autogex

Autogex Logo

Autogex

A powerful Java engine for processing Finite State Automata and Regular Expressions.

Java Version Build Status Coverage Quality Gate Status Maintainability Rating Security Rating wakatime License Javadoc Maven Central Sponsor

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), and ENFA (ε-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>org.eu.autogex</groupId>
  <artifactId>autogex</artifactId>
  <version>1.4.0</version>
</dependency>

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 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!)

2. Manual Automata Construction

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: true

Support the Project

Autogex is an open-source project maintained with passion. If you find this library useful for your work, studies, or projects, consider supporting its development!

Sponsor Tugamer89

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.

About

Autogex is a powerful Java engine for processing Finite State Automata and Regular Expressions. It is a lightweight and extensible library that strictly implements Formal Language Theory to manipulate, convert, and minimize computational models.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Contributors

Languages