-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTypeCheckingTest.java
More file actions
56 lines (53 loc) · 1.73 KB
/
TypeCheckingTest.java
File metadata and controls
56 lines (53 loc) · 1.73 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
import java.io.*;
import java_cup.runtime.*;
/****
*
* This is a simple stand-alone testing program for the lexer defined in
* tokens.jflex. The main method accepts an input file as its first
* command-line argument. It then calls the lexer's next_token method with an
* input reader for that file. The value of each Symbol returned by next_token
* is printed to stanard output.
*
* The following command-line invocation will read in the test program in the
* file "scanner-test.p" and print out each token found in that file:
*
* java ScannerTest scanner-test.p
*
*/
public class TypeCheckingTest{
public static void main(String[] args) {
Reader reader = null;
//If no file provided, take from the input stream
if (args.length == 1) {
File input = new File(args[0]);
if (!input.canRead()) {
System.out.println("Error: could not read ["+input+"]");
}
try {
reader = new FileReader(input);
} catch (Exception e) {
e.printStackTrace();
}
}
else {
reader = new InputStreamReader(System.in);
}
Lexer lexer = new Lexer(reader);
parser parser = new parser(lexer);
Program program = null;
try {
program = (Program) parser.parse().value;
}
catch (Exception e) {
e.printStackTrace();
}
if (program != null) {
try {
String typeCatch = program.typeCheck();
System.err.println("All good!");
} catch (UTDLangException u) {
System.err.println(u.toString());
}
}
}
}