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
4
5namespace automaton {
6
7void NFANode::add_transition(const NFANode* to, std::uint16_t c) {
8 if (auto it = transitions_.find(c); it != transitions_.end())
9 it->second.push_back(to);
10 else
11 transitions_.emplace(c, std::vector<const NFANode*>{to});
12}
13
14std::vector<const NFANode*> NFANode::get_transitions(std::uint16_t c) const {
15 if (erroring_) return {};
16
17 if (auto it = transitions_.find(c); it != transitions_.end())
18 return it->second;
19 else
20 return {};
21}
22
23template class AutomatonBase<NFANode>;
24
25std::ostream& operator<<(std::ostream& os, const NFANode& node) {
26 auto print_char = [](std::uint16_t c) -> std::string {
28 return "ε";
29 else if (c >= 48 && c <= 122)
30 return {static_cast<char>(c)};
31 return std::to_string(c);
32 };
33
34 return print_node(os, node, std::move(print_char));
35}
36
37} // namespace automaton
std::vector< const NFANode * > get_transitions(std::uint16_t c) const
Definition nfa.cpp:14
void add_transition(const NFANode *to, std::uint16_t c)
Definition nfa.cpp:7
std::ostream & operator<<(std::ostream &os, const DFANode &node)
Definition dfa.cpp:19
std::ostream & print_node(std::ostream &os, const NodeType &node, PrintCharF &&print_char)
Definition automaton.h:67