-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsce322a1p1d.java
More file actions
66 lines (54 loc) · 1.63 KB
/
csce322a1p1d.java
File metadata and controls
66 lines (54 loc) · 1.63 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
57
58
59
60
61
62
63
64
65
66
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.dfa.*;
import org.antlr.v4.runtime.atn.*;
import java.util.*;
public class csce322a1p1d {
public static void main(String[] args) {
CharStream stream = null;
try {
stream = new ANTLRFileStream(args[0]);
} catch(Exception e) {
System.out.println("Error: file not found");
}
csce322a1p1 lexer = new csce322a1p1(stream);
// While there are more tokens
while((lexer.nextToken()).getType() != -1) {
// Print out each token on a new line
switch (lexer.getType()) {
case csce322a1p1.BEGIN_SECTION:
System.out.println("Start Section: " + lexer.getText());
break;
case csce322a1p1.END_SECTION:
System.out.println("End Section: " + lexer.getText());
break;
case csce322a1p1.LEVEL:
case csce322a1p1.SCORE:
case csce322a1p1.MAP:
case csce322a1p1.LIVES:
System.out.println("Section: " + lexer.getText());
break;
case csce322a1p1.ASSIGNMENT:
System.out.println("Assignment: " + lexer.getText());
break;
case csce322a1p1.NUMBER:
System.out.println("Number: " + lexer.getText());
break;
case csce322a1p1.WALL:
case csce322a1p1.FOOD:
case csce322a1p1.POWER:
case csce322a1p1.EMPTY:
case csce322a1p1.BORDER:
case csce322a1p1.GHOST:
case csce322a1p1.PACMAN:
System.out.println("Cell: " + lexer.getText());
break;
case csce322a1p1.ROW_SEPARATOR:
System.out.println("Comma: " + lexer.getText());
break;
case csce322a1p1.MAP_TERMINATOR:
System.out.println("Semicolon: " + lexer.getText());
break;
}
}
}
}