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