-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
50 lines (46 loc) · 1.47 KB
/
main.cpp
File metadata and controls
50 lines (46 loc) · 1.47 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
/******************************************
* Simulator project- first milestone
* Elad Israel
* 313448888
* Narkis Shallev Kermizi
* 205832447
******************************************/
#include <string>
#include <fstream>
#include <vector>
#include <iostream>
#include "TextAnalyzer.h"
using namespace std;
/* Receive a line or a set of commands and values from the user. Transfer them to the lexer
* and then to the parser. */
int main(int argc, char *argv[]) {
vector<string> separated;
if (argc == 2) { // from file
fstream file;
string buffer;
file.open(argv[1], ios_base::in);
if (!file.is_open()) {
throw "cannot open file!";
}
getline(file, buffer);
while (!file.eof()) {
vector<string> tmpV = TextAnalyzer::lexer(buffer);
separated.insert(separated.end(), tmpV.begin(), tmpV.end());
getline(file, buffer);
}
vector<string> tmpV = TextAnalyzer::lexer(buffer);
separated.insert(separated.end(), tmpV.begin(), tmpV.end());
file.close();
} else if (argc == 1) { // from users input
string tmpS;
getline(cin, tmpS);
vector<string> tmpV = TextAnalyzer::lexer(tmpS);
separated.insert(separated.end(), tmpV.begin(), tmpV.end());
} else { //invalid arguments
throw "invalid arguments!";
}
bool shouldStop = false;
TextAnalyzer::parse(separated, shouldStop);
while (true) {}
return 0;
}