-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathExampleTypeCheckerTest.java
More file actions
52 lines (44 loc) · 1.23 KB
/
ExampleTypeCheckerTest.java
File metadata and controls
52 lines (44 loc) · 1.23 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
import java.io.*;
import java_cup.runtime.*;
public class ExampleTypeCheckerTest{
public static void main(String[] args) throws Exception
{
Reader reader = null;
if (args.length == 1) {
File input = new File(args[0]);
if (!input.canRead()) {
System.out.println("Error: could not read ["+input+"]");
}
reader = new FileReader(input);
}
else {
reader = new InputStreamReader(System.in);
}
ExampleScanner scanner = new ExampleScanner(reader); // create scanner
parser parser = new parser(scanner); // create parser
Program program = null;
try {
program = (Program) parser.parse().value;
//program = (Program) parser.debug_parse().value; // parse
//The above line of code will output current state and what token is being processed
}
catch (Exception e) {
e.printStackTrace();
}
System.out.print(program.toString(0));
//Now test type checking
try
{
program.typeCheck();
System.out.println("Type checking complete!");
}
catch (ExampleException e)
{
System.out.println(e.toString());
}
}
public static void error(String s)
{
System.out.println(s);
}
}