xref: /aosp_15_r20/external/apache-commons-bcel/src/examples/Mini/Token.java (revision 0c56280ab0842982c46a149f7b9eaa497e31e292)
1*0c56280aSSorin Basca /*
2*0c56280aSSorin Basca  * Licensed to the Apache Software Foundation (ASF) under one or more
3*0c56280aSSorin Basca  * contributor license agreements.  See the NOTICE file distributed with
4*0c56280aSSorin Basca  * this work for additional information regarding copyright ownership.
5*0c56280aSSorin Basca  * The ASF licenses this file to You under the Apache License, Version 2.0
6*0c56280aSSorin Basca  * (the "License"); you may not use this file except in compliance with
7*0c56280aSSorin Basca  * the License.  You may obtain a copy of the License at
8*0c56280aSSorin Basca  *
9*0c56280aSSorin Basca  *      http://www.apache.org/licenses/LICENSE-2.0
10*0c56280aSSorin Basca  *
11*0c56280aSSorin Basca  *  Unless required by applicable law or agreed to in writing, software
12*0c56280aSSorin Basca  *  distributed under the License is distributed on an "AS IS" BASIS,
13*0c56280aSSorin Basca  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*0c56280aSSorin Basca  *  See the License for the specific language governing permissions and
15*0c56280aSSorin Basca  *  limitations under the License.
16*0c56280aSSorin Basca  *
17*0c56280aSSorin Basca  */
18*0c56280aSSorin Basca /* Generated By:JavaCC: Do not edit this line. Token.java Version 0.7pre3 */
19*0c56280aSSorin Basca package Mini;
20*0c56280aSSorin Basca 
21*0c56280aSSorin Basca /**
22*0c56280aSSorin Basca  * Describes the input token stream.
23*0c56280aSSorin Basca  */
24*0c56280aSSorin Basca 
25*0c56280aSSorin Basca public class Token {
26*0c56280aSSorin Basca 
27*0c56280aSSorin Basca   /**
28*0c56280aSSorin Basca    * An integer that describes the kind of this token.  This numbering
29*0c56280aSSorin Basca    * system is determined by JavaCCParser, and a table of these numbers is
30*0c56280aSSorin Basca    * stored in the file ...Constants.java.
31*0c56280aSSorin Basca    */
32*0c56280aSSorin Basca   public int kind;
33*0c56280aSSorin Basca 
34*0c56280aSSorin Basca   /**
35*0c56280aSSorin Basca    * beginLine and beginColumn describe the position of the first character
36*0c56280aSSorin Basca    * of this token; endLine and endColumn describe the position of the
37*0c56280aSSorin Basca    * last character of this token.
38*0c56280aSSorin Basca    */
39*0c56280aSSorin Basca   public int beginLine, beginColumn, endLine, endColumn;
40*0c56280aSSorin Basca 
41*0c56280aSSorin Basca   /**
42*0c56280aSSorin Basca    * The string image of the token.
43*0c56280aSSorin Basca    */
44*0c56280aSSorin Basca   public String image;
45*0c56280aSSorin Basca 
46*0c56280aSSorin Basca   /**
47*0c56280aSSorin Basca    * A reference to the next regular (non-special) token from the input
48*0c56280aSSorin Basca    * stream.  If this is the last token from the input stream, or if the
49*0c56280aSSorin Basca    * token manager has not read tokens beyond this one, this field is
50*0c56280aSSorin Basca    * set to null.  This is true only if this token is also a regular
51*0c56280aSSorin Basca    * token.  Otherwise, see below for a description of the contents of
52*0c56280aSSorin Basca    * this field.
53*0c56280aSSorin Basca    */
54*0c56280aSSorin Basca   public Token next;
55*0c56280aSSorin Basca 
56*0c56280aSSorin Basca   /**
57*0c56280aSSorin Basca    * This field is used to access special tokens that occur prior to this
58*0c56280aSSorin Basca    * token, but after the immediately preceding regular (non-special) token.
59*0c56280aSSorin Basca    * If there are no such special tokens, this field is set to null.
60*0c56280aSSorin Basca    * When there are more than one such special token, this field refers
61*0c56280aSSorin Basca    * to the last of these special tokens, which in turn refers to the next
62*0c56280aSSorin Basca    * previous special token through its specialToken field, and so on
63*0c56280aSSorin Basca    * until the first special token (whose specialToken field is null).
64*0c56280aSSorin Basca    * The next fields of special tokens refer to other special tokens that
65*0c56280aSSorin Basca    * immediately follow it (without an intervening regular token).  If there
66*0c56280aSSorin Basca    * is no such token, this field is null.
67*0c56280aSSorin Basca    */
68*0c56280aSSorin Basca   public Token specialToken;
69*0c56280aSSorin Basca 
70*0c56280aSSorin Basca   /**
71*0c56280aSSorin Basca    * Returns the image.
72*0c56280aSSorin Basca    */
73*0c56280aSSorin Basca   @Override
toString()74*0c56280aSSorin Basca   public final String toString()
75*0c56280aSSorin Basca   {
76*0c56280aSSorin Basca      return image;
77*0c56280aSSorin Basca   }
78*0c56280aSSorin Basca 
79*0c56280aSSorin Basca   /**
80*0c56280aSSorin Basca    * Returns a new Token object, by default. However, if you want, you
81*0c56280aSSorin Basca    * can create and return subclass objects based on the value of ofKind.
82*0c56280aSSorin Basca    * Simply add the cases to the switch for all those special cases.
83*0c56280aSSorin Basca    * For example, if you have a subclass of Token called IDToken that
84*0c56280aSSorin Basca    * you want to create if ofKind is ID, simlpy add something like :
85*0c56280aSSorin Basca    *
86*0c56280aSSorin Basca    *    case MyParserConstants.ID : return new IDToken();
87*0c56280aSSorin Basca    *
88*0c56280aSSorin Basca    * to the following switch statement. Then you can cast matchedToken
89*0c56280aSSorin Basca    * variable to the appropriate type and use it in your lexical actions.
90*0c56280aSSorin Basca    */
newToken(int ofKind)91*0c56280aSSorin Basca   public static Token newToken(int ofKind)
92*0c56280aSSorin Basca   {
93*0c56280aSSorin Basca      switch(ofKind)
94*0c56280aSSorin Basca      {
95*0c56280aSSorin Basca        default : return new Token();
96*0c56280aSSorin Basca      }
97*0c56280aSSorin Basca   }
98*0c56280aSSorin Basca 
99*0c56280aSSorin Basca }
100