-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpa3.cpp
More file actions
215 lines (166 loc) · 4.97 KB
/
Copy pathpa3.cpp
File metadata and controls
215 lines (166 loc) · 4.97 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
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <deque>
#include <string>
#include <stdlib.h>
using namespace std;
string getFileName();
deque<string> getLines(string fileName);
vector<string> getKeywords(string lines);
vector<string> getIdentifiers(string lines);
vector<string> getConstants(string lines);
vector<string> getOperators(string lines);
vector<string> getDelimiters(string lines);
int main() {
string fileName = getFileName();
deque<string> linesInFile = getLines(fileName);
vector<vector<string>> keywordsInFile;
vector<vector<string>> identifiersInFile;
vector<vector<string>> constantsInFile;
vector<vector<string>> operatorsInFile;
vector<vector<string>> delimitersInFile;
vector<string> simpleLines;
int i = 0;
while (!linesInFile.empty()) {
keywordsInFile.at(i) = getKeywords(linesInFile.at(0));
operatorsInFile.at(i) = getOperators(linesInFile.at(0));
delimitersInFile.at(i) = getDelimiters(linesInFile.at(0));
identifiersInFile.at(i) = getIdentifiers(linesInFile.at(0));
constantsInFile.at(i) = getConstants(linesInFile.at(0));
linesInFile.pop_front();
i++;
}
return 0;
}
string getFileName() {
string fileName;
cout << "Enter text file name: ";
cin >> fileName;
cout << endl;
return fileName;
}
deque<string> getLines(string fileName) {
deque<string> allLinesInText;
string line;
ifstream textFile(fileName);
while (getline(textFile, line)) {
allLinesInText.push_back(line);
}
textFile.close();
return allLinesInText;
}
vector<string> getKeywords(string lines) {
vector<string> keywords;
vector<string> keyTokens;
keyTokens.push_back("BEGIN");
keyTokens.push_back("END");
keyTokens.push_back("FOR");
for (int j = 0; j < 3; j++) {
//check each string in the deque for each of the keyword tokens
//erase the individual occurence in the string as we count them to prevent recounts
//and simplify the string as we go
string keyword = keyTokens.at(j);
while (lines.find(keyword) != string::npos) {
keywords.push_back(keyword);
//erase keyword at index j of keytokens vector from the temporary string
lines.replace(lines.find(keyword), keyword.length(), "");
}
}
return keywords;
}
vector<string> getIdentifiers(string lines) {
vector<string> identifiers;
int j;
for (int i = 0; i < lines.size(); i++) {
j = i;
if (islower(lines.at(i))) {
}
}
return identifiers;
}
vector<string> getConstants(string lines) {
vector<string> constants;
return constants;
}
vector<string> getOperators(string lines) {
vector<string> operators;
vector<string> opTokens;
opTokens.push_back("*");
opTokens.push_back("/");
opTokens.push_back("++");
opTokens.push_back("--");
opTokens.push_back("==");
opTokens.push_back("+");
opTokens.push_back("-");
opTokens.push_back("=");
opTokens.push_back("<");
opTokens.push_back(">");
opTokens.push_back("&&");
opTokens.push_back("||");
opTokens.push_back("!");
for (int j = 0; j < 13; j++) {
//check each string in the deque for each of the keyword tokens
//erase the individual occurence in the string as we count them to prevent recounts
//and simplify the string as we go
string op = opTokens.at(j);
while (lines.find(op) != string::npos) {
operators.push_back(op);
//erase keyword at index j of keytokens vector from the temporary string
lines.replace(lines.find(op), op.length(), "");
}
}
return operators;
}
vector<string> getDelimiters(string lines) {
vector<string> delimiters;
vector<string> delTokens;
delTokens.push_back(";");
delTokens.push_back(",");
for (int j = 0; j < 2; j++) {
//check each string in the deque for each of the keyword tokens
//erase the individual occurence in the string as we count them to prevent recounts
//and simplify the string as we go
string del = delTokens.at(j);
while (lines.find(del) != string::npos) {
delimiters.push_back(del);
//erase keyword at index j of keytokens vector from the temporary string
lines.replace(lines.find(del), del.length(), "");
}
}
return delimiters;
}
/*
string simplifyLines(string lines) {
string simpleLines = lines;
for (int i = 0; i < lines.size(); i++) {
if (isupper(lines.at(i))) {
simpleLines.replace(simpleLines.at(i), 1, "");
}
else if (simpleLines.at(i) == ' ') {
simpleLines.replace(simpleLines.at(i), 1, "");
}
else if (simpleLines.at(i) == '\t') {
simpleLines.replace(simpleLines.at(i), 1, "");
}
else if (simpleLines.at(i) == '\n') {
simpleLines.replace(simpleLines.at(i), 1, "");
}
else if (simpleLines.at(i) == '\v') {
simpleLines.replace(simpleLines.at(i), 1, "");
}
else if (simpleLines.at(i) == '\f') {
simpleLines.replace(simpleLines.at(i), 1, "");
}
else if (simpleLines.at(i) == '\r') {
simpleLines.replace(simpleLines.at(i), 1, "");
}
else if (simpleLines.at(i) == ('*' || '/' || '++' || '--' || '==' || '+' || '-' || '=' || '<>' || '&&' || '||' || '!')) {
simpleLines.replace(simpleLines.at(i), 1, "");
}
}
return simpleLines;
}
*/