-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
64 lines (56 loc) · 1.69 KB
/
Copy pathMain.java
File metadata and controls
64 lines (56 loc) · 1.69 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
59
60
61
62
63
64
//
// A modified version of the main() method found in the Java 1.1 grammar.
// To add your visitors to the program, go to near the end, and copy or
// replace the line "root.accept(new Visitor());" with your own visitor
//
import javacc_generated.*;
import syntaxtree.*;
import visitor.*;
public class Main {
public static void main(String args[]) {
ArithExpr parser;
if (args.length == 0) {
System.err.println("Reading from standard " +
"input . . .");
parser = new ArithExpr(System.in);
}
else if (args.length == 1) {
System.err.println("Reading from file " +
args[0] + " . . .");
try { parser = new ArithExpr(new java.io.FileInputStream(args[0])); }
catch (java.io.FileNotFoundException e) {
System.err.println("File " + args[0] +
" not found.");
return;
}
}
else {
System.err.println("Usage is one of:");
System.err.println(" java Main < inputfile");
System.err.println("OR");
System.err.println(" java Main inputfile");
return;
}
try {
//
// Here's where the AST actions and visiting take place.
//
Start root = ArithExpr.Start();
System.out.println("ArithExpr parsed " +
"successfully.");
System.out.println();
System.out.println("Calling the visitor from inner anonymous class:");
root.accept(new CodeGenVisitor() {
public void visit(Start n) {
//dumper.startAtNextToken();
n.accept(new CodeGenVisitor());
}
});
}
catch (ParseException e) {
System.err.println(e.getMessage());
System.err.println("Encountered errors " +
"during parse.");
}
}
}