-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
49 lines (45 loc) · 1.14 KB
/
main.cpp
File metadata and controls
49 lines (45 loc) · 1.14 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
#include <string>
#include <vector>
#include <scanner.hpp>
#include <error.hpp>
#include <parser.hpp>
#include <graph.hpp>
#include <visitor.hpp>
#include <memory.hpp>
#include <fstream>
#include <interpreter.hpp>
using namespace std;
// Extracts the file name from command arguments
string getName(int argCount, char *args[])
{
if (argCount < 2)
error("less number of arguments");
return string(args[1]);
}
// Extract the code from file
string getCode(const string& name)
{
ifstream file(name);
if (!file)
error("can't read file: " + name);
return string((istreambuf_iterator<char>(file)), (istreambuf_iterator<char>()));
}
// Main
int main(int argCount, char *args[])
{
try
{
string name = getName(argCount, args);
string code = getCode(name);
vector<Token> token = scan(code);
map<string, unique_ptr<StackBase>> stackmap = generateStackMap(token);
vector<unique_ptr<Statement>> v = parse(token, stackmap);
Interpreter i(v);
}
catch (const std::exception &e)
{
// Terminates the program when exception is caught
return -1;
}
return 0;
}