KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > sql > compile > Token


1 /*
2
3    Derby - Class org.apache.derby.impl.sql.compile.Token
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to you under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

21
22 package org.apache.derby.impl.sql.compile;
23
24 /**
25  * Describes the input token stream.
26  */

27
28 public class Token {
29
30   /**
31    * An integer that describes the kind of this token. This numbering
32    * system is determined by JavaCCParser, and a table of these numbers is
33    * stored in the file ...Constants.java.
34    */

35   public int kind;
36
37   /**
38    * beginLine and beginColumn describe the position of the first character
39    * of this token; endLine and endColumn describe the position of the
40    * last character of this token.
41    */

42   public int beginLine, beginColumn, endLine, endColumn;
43
44   /**
45    * beginOffset and endOffset are useful for siphoning substrings out of
46    * the Statement so that we can recompile the substrings at upgrade time.
47    * For instance, VIEW definitions and the Restrictions on Published Tables
48    * need to be recompiled at upgrade time.
49    */

50   public int beginOffset, endOffset;
51
52   /**
53    * The string image of the token.
54    */

55   public String JavaDoc image;
56
57   /**
58    * A reference to the next regular (non-special) token from the input
59    * stream. If this is the last token from the input stream, or if the
60    * token manager has not read tokens beyond this one, this field is
61    * set to null. This is true only if this token is also a regular
62    * token. Otherwise, see below for a description of the contents of
63    * this field.
64    */

65   public Token next;
66
67   /**
68    * This field is used to access special tokens that occur prior to this
69    * token, but after the immediately preceding regular (non-special) token.
70    * If there are no such special tokens, this field is set to null.
71    * When there are more than one such special token, this field refers
72    * to the last of these special tokens, which in turn refers to the next
73    * previous special token through its specialToken field, and so on
74    * until the first special token (whose specialToken field is null).
75    * The next fields of special tokens refer to other special tokens that
76    * immediately follow it (without an intervening regular token). If there
77    * is no such token, this field is null.
78    */

79   public Token specialToken;
80
81   /**
82    * Returns the image.
83    */

84   public String JavaDoc toString()
85   {
86      return image;
87   }
88
89   /**
90    * Returns a new Token object, by default. However, if you want, you
91    * can create and return subclass objects based on the value of ofKind.
92    * Simply add the cases to the switch for all those special cases.
93    * For example, if you have a subclass of Token called IDToken that
94    * you want to create if ofKind is ID, simlpy add something like :
95    *
96    * case MyParserConstants.ID : return new IDToken();
97    *
98    * to the following switch statement. Then you can cast matchedToken
99    * variable to the appropriate type and use it in your lexical actions.
100    */

101   public static final Token newToken(int ofKind)
102   {
103      switch(ofKind)
104      {
105        default : return new Token();
106      }
107   }
108
109 }
110
Popular Tags