MimIR
0.4-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
nfa.cpp
Go to the documentation of this file.
1
#include "
automaton/nfa.h
"
2
3
#include <string>
4
5
#include "
automaton/automaton.h
"
6
7
namespace
automaton
{
8
9
void
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
16
std::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
25
template
class
AutomatonBase<NFANode>
;
26
27
std::ostream&
operator<<
(std::ostream& os,
const
NFANode
& node) {
28
auto
print_char = [](std::uint16_t c) -> std::string {
29
if
(c ==
NFA::SpecialTransitons::EPSILON
)
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
automaton.h
automaton::AutomatonBase
Definition
automaton.h:18
automaton::NFANode::NFANode
NFANode(int id)
Definition
nfa.h:19
automaton::NFANode::operator<<
friend std::ostream & operator<<(std::ostream &os, const NFANode &node)
Definition
nfa.cpp:27
automaton::NFANode::get_transitions
std::vector< const NFANode * > get_transitions(std::uint16_t c) const
Definition
nfa.cpp:16
automaton::NFANode::add_transition
void add_transition(const NFANode *to, std::uint16_t c)
Definition
nfa.cpp:9
automaton::NFA::EPSILON
@ EPSILON
Definition
nfa.h:77
automaton
Definition
automaton.h:12
automaton::print_node
std::ostream & print_node(std::ostream &os, const NodeType &node, PrintCharF &&print_char)
Definition
automaton.h:71
nfa.h
src
automaton
nfa.cpp
Generated by
1.18.0