Skip to content

Commit fad33ca

Browse files
Add files via upload
1 parent e305290 commit fad33ca

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

JunLang.cpp

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,21 @@ using namespace std;
99
#define _VERSION_ "1.00"
1010
#define _DEFAULT_BUFFER_SIZE_ 1024
1111
string identifiers[] = {
12-
"output"
12+
"output",
13+
"wrap"
1314
};
1415

1516

17+
struct UnknowIdentifier : public exception {
18+
const char * what () const throw () {
19+
return "Unknow identifier.";
20+
}
21+
};
22+
struct FileCannotOpen : public exception {
23+
const char * what () const throw () {
24+
return "File cannot open.";
25+
}
26+
};
1627
vector<string> split(string str, char delim) {
1728
stringstream ss(str);
1829
string item;
@@ -37,22 +48,31 @@ int main (int argc, char* argv[]) {
3748
char buffer[bufferSize];
3849
ifstream file(fileName);
3950
if (!file.is_open()) {
40-
cout << "[Error] File cannot open." << endl;
51+
throw FileCannotOpen();
4152
}
4253
while (file.good()) {
4354
file.getline(buffer, sizeof(buffer));
4455
vector<string> vec(split(string(buffer), ' '));
4556
for (vector<string>::iterator it = vec.begin(); it != vec.end(); it++) {
57+
bool unknow = true;
4658
for (int i = 0; i < (sizeof(identifiers) / sizeof(string)); i++) {
47-
if (identifiers[i] != *it) {
48-
if (*(it - 1) == identifiers[0]) {
49-
cout << *it << endl;
50-
}
51-
else {
52-
cout << "[Error] Unknow identifiers: " << *it << endl;
53-
}
59+
if (identifiers[i] == *it) {
60+
unknow = false;
5461
}
5562
}
63+
if (!unknow) {
64+
if (*it == identifiers[0]) {
65+
cout << *(it + 1);
66+
break;
67+
}
68+
if (*it == identifiers[1]) {
69+
cout << endl;
70+
}
71+
// TODO =====================================================================================================
72+
}
73+
else {
74+
throw UnknowIdentifier();
75+
}
5676
}
5777
}
5878
}

0 commit comments

Comments
 (0)