MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
nfa.cpp
Go to the documentation of this file.
1#include "automaton/nfa.h"
2
5
6namespace automaton {
7
8void NFANode::add_transition(const NFANode* to, std::uint16_t c) {
9 if (auto it = transitions_.find(c); it != transitions_.end())
10 it->second.push_back(to);
11 else
12 transitions_.emplace(c, std::vector<const NFANode*>{to});
13}
14
15std::vector<const NFANode*> NFANode::get_transitions(std::uint16_t c) const {
16 if (erroring_) return {};
17
18 if (auto it = transitions_.find(c); it != transitions_.end())
19 return it->second;
20 else
21 return {};
22}
23
24template class AutomatonBase<NFANode>;
25
26std::ostream& operator<<(std::ostream& os, const NFANode& node) {
27 auto print_char = [](std::uint16_t c) -> std::string {
29 return "ε";
30 else if (c >= 48 && c <= 122)
31 return {static_cast<char>(c)};
32 return std::to_string(c);
33 };
34
35 return print_node(os, node, std::move(print_char));
36}
37
38} // namespace automaton
std::vector< const NFANode * > get_transitions(std::uint16_t c) const
Definition nfa.cpp:15
void add_transition(const NFANode *to, std::uint16_t c)
Definition nfa.cpp:8
std::ostream & operator<<(std::ostream &os, const DFANode &node)
Definition dfa.cpp:20
std::ostream & print_node(std::ostream &os, const NodeType &node, PrintCharF &&print_char)
Definition automaton.h:70