https://github.com/shaina-gh/dfa-construction
A C++ implementation to simulate a DFA for the regular expression (a|b)*abb+
https://github.com/shaina-gh/dfa-construction
compiler-design cpp dfa-construction
Last synced: about 1 year ago
JSON representation
A C++ implementation to simulate a DFA for the regular expression (a|b)*abb+
- Host: GitHub
- URL: https://github.com/shaina-gh/dfa-construction
- Owner: shaina-gh
- Created: 2025-05-20T05:12:49.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-20T05:20:20.000Z (about 1 year ago)
- Last Synced: 2025-05-20T06:26:25.168Z (about 1 year ago)
- Topics: compiler-design, cpp, dfa-construction
- Language: C++
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ๐ฆ DFA Construction
This project demonstrates the construction and simulation of a **Deterministic Finite Automaton (DFA)** to recognise strings that match a specific regular expression. The implementation is done in **C++**.
---
## ๐ Definition
A **Deterministic Finite Automaton (DFA)** is a theoretical model of computation used to determine whether a given string belongs to a particular regular language. A DFA consists of:
- A finite set of **states**
- An **input alphabet**
- A **transition function**
- A **start state**
- A set of **accepting (final) states**
In this experiment, the DFA is constructed to accept the language defined by the **regular expression**:
```yaml
(a|b)*abb+
```
This expression denotes all strings over `{a, b}` that end in one or more `b`s and are preceded by the substring `"ab"`.
---
## ๐ Logic & DFA Core
The DFA transitions are modelled using a 2D vector `re` where each row represents a state, and the columns represent the transition on `'a'` and `'b'` respectively.
### DFA Transition Table
| State | On 'a' | On 'b' |
|-------|--------|--------|
| 0 | 1 | 0 |
| 1 | 1 | 2 |
| 2 | 1 | 3 |
| 3 | 1 | 3 |
- **Start State**: 0
- **Final State**: 3
- **Accepted Language**: All strings containing a substring ending in `"abb"` followed by one or more `b`s.
---
## ๐งช Sample Input/Output
Example 1
```yaml
Input: aabb
Output: Accepted
```
Example 2
```yaml
Input: abababbb
Output: Accepted
```
Example 3
```yaml
Input: aba
Output: Rejected
```
---
## ๐ Real-World Applications
- Lexical Analysis: Tokenising source code in compilers.
- Network Security: Pattern matching in intrusion detection systems.
- Text Editors: Implementing search and syntax highlighting.
- Natural Language Processing: Recognising grammars in structured text.
- Embedded Systems: Modelling finite state behaviour in devices.
---