-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
31 lines (29 loc) · 1.3 KB
/
Main.java
File metadata and controls
31 lines (29 loc) · 1.3 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
package icsi311;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Optional;
public class Main {
public static void main(String[] args) throws Exception{
/*
* Tries to run code, if it doesn't work it throws an exception.
*/
if(args.length < 2)
throw new Exception("args have not been declared!");
String scriptPath = args[0];
String inputPath = args[1];
// Reads files with getAllBytes.
Path myPath = Paths.get(scriptPath);
String content = new String(Files.readAllBytes(myPath));
//Lexer object created to create a linkedlist and display the tokens
Lexer translator = new Lexer(content);
//Parser initiated and is printed when Parse() is called.
Parser parser = new Parser(translator.getTokens());
// With parser initiated, interpret the program by retrieving the programnode from
// parse, and then interpret the programnode produced from parse and pass in
// the input file path.
Path input = Paths.get(inputPath);
Interpreter interpreter = new Interpreter(parser.Parse(), Optional.of(input));
interpreter.InterpretProgram();
}
}