-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interpreter.js
34 lines (27 loc) · 931 Bytes
/
Interpreter.js
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
let fs = require("fs");
let lexer = require("./Lexer");
let parser = require("./Parser");
let programFile = "SamplePrograms/Simple.lang";
// if(process.argv.length >= 3) {
// programFile = process.argv[2];
// }
fs.readFile(programFile, "utf-8", function(error, data) {
if(error) {
console.log("ERROR READING FILE: " + programFile);
console.log("WITH ERROR: " + error.message);
}
else {
console.log("READ FILE: " + programFile + " SUCCESSFUL!")
const program = data;
console.log("\nSTARTED LEXING");
const tokens = lexer.lex(program);
console.log("FINISHED LEXING");
console.log("\nTOKEN STREAM: ");
console.log(tokens);
console.log("\nSTARTED PARSING");
const parseTree = parser.parse(tokens);
console.log("FINISHED PARSING");
console.log("PARSE TREE:");
parser.print();
}
});