-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScanner.java
More file actions
38 lines (32 loc) · 975 Bytes
/
Scanner.java
File metadata and controls
38 lines (32 loc) · 975 Bytes
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
/*
File Name: CM.java
This file was repurposed from the SampleScanner given to start Checkpoint One
Contains the logic to run the scanner generated from jflex and cm.flex
*/
import java.io.InputStreamReader;
import java_cup.runtime.Symbol;
public class Scanner {
private Lexer scanner = null;
public Scanner( Lexer lexer ) {
scanner = lexer;
}
public Symbol getNextToken() throws java.io.IOException {
return scanner.next_token();
}
public static void main(String argv[]) {
try {
Scanner scanner = new Scanner(new Lexer(new InputStreamReader(System.in)));
Symbol tok = null;
while( (tok=scanner.getNextToken()) != null ) {
System.out.print(sym.terminalNames[tok.sym]);
if (tok.value != null)
System.out.print("(" + tok.value + ")");
System.out.println();
}
}
catch (Exception e) {
System.out.println("Unexpected exception:");
e.printStackTrace();
}
}
}