-
Notifications
You must be signed in to change notification settings - Fork 3
/
endmeendme
63 lines (60 loc) · 1.8 KB
/
endmeendme
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
void Parser::printAST() {
for (int i = 0; i < _ast.size(); i++) {
// cout << type << endl;
cout << _ast[i]._type << " " << _ast[i] << "; data{" << to_string(data.size()) << "}";
if(type == "FDECL") {
cout << ((FDECL*)(&ast))->_data2.size() << endl;
// cout << "; data2{" << to_string((*((FDECL*)(sast)))._data2.size()) << "}";
}else cout << type;
cout << endl;
}
}
void Parser::out(string filename) {
// write ast into a json-tree like form in output file. (INCLUDING THE AST INSIDE DATA AND DATA2)
ofstream file;
file.open(filename);
file << "{";
for (int i = 0; i < _ast.size(); i++) {
Node node = *_ast[i];
FDECL typedNode = *((FDECL *)(_ast[i]));
file << "\"" << (*_ast[i])._type << "\": \"" << (*_ast[i])._value << "\"";
// ast data
file << ", \"data\": {";
for (int j = 0; j < node._data.size(); j++) {
file << "\"" << typedNode._data[j]->_type << "\": \"" << (*_ast[i])._data[j]->_value << "\"";
if(j != (*_ast[i])._data.size() - 1) {
file << ",";
}
}
file << "}";
// ast data2
if((*_ast[i])._type == "FDECL") {
file << ", \"data2\": {";
for (int j = 0; j < (*((FDECL *)(_ast[i])))._data2.size(); j++) {
file << "\"" << (*((FDECL *)(_ast[i])))._data2[j]->_type << "\": \"" << (*((FDECL *)(_ast[i])))._data2[j]->_value << "\"";
if(j != (*((FDECL *)(_ast[i])))._data2.size() - 1) {
file << ",";
}
}
file << "}";
if(i != _ast.size() - 1) {
file << ",";
}
}
}
file << "}";
file.close();
/*
ofstream file;
file.open(filename);
file << "{";
for (int i = 0; i < _ast.size(); i++) {
file << "\"" << _ast[i]._type << "\": \"" << _ast[i]._value << "\"";
if(i != _ast.size() - 1) {
file << ",";
}
}
file << "}";
file.close();
*/
}