MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
dfa.cpp
Go to the documentation of this file.
1#include "automaton/dfa.h"
2
3#include <absl/container/flat_hash_map.h>
4
6
7namespace automaton {
8
9void DFANode::add_transition(const DFANode* to, std::uint16_t c) { transitions_[c] = to; }
10
11const DFANode* DFANode::get_transition(std::uint16_t c) const {
12 if (erroring_) return nullptr;
13 if (auto i = transitions_.find(c); i != transitions_.end()) return i->second;
14 return nullptr;
15}
16
17template class AutomatonBase<DFANode>;
18
19std::ostream& operator<<(std::ostream& os, const DFANode& node) {
20 auto print_char = [](std::uint16_t c) -> std::string {
21 if (c >= 48 && c <= 122) return {static_cast<char>(c)};
22 return std::to_string(c);
23 };
24 return print_node(os, node, print_char);
25}
26
27} // namespace automaton
const DFANode * get_transition(std::uint16_t c) const
Definition dfa.cpp:11
void add_transition(const DFANode *to, std::uint16_t c)
Definition dfa.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:67