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
|
import java.io.*;
import visitor.*;
import parse.*;
import syntaxtree.*;
import java.util.*;
import st.*;
import misc.*;
import heat.*;
public class Typecheck {
public static void main(String[] args) {
Node root = null;
try {
root = new MiniJavaParser(System.in).Goal();
// Pretty-print the tree. PPrinter inherits from
// GJDepthFirst<R,A>. R=Void, A=String.
PPrinter<Void,String> pp = new PPrinter<Void,String>();
root.accept(pp, "");
// Build the symbol table. Top-down visitor, inherits from
// GJDepthFirst<R,A>. R=Void, A=Integer.
try {
SymbolTable symt = new SymbolTable();
MinimalLogger.info("Populating classes...");
root.accept(new SymTableClasses<Void>(), symt);
MinimalLogger.info("Populating methods...");
root.accept(new SymTableMethods<Void>(), symt);
MinimalLogger.info("Populating variables...");
root.accept(new SymTableVars<Void>(), symt);
MinimalLogger.info("Populating extensions...");
root.accept(new SymTableExtend<Void>(), symt);
MinimalLogger.info(symt.toString());
HeatVisitor hv = new HeatVisitor(symt);
root.accept(hv, null);
System.out.println("Program type checked successfully");
} catch (TypecheckException e) {
System.out.println("Type error");
MinimalLogger.severe(String.format("Reason: %s",
e.toString()));
}
}
catch (ParseException e) {
System.out.println(e.toString());
System.exit(1);
}
}
}
|