-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
98 lines (78 loc) · 2.49 KB
/
main.cpp
File metadata and controls
98 lines (78 loc) · 2.49 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
#include <iostream>
#include <fstream>
#include <string>
#include "lexer.h"
#include "insert.h"
#include "delete.h"
#include "create.h"
#include "query.h"
using namespace std;
int main(int argc, char* argv[]) {
// open file
ifstream file(argv[1]);
Lexer lexer;
// create database db called "SSQL"
// create null vector<Table>
vector<Table> tableVector;
Database db("SSQL", tableVector);
// use Lexer to get tokens
vector<Token> tokens = lexer.getToken(file);
// separate every "line"
vector<Token> tokenLine;
int commandCount = 0;
while (!tokens.empty()) {
bool findDouhao = false;
vector<Token>::iterator iter;
for (iter = tokens.begin(); iter != tokens.end(); iter++) {
// indicate the end of line, cut it
if ((*iter).getName().compare(";") == 0) {
// copy to new vector
tokenLine.assign(tokens.begin(), ++iter);
// delete the line
tokens.erase(tokens.begin(), iter);
findDouhao = true;
break;
}
}
if (!findDouhao) {
cout << "Lack of ';'." << endl;
break;
}
commandCount++;
for (iter = tokenLine.begin(); iter != tokenLine.end(); iter++) {
if ((*iter).getType() == "error") {
cout << "In NO." << commandCount << " command contains error token: ["
<< (*iter).getName() << "]." << endl;
}
}
string first = tokenLine[0].getName();
first = TransLow(first);
if (first == "create") {
Create creator(tokenLine);
Table t = creator.create();
if (db.isTableExist(t.getName())) {
creator.printTest(true);
} else {
creator.printTest(false);
db.addTable(t);
}
}
else if (first == "insert") {
// fill in insert code
insert(tokenLine, db);
}
else if (first == "delete") {
deleteParse(db, tokenLine);
}
else if (first == "select") {
// fill in query code
queryParse(db, tokenLine);
}
else {
cout << "Syntax Error.\n";
}
// clear content in vector
tokenLine.clear();
}
return 0;
}