-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathExampleParserTest.java
More file actions
43 lines (34 loc) · 1 KB
/
ExampleParserTest.java
File metadata and controls
43 lines (34 loc) · 1 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
import java.io.*;
import java_cup.runtime.*;
public class ExampleParserTest{
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));
}
public static void error(String s)
{
System.out.println(s);
}
}