-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.java
More file actions
54 lines (48 loc) · 1.43 KB
/
Main.java
File metadata and controls
54 lines (48 loc) · 1.43 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
import syntaxtree.*;
import visitor.*;
import java.util.*;
import java.io.*;
class Main{
public static void main(String [] args){
if(args.length==0){
System.err.println("<inputFile> missing");
System.exit(-1);
}
for(int i=0; i<args.length; i++) {
FileInputStream flsin = null;
try{
System.err.println("FILE ["+args[i]+"]");
flsin = new FileInputStream(args[i]);
MiniJavaParser parser = new MiniJavaParser(flsin);
Goal root = parser.Goal();
SymbolTable symboltable = new SymbolTable();
SymbolTable finalsymboltable = new SymbolTable();
VisitorSymbolTable visitorsymboltable = new VisitorSymbolTable(symboltable);
root.accept(visitorsymboltable, null);
TypeChecking typechecking = new TypeChecking(symboltable, finalsymboltable);
root.accept(typechecking, null);
finalsymboltable.addoffsets();
System.err.println("Program compiled successfully!");
}
catch(RuntimeException ex){
System.out.println("Compilation error at:");
System.out.println(ex.getMessage()+"\n");
continue;
}
catch(ParseException ex){
System.out.println(ex.getMessage());
}
catch(FileNotFoundException ex){
System.err.println(ex.getMessage());
}
finally{
try{
if(flsin!=null) flsin.close();
}
catch(IOException ex){
System.err.println(ex.getMessage());
}
}
}
}
}