1 #ifndef TEUCHOS_FINITE_AUTOMATON_HPP
2 #define TEUCHOS_FINITE_AUTOMATON_HPP
4 #include <Teuchos_TableDecl.hpp>
11 #ifdef HAVE_TEUCHOSCORE_CXX11
12 extern template struct Table<int>;
24 struct FiniteAutomaton {
26 std::vector<int> accepted_tokens;
27 bool is_deterministic;
29 FiniteAutomaton(
int nsymbols_init,
bool is_deterministic_init,
int nstates_reserve);
30 void swap(FiniteAutomaton& other);
34 inline bool operator==(FiniteAutomaton
const&, FiniteAutomaton
const&) {
38 inline void swap(FiniteAutomaton& a, FiniteAutomaton& b) { a.swap(b); }
40 int get_nstates(FiniteAutomaton
const& fa);
41 int get_nsymbols(FiniteAutomaton
const& fa);
42 bool get_determinism(FiniteAutomaton
const& fa);
43 int get_epsilon0(FiniteAutomaton
const& fa);
44 int get_epsilon1(FiniteAutomaton
const& fa);
45 int add_state(FiniteAutomaton& fa);
46 void add_transition(FiniteAutomaton& fa,
int from_state,
int at_symbol,
int to_state);
47 void add_accept(FiniteAutomaton& fa,
int state,
int token);
48 void remove_accept(FiniteAutomaton& fa,
int state);
49 int step(FiniteAutomaton
const& fa,
int state,
int symbol);
50 int accepts(FiniteAutomaton
const& fa,
int state);
51 int get_nsymbols_eps(FiniteAutomaton
const& fa);
52 void append_states(FiniteAutomaton& fa, FiniteAutomaton
const& other);
54 void make_single_nfa(FiniteAutomaton& result,
int nsymbols,
int symbol,
int token = 0);
55 void make_set_nfa(FiniteAutomaton& result,
int nsymbols, std::set<int>
const& accepted,
int token = 0);
56 void make_range_nfa(FiniteAutomaton& result,
int nsymbols,
int range_start,
int range_end,
int token = 0);
57 void unite(FiniteAutomaton& result, FiniteAutomaton
const& a, FiniteAutomaton
const& b);
58 void concat(FiniteAutomaton& result, FiniteAutomaton
const& a, FiniteAutomaton
const& b,
int token = 0);
59 void plus(FiniteAutomaton& result, FiniteAutomaton
const& a,
int token = 0);
60 void maybe(FiniteAutomaton& result, FiniteAutomaton
const& a,
int token = 0);
61 void star(FiniteAutomaton& result, FiniteAutomaton
const& a,
int token = 0);
62 void make_deterministic(FiniteAutomaton& result, FiniteAutomaton& nfa);
63 void simplify_once(FiniteAutomaton& result, FiniteAutomaton
const& fa);
64 void simplify(FiniteAutomaton& result, FiniteAutomaton
const& fa);
66 FiniteAutomaton make_char_nfa(
bool is_deterministic_init,
int nstates_reserve);
67 void add_char_transition(FiniteAutomaton& fa,
int from_state,
char at_char,
int to_state);
68 bool is_symbol(
char c);
69 int get_symbol(
char c);
70 char get_char(
int symbol);
71 void make_char_set_nfa(FiniteAutomaton& result, std::set<char>
const& accepted,
int token = 0);
72 void make_char_range_nfa(FiniteAutomaton& result,
char range_start,
char range_end,
int token = 0);
73 void make_char_single_nfa(FiniteAutomaton& result,
char symbol_char,
int token = 0);
74 void negate_set(std::set<char>& result, std::set<char>
const& s);
76 std::ostream& operator<<(std::ostream& os, FiniteAutomaton
const& fa);