-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestAssembly.java
More file actions
51 lines (47 loc) · 1.58 KB
/
Copy pathTestAssembly.java
File metadata and controls
51 lines (47 loc) · 1.58 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
public class TestAssembly {
public static void main(String args[]) {
simplejava parser;
if (args.length < 1) {
System.out.print("Usage: java TestAssembly <filename>");
return;
}
try {
parser = new simplejava(new java.io.FileInputStream(args[0]));
} catch (java.io.FileNotFoundException e) {
System.out.println("File " + args[0] + " not found.");
return;
}
try {
ASTProgram prog = parser.program();
ASTPrintTree pt = new ASTPrintTree();
AATPrintTree pat = new AATPrintTree();
SemanticAnalyzer sa = new SemanticAnalyzer();
AATInterpreter intr;
System.out.println("Parsing Successful");
System.out.println("=================");
System.out.println("Printing AST ...");
System.out.println("=================");
prog.Accept(pt);
AATStatement assem = (AATStatement) prog.Accept(sa);
if (!CompError.anyErrors()) {
System.out.println("=================");
System.out.println("Printing AAT ...");
System.out.println("=================");
assem.Accept(pat);
intr = new AATInterpreter(assem);
System.out.println("========================");
System.out.println("Starting Interpreter ...");
System.out.println("========================");
intr.run();
System.out.println("========================");
System.out.println("Interpreter Done!");
System.out.println("========================");
} else {
System.out.println("Semantic Errors Detected. No AAT Created");
}
} catch (ParseException e) {
System.out.println(e.getMessage());
System.out.println("Parsing Failed");
}
}
}