10 #ifndef TEUCHOS_FINITE_AUTOMATON_HPP
11 #define TEUCHOS_FINITE_AUTOMATON_HPP
13 #include <Teuchos_TableDecl.hpp>
20 #ifdef HAVE_TEUCHOSCORE_CXX11
21 extern template struct Table<int>;
33 struct FiniteAutomaton {
35 std::vector<int> accepted_tokens;
36 bool is_deterministic;
38 FiniteAutomaton(
int nsymbols_init,
bool is_deterministic_init,
int nstates_reserve);
39 void swap(FiniteAutomaton& other);
43 inline bool operator==(FiniteAutomaton
const&, FiniteAutomaton
const&) {
47 inline void swap(FiniteAutomaton& a, FiniteAutomaton& b) { a.swap(b); }
49 int get_nstates(FiniteAutomaton
const& fa);
50 int get_nsymbols(FiniteAutomaton
const& fa);
51 bool get_determinism(FiniteAutomaton
const& fa);
52 int get_epsilon0(FiniteAutomaton
const& fa);
53 int get_epsilon1(FiniteAutomaton
const& fa);
54 int add_state(FiniteAutomaton& fa);
55 void add_transition(FiniteAutomaton& fa,
int from_state,
int at_symbol,
int to_state);
56 void add_accept(FiniteAutomaton& fa,
int state,
int token);
57 void remove_accept(FiniteAutomaton& fa,
int state);
58 int step(FiniteAutomaton
const& fa,
int state,
int symbol);
59 int accepts(FiniteAutomaton
const& fa,
int state);
60 int get_nsymbols_eps(FiniteAutomaton
const& fa);
61 void append_states(FiniteAutomaton& fa, FiniteAutomaton
const& other);
63 void make_single_nfa(FiniteAutomaton& result,
int nsymbols,
int symbol,
int token = 0);
64 void make_set_nfa(FiniteAutomaton& result,
int nsymbols, std::set<int>
const& accepted,
int token = 0);
65 void make_range_nfa(FiniteAutomaton& result,
int nsymbols,
int range_start,
int range_end,
int token = 0);
66 void unite(FiniteAutomaton& result, FiniteAutomaton
const& a, FiniteAutomaton
const& b);
67 void concat(FiniteAutomaton& result, FiniteAutomaton
const& a, FiniteAutomaton
const& b,
int token = 0);
68 void plus(FiniteAutomaton& result, FiniteAutomaton
const& a,
int token = 0);
69 void maybe(FiniteAutomaton& result, FiniteAutomaton
const& a,
int token = 0);
70 void star(FiniteAutomaton& result, FiniteAutomaton
const& a,
int token = 0);
71 void make_deterministic(FiniteAutomaton& result, FiniteAutomaton& nfa);
72 void simplify_once(FiniteAutomaton& result, FiniteAutomaton
const& fa);
73 void simplify(FiniteAutomaton& result, FiniteAutomaton
const& fa);
75 void add_char_transition(FiniteAutomaton& fa,
int from_state,
char at_char,
int to_state);
76 bool is_symbol(
char c);
77 int get_symbol(
char c);
78 char get_char(
int symbol);
79 void make_char_set_nfa(FiniteAutomaton& result, std::set<char>
const& accepted,
int token = 0);
80 void make_char_range_nfa(FiniteAutomaton& result,
char range_start,
char range_end,
int token = 0);
81 void make_char_single_nfa(FiniteAutomaton& result,
char symbol_char,
int token = 0);
82 void negate_set(std::set<char>& result, std::set<char>
const& s);
84 std::ostream& operator<<(std::ostream& os, FiniteAutomaton
const& fa);