-
Notifications
You must be signed in to change notification settings - Fork 0
/
machine.h
129 lines (78 loc) · 2.89 KB
/
machine.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
//
// Created by hesham on 3/18/18.
// Initial definion to the Machine strcture
//
#ifndef KOMPILAR_MACHINE_H
#define KOMPILAR_MACHINE_H
#include <map>
#include <vector>
#include <string>
#include <set>
#define EPS_C 0x01
typedef int sid_t;
class machine {
class state {
class transition {
private:
sid_t to_identifier;
char on_input;
public:
transition(sid_t, char);
sid_t get_to_identifier() const;
char get_transition_char() const;
};
private:
std::map<char, std::vector<transition> > transitions;
std::string token_class;
std::string key;
public:
state();
state(std::string _token_class);
state(std::string _token_class, std::string _key);
std::string get_token_class() const;
bool add_new_transition(sid_t to_id, char on_input = EPS_C);
void set_key(std::string key);
void set_token_class(std::string token_class);
std::string get_key() const;
std::vector<sid_t> get_transitions_for(char input);
};
private:
std::string machine_identifier;
std::vector<state> states;
std::set<sid_t> accepting;
std::set<char> language;
sid_t starting;
public:
machine();
machine(std::string _machine_identifier);
sid_t add_new_state(std::string key, std::string token_class = "",
bool is_starting = false, bool is_accepting = false);
sid_t add_new_state(bool is_starting = false, bool is_accepting = false);
sid_t add_new_state(std::string token_class = "", bool is_starting = false,
bool is_accepting = false);
bool add_new_transition(sid_t from_id, sid_t to_id, char on_input = EPS_C);
bool set_starting_state(sid_t _starting_id);
sid_t add_starting_state(std::string key, std::string token_class = "",
bool is_accepting = false);
sid_t get_starting_state() const;
sid_t merge(machine other);
std::string get_machine_identifier() const;
std::set<sid_t> get_accepting_states() const;
std::vector<sid_t> get_transitions(sid_t id, char input);
std::string get_token_class(sid_t id) const;
std::string get_key_for(sid_t id) const;
void set_key_for(sid_t id, std::string new_key);
std::set<char> get_language() const;
sid_t get_states_count() const;
bool set_accepting(sid_t id);
bool set_token_class(sid_t id, std::string new_token_class);
bool set_token_class(std::string new_token_class);
void set_machine_identifier (std::string identifier);
bool is_accepting(sid_t id);
bool is_starting(sid_t id);
void clear_accepting_states();
void print_machine();
friend std::ostream &operator <<(std::ostream &os, machine &m);
friend std::istream &operator >>(std::istream &is, machine &m);
};
#endif //KOMPILAR_MACHINE_H