-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
45 lines (42 loc) · 1.05 KB
/
main.cpp
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
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include "Interpreter.h"
using namespace std;
/*
* main function that runs the interpreter.
* reads the script line by line.
* */
int main(int argc, char* argv[]) {
Interpreter interpreter;
vector<string> endProgram = {"exit"};
string inputStr;
// if we have a filename to read from:
if (argc == 2) {
ifstream script(argv[1]);
interpreter.setStream(script);
while (getline(script, inputStr)) {
vector<string> line = Interpreter::lexer(inputStr);
interpreter.parser(line, 0);
}
return 0;
}
/*
* else, we read from the command line.
* and parse each line.
* */
while (getline(cin, inputStr)) {
if (Interpreter::isScriptFile(inputStr)) {
ifstream script(inputStr);
interpreter.setStream(script);
while (getline(script, inputStr)) {
vector<string> line = Interpreter::lexer(inputStr);
interpreter.parser(line, 0);
}
interpreter.parser(endProgram, 0);
}
vector<string> line = Interpreter::lexer(inputStr);
interpreter.parser(line, 0);
}
}