-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompiler.java
More file actions
43 lines (36 loc) · 1.32 KB
/
Compiler.java
File metadata and controls
43 lines (36 loc) · 1.32 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
import java.io.BufferedReader;
//The main coderunner class.
public class Compiler {
public static void main(String[] args) {
VM myVm = new VM();
// For Lexer.
System.out.println(Colors.GREEN_BOLD_BRIGHT + "\n::LEXER::\n" + Colors.RESET);
String filename = "Input.txt";
if (args.length == 1)
filename = args[0];
Lexer.fr = Lexer.getFileReader(filename);
Lexer.fw = Lexer.getFileWriter();
Lexer.run();
try {
Lexer.fr.close();
Lexer.fw.close();
} catch (Exception e) {
e.printStackTrace();
}
// For Parser.
System.out.println(Colors.CYAN_BOLD_BRIGHT + "\n\n::PARSER::\n" + Colors.RESET);
Parser myParser = new Parser();
myParser.setFileReader("Output.txt");
myParser.reader = new BufferedReader(myParser.fr);
myParser.lookAhead = myParser.getNextToken();
myParser.Code();
System.out.println(Colors.GREEN_BOLD + "Code Parsing Successful!" + Colors.RESET);
myParser.printSymbolTable();
myParser.printTAC();
// For Virtual Machine.
System.out.println(Colors.YELLOW_BOLD_BRIGHT + "\n\n::VIRTUAL MACHINE::\n" + Colors.RESET);
myVm.readTAC();
myVm.readSymbolTable();
myVm.execute();
}
}