DFA.hpp

A Deterministic Finite Automata simulator.

Note

Status: BETA

Typedefs

using DFA = tDFA<128, uint8_t>

Setup DFA to be a simple tDFA with the basic character set for symbols.

template<int NUM_SYMBOLS = 128, typename STOP_TYPE = uint8_t>
class tDFA
#include <DFA.hpp>

Public Types

using stop_t = STOP_TYPE

Public Functions

inline tDFA(size_t num_states = 0)
tDFA(const this_t&) = default
tDFA(this_t&&) = default
inline ~tDFA()
this_t &operator=(const this_t&) = default
this_t &operator=(this_t&&) = default
inline size_t GetSize() const

How many states is this DFA using?

inline void Resize(size_t new_size)

Add Additional empty states.

inline const array<int, NUM_SYMBOLS> &GetTransitions(size_t from) const

Return an array of all transitions associated with a specified state.

inline void SetTransition(size_t from, size_t to, size_t sym)

Add a specific transition associated with an input symbol.

inline void SetStop(size_t state, stop_t stop_val = 1)

Set the stop value (no matter what it currently is)

inline void AddStop(size_t state, stop_t stop_val = 1)

Set the stop value only if it’s higher than the current stop value.

inline stop_t GetStop(int state) const

Get the stop value associated with a state.

inline bool IsActive(int state) const

Test if a state is still valid.

inline bool IsStop(int state) const

Test if a state has a stop.

inline stop_t GetStop(size_t state) const
inline bool IsActive(size_t) const
inline bool IsStop(size_t state) const
inline int Next(int state, size_t sym) const

Return the new state after a symbol occurs.

inline int Next(int state, std::string sym_set) const

Return the new state after a series of symbols.

inline stop_t Test(const std::string &str) const

Determine if an entire series of symbols is valid.

inline void Print(std::ostream &os = std::cout)

Print details about this DFA.

Private Types

using this_t = tDFA<NUM_SYMBOLS, STOP_TYPE>

Private Members

vector<array<int, NUM_SYMBOLS>> transitions
vector<STOP_TYPE> is_stop