-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathParserTest2.java
45 lines (38 loc) · 1.57 KB
/
ParserTest2.java
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
import java.io.*;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import minipython.lexer.Lexer;
import minipython.parser.Parser;
import minipython.node.Start;
public class ParserTest2 {
public static void main(String[] args) {
try {
Parser parser =
new Parser(
new Lexer(
new PushbackReader(
new FileReader(args[0].toString()), 1024)));
Start ast = parser.parse();
ast.apply(new ASTPrinter());
Hashtable<String, Variable> variables = new Hashtable();
Hashtable<String, List<Function>> functions = new Hashtable(); /* List of functions for overloading */
System.out.println("Entering First Visitor:");
ast.apply(new Visitor1(functions));
System.out.println("Entering Second Visitor:");
ast.apply(new Visitor2(variables, functions));
System.out.println("Entering Third Visitor:");
ast.apply(new Visitor3(variables, functions));
System.out.println("Functions");
System.out.println(functions);
System.out.println("Variables");
for (Map.Entry<String, Variable> entry : variables.entrySet()) {
String key = entry.getKey();
Variable value = entry.getValue();
System.out.println("Key: " + key + " Value: " + value);
}
} catch (Exception e) {
System.err.println(e);
}
}
}