-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTokenTable.java
More file actions
52 lines (44 loc) · 1.39 KB
/
TokenTable.java
File metadata and controls
52 lines (44 loc) · 1.39 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.util.HashMap;
public class TokenTable {
private HashMap<String, Integer> table;
public TokenTable() {
this.table = new HashMap<String, Integer>();
this.table.put("IF", 1);
this.table.put("THEN", 2);
this.table.put("ELSE", 3);
this.table.put("FI", 4);
this.table.put("LOOP", 5);
this.table.put("BREAK", 6);
this.table.put("READ", 7);
this.table.put("PRINT", 8);
this.table.put("AND", 9);
this.table.put("OR", 0);
this.table.put("END", 31);
this.table.put(".", 11);
this.table.put(")", 12);
this.table.put("(", 13);
this.table.put("/", 14);
this.table.put("*", 15);
this.table.put("-", 16);
this.table.put("+", 17);
this.table.put("<>", 18);
this.table.put(">", 19);
this.table.put(">=", 20);
this.table.put("=", 21);
this.table.put("<=", 22);
this.table.put("<", 23);
this.table.put(":=", 24);
this.table.put(";", 25);
this.table.put("SPACE", 26);
this.table.put("EOL", 27);
this.table.put("IDENTIFIER", 28);
this.table.put("NUMBER", 29);
this.table.put("STRING", 3);
}
public boolean isToken(String s) {
return this.table.containsKey(s);
}
public int getCode(String s) {
return this.table.get(s);
}
}