-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutomataNode.cpp
More file actions
54 lines (42 loc) · 1.48 KB
/
Copy pathAutomataNode.cpp
File metadata and controls
54 lines (42 loc) · 1.48 KB
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
#include "Transition.h"
using namespace std;
Automata *epsilonAut(AutomataNode *a, AutomataNode *b) {
Transition *t = new Transition('e', b);
a->addTransition(t);
Automata *automata = new Automata(a, b);
return automata;
}
Automata *letterAut(AutomataNode *a, AutomataNode *b, char val) {
Transition *t = new Transition(val, b);
a->addTransition(t);
Automata *automata = new Automata(a, b);
return automata;
}
Automata *orAut(Automata *a, Automata *b) {
AutomataNode *initial = new AutomataNode();
AutomataNode *final = new AutomataNode();
epsilonAut(initial, a->getInitNode());
epsilonAut(initial, b->getInitNode());
epsilonAut(a->getFinNode(), final);
epsilonAut(b->getFinNode(), final);
Automata* autom = new Automata(initial, final);
return autom;
}
Automata *andAutomata(Automata *a, Automata *b) {
for (int i=0;i<b->getInitNode()->getTransition().size();i++){
a->getFinNode()->addTransition(b->getInitNode()->getTransition()[i]);
}
b->setInitAutomataNode(nullptr);
Automata *autom = new Automata(a->getInitNode(), b->getFinNode());
return autom;
}
Automata *kleenAutomata(Automata *a) {
AutomataNode *init = new AutomataNode();
AutomataNode *final = new AutomataNode();
epsilonAut(a->getFinNode(), a->getInitNode());
epsilonAut(init, a->getInitNode());
epsilonAut(init, final);
epsilonAut(a->getFinNode(), final);
Automata* autom = new Automata(init, final);
return autom;
}