-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwriteTxt.cpp
More file actions
111 lines (83 loc) · 2.6 KB
/
Copy pathwriteTxt.cpp
File metadata and controls
111 lines (83 loc) · 2.6 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
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
//
// Created by Freddie on 9/21/2016.
//
#include <iostream>
#include <fstream>
#include "writeTxt.h"
#include "AutomataNode.h"
#include "Transition.h"
#include <set>
set<AutomataNode*> nodes;
string states = "Estados = {";
string transitions = "Transiciones = {";
void moves(AutomataNode* a) {
bool is_in = nodes.find(a) != nodes.end();
if (!is_in) {
nodes.insert(a);
vector<Transition *> t = a->getTransition();
for (int i = 0; i < t.size(); i++) {
transitions +=
to_string(a->getNumber()) + t[i]->getValue() + "->" + to_string(t[i]->getNextNode()->getNumber()) +
",";
moves(a->getTransition()[i]->getNextNode());
}
}
}
void nfaWriter(Automata* a,string language){
string sym = "Simbolos = {";
string init = "Inicio = {";
string end = "Aceptacion = {";
ofstream file;
file.open ("C:/Users/Freddie/ClionProjects/C++Compiler/nfa.txt");
init += to_string(a->getInitNode()->getNumber());
end += to_string(a->getFinNode()->getNumber());
for(int i =0;i<language.size();i++){
sym += (language[i]);
}
moves(a->getInitNode());
for (set<AutomataNode *>::iterator it3 = nodes.begin(); it3 != nodes.end(); it3++) {
AutomataNode *state2 = *it3;
states += to_string(state2->getNumber())+",";
}
states += "}";
sym += "}";
init += "}";
end += "}";
transitions += "}";
file<<states<< endl <<sym<<endl<<init<<endl<<end<<endl<<transitions<<endl;
file.close();
nodes.clear();
transitions.clear();
states.clear();
states = "Estados = {";
transitions = "Transiciones = {";
}
void dfaWriter(AutomataDfa* a,string language){
string sym = "Simbolos = {";
string init = "Inicio = {";
string end = "Aceptacion = {";
ofstream file;
file.open ("C:/Users/Freddie/ClionProjects/C++Compiler/dfa.txt");
init += to_string(a->getInitNode()->getNumber());
for (int i=0;i<a->getFinNode().size();i++){
end += to_string(a->getFinNode()[i]->getNumber());
}
for(int i =0;i<language.size();i++){
sym += (language[i]);
}
moves(a->getInitNode());
for (set<AutomataNode *>::iterator it3 = nodes.begin(); it3 != nodes.end(); it3++) {
AutomataNode *state2 = *it3;
states += to_string(state2->getNumber())+",";
}
states += "}";
sym += "}";
init += "}";
end += "}";
transitions += "}";
file<<states<< endl <<sym<<endl<<init<<endl<<end<<endl<<transitions<<endl;
file.close();
nodes.clear();
transitions.clear();
states.clear();
}