A deterministic finite automaton (DFA) is a mathematical model used in computer science and theoretical linguistics to recognize patterns in string inputs. It is a type of finite state machine that operates by reading a sequence of symbols from an input string and moving through a series of states based on those symbols. The DFA accepts or rejects the input string based on whether the final state it reaches after processing the input is an accepting state or not. In this project, several DFAs have been developed to check string inputs for various patterns and purposes. These DFAs have been implemented using Rust and can be used to validate string inputs for specific patterns or conditions. There's also the option to validate a string with a custom DFA.
- Allows the user to create their own DFA using a JSON config file (src/input_dfa.json), which can be used to validate a string input.
- The JSON config file contains the following fields:
tokens
: The tokens or alphabet accepted for the DFAstates
: The states of the DFAinitial_state
: The initial state of the DFAaccepted_states
: The accepting states of the DFAtransitions
: The transition functions of the DFA, where each transition is represented by having the state as the key and the transition function as the value. For each input token, the transition function returns the next state.
JSON config | DFA generated |
---|---|
- Accepted string examples: 123e+3, 2.3E3, 123, 345.4e-3
- Rejected string examples: 234.234.3, 5-2, 45e34.3
- Alphabet(Sigma): {1,0}
- Accepted string examples: 1001, 101010101, 00, 00001
- Rejected string examples: 1100, 1011, 101010, 000
- Alphabet(Sigma): {a, b, c, d}
- Accepted string examples: aa, abcdd, abcc, aaaaab
- Rejected string examples: abcd, a, abc, ba
Note: The format should be day -> month -> year
- Accepted string examples: 12/12/12, 3.4.2022, 31-1-2000
- Rejected string examples: 32/12/2000, 3-13-2010, 234-3
Clone the Repo and simply cargo run
on the project's root folder.
All of these examples have different state machines, but share the same structure in order to build the States and Transition Functions between them.
Built in Rust. Implementation inspired by Pretty State Machine Patterns in Rust by Anna Hoverbear