Repository navigation
Expand file tree
/
Copy pathMain.java
More file actions
58 lines (46 loc) · 1.9 KB
/
Copy pathMain.java
File metadata and controls
58 lines (46 loc) · 1.9 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
50
51
52
53
54
55
56
57
58
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import symboltable.STValidator;
import symboltable.SemanticError;
import symboltable.State;
import symboltable.TypeChecker;
import symboltable.OffsetPrinter;
import symboltable.Codegen;
import syntaxtree.*;
public class Main {
public static void main(String[] args) {
if (args.length < 1) {
System.err.println("Usage: java Main <inputFile1> [<inputFile2> ...]");
System.exit(1);
}
for (String path : args) {
System.err.println("=== " + path + " ===");
try (FileInputStream fis = new FileInputStream(path)) {
MiniJavaParser parser = new MiniJavaParser(fis);
Goal root = parser.Goal();
STBuilder stb = new STBuilder();
root.accept(stb);
STValidator stv = new STValidator();
stv.resolveTypes(stb.globalTable);
stv.checkOverloads(stb.globalTable);
State state = new State();
TypeChecker typeChecker = new TypeChecker(stb.globalTable);
root.accept(typeChecker, state);
OffsetPrinter offsetPrinter = new OffsetPrinter();
offsetPrinter.compute(stb.globalTable);
offsetPrinter.print(stb.globalTable);
Codegen codegen = new Codegen(stb.globalTable);
codegen.generate(root, path, state);
System.err.println("Program parsed successfully.");
} catch (ParseException e) {
System.err.println(e.getMessage());
} catch (FileNotFoundException e) {
System.err.println(e.getMessage());
} catch (SemanticError e) {
System.err.println(e.getMessage());
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}
}