DFA.hpp

A Deterministic Finite Automata simulator.

This file is part of Empirical, https://github.com/devosoft/Empirical Copyright (C) 2016-2024 Michigan State University MIT Software license; see doc/LICENSE.md

Note

Status: BETA

Defines

INCLUDE_EMP_COMPILER_DFA_HPP_GUARD

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_T = uint8_t>
class tDFA
#include <DFA.hpp>

Public Types

using stop_t = STOP_T

Public Functions

inline size_t GetSize() const

How many states is this DFA using?

inline void Resize(size_t new_size)

Add Additional empty states.

inline size_t AddState()

Add a single new, empty state and return its position.

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, String sym_set) const

Return the new state after a series of symbols.

inline stop_t Test(const String &str) const

Determine if an entire series of symbols is valid.

inline bool UsesSymbol(size_t symbol_id) const
inline void Print(std::ostream &os = std::cout) const

Print details about this DFA.

inline void WriteCPP(CPPFile &file, String object_name = "DFA") const

Public Static Attributes

static constexpr size_t SYMBOL_START = 2

Symbol to indicate a start of line.

static constexpr size_t SYMBOL_STOP = 3

Symbol to indicate an end of line.

static constexpr size_t SYMBOL_MIN_INPUT = 9

All symbols below this are control symbols.

Private Types

using this_t = tDFA<NUM_SYMBOLS, STOP_T>

Private Members

vector<array<int, NUM_SYMBOLS>> transitions
vector<STOP_T> stop_id