Debian Codegraph @

templates/Token.template

raw
1 /**
2 * Describes the input token stream.
3 */
4
5 #if TOKEN_EXTENDS
6 ${SUPPORT_CLASS_VISIBILITY_PUBLIC?public :}class Token extends ${TOKEN_EXTENDS} implements java.io.Serializable {
7 #else
8 ${SUPPORT_CLASS_VISIBILITY_PUBLIC?public :}class Token implements java.io.Serializable {
9 #fi
10
11 /**
12 * The version identifier for this Serializable class.
13 * Increment only if the <i>serialized</i> form of the
14 * class changes.
15 */
16 private static final long serialVersionUID = 1L;
17
18 /**
19 * An integer that describes the kind of this token. This numbering
20 * system is determined by JavaCCParser, and a table of these numbers is
21 * stored in the file ...Constants.java.
22 */
23 public int kind;
24 #if KEEP_LINE_COLUMN
25
26 /** The line number of the first character of this Token. */
27 public int beginLine;
28 /** The column number of the first character of this Token. */
29 public int beginColumn;
30 /** The line number of the last character of this Token. */
31 public int endLine;
32 /** The column number of the last character of this Token. */
33 public int endColumn;
34 #fi
35
36 /**
37 * The string image of the token.
38 */
39 public String image;
40
41 /**
42 * A reference to the next regular (non-special) token from the input
43 * stream. If this is the last token from the input stream, or if the
44 * token manager has not read tokens beyond this one, this field is
45 * set to null. This is true only if this token is also a regular
46 * token. Otherwise, see below for a description of the contents of
47 * this field.
48 */
49 public Token next;
50
51 /**
52 * This field is used to access special tokens that occur prior to this
53 * token, but after the immediately preceding regular (non-special) token.
54 * If there are no such special tokens, this field is set to null.
55 * When there are more than one such special token, this field refers
56 * to the last of these special tokens, which in turn refers to the next
57 * previous special token through its specialToken field, and so on
58 * until the first special token (whose specialToken field is null).
59 * The next fields of special tokens refer to other special tokens that
60 * immediately follow it (without an intervening regular token). If there
61 * is no such token, this field is null.
62 */
63 public Token specialToken;
64
65 /**
66 * An optional attribute value of the Token.
67 * Tokens which are not used as syntactic sugar will often contain
68 * meaningful values that will be used later on by the compiler or
69 * interpreter. This attribute value is often different from the image.
70 * Any subclass of Token that actually wants to return a non-null value can
71 * override this method as appropriate.
72 */
73 public Object getValue() {
74 return null;
75 }
76
77 /**
78 * No-argument constructor
79 */
80 public Token() {}
81
82 /**
83 * Constructs a new token for the specified Image.
84 */
85 public Token(int kind)
86 {
87 this(kind, null);
88 }
89
90 /**
91 * Constructs a new token for the specified Image and Kind.
92 */
93 public Token(int kind, String image)
94 {
95 this.kind = kind;
96 this.image = image;
97 }
98
99 /**
100 * Returns the image.
101 */
102 public String toString()
103 {
104 return image;
105 }
106
107 /**
108 * Returns a new Token object, by default. However, if you want, you
109 * can create and return subclass objects based on the value of ofKind.
110 * Simply add the cases to the switch for all those special cases.
111 * For example, if you have a subclass of Token called IDToken that
112 * you want to create if ofKind is ID, simply add something like :
113 *
114 * case MyParserConstants.ID : return new IDToken(ofKind, image);
115 *
116 * to the following switch statement. Then you can cast matchedToken
117 * variable to the appropriate type and use sit in your lexical actions.
118 */
119 public static Token newToken(int ofKind, String image)
120 {
121 switch(ofKind)
122 {
123 default : return new Token(ofKind, image);
124 }
125 }
126
127 public static Token newToken(int ofKind)
128 {
129 return newToken(ofKind, null);
130 }
131
132 }