1 package antlr;
2
3 * <b>SOFTWARE RIGHTS</b>
5 * <p>
6 * ANTLR 2.5.0 MageLang Institute, 1998
7 * <p>
8 * We reserve no legal rights to the ANTLR--it is fully in the
9 * public domain. An individual or company may do whatever
10 * they wish with source code distributed with ANTLR or the
11 * code generated by ANTLR, including the incorporation of
12 * ANTLR, or its output, into commerical software.
13 * <p>
14 * We encourage users to develop software with ANTLR. However,
15 * we do ask that credit is given to us for developing
16 * ANTLR. By "credit", we mean that if you use ANTLR or
17 * incorporate any source code into one of your programs
18 * (commercial product, research project, or otherwise) that
19 * you acknowledge this fact somewhere in the documentation,
20 * research report, etc... If you like ANTLR and have
21 * developed a nice tool with the output, please mention that
22 * you developed it using ANTLR. In addition, we ask that the
23 * headers remain intact in our source code. As long as these
24 * guidelines are kept, we expect to continue enhancing this
25 * system and expect to make other tools available as they are
26 * completed.
27 * <p>
28 * The ANTLR gang:
29 * @version ANTLR 2.5.0 MageLang Institute, 1998
30 * @author Terence Parr, <a href=http://www.MageLang.com>MageLang Institute</a>
31 * @author <br>John Lilley, <a href=http://www.Empathy.com>Empathy Software</a>
32 */
33 import java.io.*;
34 import java.util.Hashtable;
35 import java.util.Enumeration;
36 import antlr.collections.impl.Vector;
37
38 class SimpleTokenManager implements TokenManager {
39 protected int maxToken = Token.MIN_USER_TYPE;
40 protected Vector vocabulary;
42 private Hashtable table;
44 protected Tool tool;
46 protected String name;
48
49
50 SimpleTokenManager(String name_, Tool tool_) {
51 tool = tool_;
52 name = name_;
53 vocabulary = new Vector(1);
55 table = new Hashtable();
56
57 TokenSymbol ts = new TokenSymbol("EOF");
59 ts.setTokenType(Token.EOF_TYPE);
60 define(ts);
61
62 // define <epsilon> but only in the vocabulary vector
64 vocabulary.ensureCapacity(GrammarAnalyzer.EPSILON_TYPE);
65 // The only time epsilon can appear (in warning) is when
66 // it implies end-of-syn-pred, so we just set its string here.
67 vocabulary.setElementAt("<end-of-syn-pred>", GrammarAnalyzer.EPSILON_TYPE);
68 */
69
70 vocabulary.ensureCapacity(Token.NULL_TREE_LOOKAHEAD);
72 vocabulary.setElementAt("NULL_TREE_LOOKAHEAD", Token.NULL_TREE_LOOKAHEAD);
73 }
74
75 public void define(TokenSymbol ts) {
76 vocabulary.ensureCapacity(ts.getTokenType());
78 vocabulary.setElementAt(ts.getId(), ts.getTokenType());
79 table.put(ts.getId(), ts);
81 }
82
83 public String getName() { return name; }
84
85 public String getTokenStringAt(int idx) {
86 return (String)vocabulary.elementAt(idx);
87 }
88
89 public TokenSymbol getTokenSymbol(String sym) {
90 return (TokenSymbol)table.get(sym);
91 }
92
93 public Enumeration getTokenSymbolElements() {
94 return table.elements();
95 }
96 * @return A Vector of TokenSymbol
98 */
99 public Vector getVocabulary() {
100 return vocabulary;
101 }
102
103 public boolean isReadOnly() { return false; }
104
105 public int maxTokenType() {
106 return maxToken-1;
107 }
108
109 public int nextTokenType() {
110 return maxToken++;
111 }
112
113 public void setName(String name_) { name = name_; }
114
115 public boolean tokenDefined(String symbol) {
116 return table.containsKey(symbol);
117 }
118 }
119