-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtokens.cpp
More file actions
249 lines (217 loc) · 4.96 KB
/
Copy pathtokens.cpp
File metadata and controls
249 lines (217 loc) · 4.96 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#include "tokens.h"
Tnames::Tnames(Tname *t)
{
tk = T_TNAMES;
names = new vector<Tname*>();
names->push_back(t);
}
Tnames::Tnames(Tnames *ts,Tname *t)
{
tk = T_TNAMES;
names = new vector<Tname*>(*ts->getNames());
names->push_back(t);
}
string Tnames::getName()
{
vector<Tname*>::iterator it;
it=names->begin();
string re;
if(it!=names->end())
{
re = (*it)->getName();
it++;
for(; it!=names->end(); it++)
{
re += ", " + (*it)->getName();
}
}
return re;
}
Tnames::~Tnames()
{
delete names;
}
Tables::Tables(Table *t)
{
tk = T_TABLES;
tables = new vector<Table*>();
tables->push_back(t);
}
Tables::Tables(Tables* ts,Table*t)
{
tk = T_TABLES;
tables = new vector<Table*>(*ts->getTables());
tables->push_back(t);
}
string Tables::getName()
{
vector<Table*>::iterator it;
it=tables->begin();
string re;
if(it!=tables->end())
{
re = (*it)->getName();
it++;
for(; it!=tables->end(); it++)
{
re += ", " + (*it)->getName();
}
}
return re;
}
Tables::~Tables()
{
delete tables;
}
Where::Where(CompareUnit *l,CompareOp *c,CompareUnit *r)
{
this->left = l;
this->comp = c;
this->right = r;
tk=T_WHERE;
}
string Where::getName()
{
return left->getName() + " " + comp->getName() + " " + right->getName();
}
Wheres::Wheres(Where *w)
{
tk = T_WHERES;
compares = new vector<Where*>();
compares->push_back(w);
logics = new vector<Logic*>();
}
Wheres::Wheres(Wheres *ws,Logic *l, Where *w)
{
tk = T_WHERES;
compares = new vector<Where*>(*ws->getCompares());
compares->push_back(w);
logics = new vector<Logic*>(*ws->getLogics());
logics->push_back(l);
}
Wheres::~ Wheres()
{
delete compares;
delete logics;
}
string Wheres::getName()
{
vector<Where*>::iterator it1;
vector<Logic*>::iterator it2;
it1= compares->begin();
it2 = logics ->begin();
string re;
re = (*it1)->getName();
it1++;
for(; it1!=compares->end(); it1++,it2++)
{
re += " " + (*it2)->getName() +" " + (*it1)->getName();
}
return re;
}
Select::Select(Tnames *n,Tables *t,Wheres *w)
{
tk = T_SELECTION;
names = n;
tables = t;
wheres = w;
}
string Select::getName()
{
string rs = "select " + names->getName() + " from "+ tables->getName();
if(wheres != NULL)
{
rs += " where " + wheres->getName();
}
return rs;
}
Select::~Select()
{
}
void Select::printspace(int space)
{
for(int i=0; i<space; i++)
cout << " ";
}
void Select::printTree()
{
return printTree(0);
}
void Select::printTree(int space)
{
printspace(space);
cout << "+ QUERY/SELECT"<<endl;
space +=1;
printspace(space);
cout << "+ SELECT" <<endl;
printspace(space);
cout << "+ FIELD" <<endl;
space += 1;
vector<Tname*> * ns = this->names->getNames();
vector<Tname*>::iterator it1 = ns->begin();
for(; it1!=ns->end(); it1++)
{
printspace(space);
cout << "+ " << (*it1)->getName() <<endl;
}
space -= 1;
printspace(space);
cout << "+ FROM" <<endl;
printspace(space);
cout << "+ TABLE" <<endl;
space += 1;
vector<Table*> * ts = this->tables->getTables();
vector<Table*>::iterator it2 = ts->begin();
for(; it2!=ts->end(); it2++)
{
if( (*it2)->getSelect() != NULL)
{
printspace(space);
cout << "+ TABLE/SELECT AS " << (*it2)->getName() <<endl;
space +=1;
(*it2)->getSelect()->printTree(space);
space -=1;
}
else
{
printspace(space);
cout << "+ " << (*it2)->getName() <<endl;
}
}
space -= 1;
if(this->wheres != NULL)
{
printspace(space);
cout << "+ WHERE" <<endl;
space += 1;
vector<Where*>::iterator it3;
vector<Logic*>::iterator it4;
it3= wheres->getCompares()->begin();
it4 = wheres->getLogics() ->begin();
printspace(space);
cout << "+ COMPARE[ " << (*it3)->getOp()->getName() << " ]"<< endl;
space +=1;
printspace(space);
cout << "+ " << (*it3)->getLeft()->getName() << endl;
printspace(space);
cout << "+ " << (*it3)->getRight()->getName() << endl;
space -=1;
it3++;
space -=1;
for(; it3!=wheres->getCompares()->end(); it3++,it4++)
{
space +=1;
printspace(space);
cout << "+ LOGICAL OPERATOR[ " << (*it4)->getName() << " ]"<<endl;
printspace(space);
cout << "+ COMPARE[ " << (*it3)->getOp()->getName() << " ]"<< endl;
space +=1;
printspace(space);
cout << (*it3)->getLeft()->getName() << endl;
printspace(space);
cout << (*it3)->getRight()->getName() << endl;
space -=1;
space -=1;
}
}
}