-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSemantics.java
34 lines (29 loc) · 1.2 KB
/
Semantics.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
import java.io.*;
import minipython.lexer.Lexer;
import minipython.parser.Parser;
import minipython.node.*;
import java.util.*;
// The Semantics class calls and applies the Visitors
public class Semantics {
public static void main(String[] args) {
try {
Parser parser =
new Parser(
new Lexer(
new PushbackReader(
new FileReader(args[0].toString()), 1024)));
// Hash tables for storing declared variables and functions
Hashtable<String, Node> variables = new Hashtable<>();
Hashtable<String, Node> functions = new Hashtable<>();
Hashtable<Node, FirstVisitor.VAR_TYPES> variableTypes = new Hashtable<>();
Start ast = parser.parse();
// Apply the visitors
FirstVisitor firstVisitor = new FirstVisitor(variables, functions, variableTypes);
ast.apply(firstVisitor);
SecondVisitor secondVisitor = new SecondVisitor(firstVisitor.getVariables(), firstVisitor.getFunctions(), firstVisitor.getVariableTypes());
ast.apply(secondVisitor);
} catch (Exception e) {
System.err.println(e);
}
}
}