https://github.com/alafty/regularexpressiontonfa
Task 1 for the Compilers lab where the needed deliverable is a function that takes a regular expression as an input and outputs an equivalent NFA as per Thompson's methon
https://github.com/alafty/regularexpressiontonfa
compiler-design compilers java nfa regex
Last synced: about 2 months ago
JSON representation
Task 1 for the Compilers lab where the needed deliverable is a function that takes a regular expression as an input and outputs an equivalent NFA as per Thompson's methon
- Host: GitHub
- URL: https://github.com/alafty/regularexpressiontonfa
- Owner: alafty
- Created: 2024-02-15T20:36:57.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-07T00:16:02.000Z (over 1 year ago)
- Last Synced: 2025-03-14T13:24:20.813Z (7 months ago)
- Topics: compiler-design, compilers, java, nfa, regex
- Language: Java
- Homepage:
- Size: 68.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# RegExToNfa
## Description
The `RegExToNfa` Java class provides functionality to convert a regular expression into a corresponding Non-Deterministic Finite Automata (NFA) using Thompson's construction algorithm. This conversion is a crucial step in various applications, such as pattern matching and lexical analysis.
## Usage
To use the `RegExToNfa` class, follow these steps:
1. Include the `RegExToNfa.java` file in your Java project.
2. Create an instance of the `RegExToNfa` class, providing the regular expression in postfix notation and the alphabet as input.
3. Call the `toString()` method of the `RegExToNfa` instance to obtain a formatted string representation of the resulting NFA.Example:
```java
String regex = "abcu#abc|.∪.*";
RegExToNfa converter = new RegExToNfa(regex);
String nfaString = converter.toString();
System.out.println(nfaString);
```## Input Format
The input to the `RegExToNfa` class should be a regular expression in postfix notation, where:
- Characters represent literals in the regular expression.
- `.` represents concatenation.
- `∪` represents union.
- `*` represents Kleene star (zero or more occurrences).
- `e` represents an empty string (epsilon transition).## Output Format
The output of the `toString()` method is a formatted string representation of the resulting NFA. The string representation follows a specific format as described in the task description.
## Classes
- `RegExToNfa`: Main class responsible for converting a regular expression to an NFA.
- `State`: Represents a state in the NFA.
- `NFA`: Represents the NFA, containing states, transitions, start state, and accept state.
- `Transition`: Represents a transition between states in the NFA.## Authors
- [Mohamed El-Alafty](https://github.com/alafty)