-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
33 lines (26 loc) · 805 Bytes
/
main.cpp
File metadata and controls
33 lines (26 loc) · 805 Bytes
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
#include <iostream>
#include <fstream>
#include <string>
#include "./headers/scanner.h"
#include "./headers/parser.h"
#include "./headers/interpreter.h"
int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "Usage: " << argv[0] << " <file.k>" << std::endl;
return 1;
}
std::ifstream file(argv[1]);
if (!file.is_open()) {
std::cerr << "Error: Could not open file " << argv[1] << std::endl;
return 1;
}
std::string source((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
file.close();
Scanner scanner(source);
auto tokens = scanner.scanTokens();
Parser parser(tokens);
auto statements = parser.parse();
Interpreter interpreter;
interpreter.interpret(statements);
return 0;
}