001 /* Generated By:JavaCC: Do not edit this line. Token.java Version 5.0 */
002 /* JavaCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COL=null,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
003 /*
004 * Copyright (c) 2009 The JOMC Project
005 * Copyright (c) 2005 Christian Schulte <cs@jomc.org>
006 * All rights reserved.
007 *
008 * Redistribution and use in source and binary forms, with or without
009 * modification, are permitted provided that the following conditions
010 * are met:
011 *
012 * o Redistributions of source code must retain the above copyright
013 * notice, this list of conditions and the following disclaimer.
014 *
015 * o Redistributions in binary form must reproduce the above copyright
016 * notice, this list of conditions and the following disclaimer in
017 * the documentation and/or other materials provided with the
018 * distribution.
019 *
020 * THIS SOFTWARE IS PROVIDED BY THE JOMC PROJECT AND CONTRIBUTORS "AS IS"
021 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
022 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
023 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE JOMC PROJECT OR
024 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
027 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
028 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
029 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
030 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031 *
032 * $Id: VersionParser.jj 733 2009-10-05 17:22:57Z schulte2005 $
033 *
034 */
035 package org.jomc.util;
036
037 /**
038 * Describes the input token stream.
039 */
040
041 public class Token implements java.io.Serializable {
042
043 /**
044 * The version identifier for this Serializable class.
045 * Increment only if the <i>serialized</i> form of the
046 * class changes.
047 */
048 private static final long serialVersionUID = 1L;
049
050 /**
051 * An integer that describes the kind of this token. This numbering
052 * system is determined by JavaCCParser, and a table of these numbers is
053 * stored in the file ...Constants.java.
054 */
055 public int kind;
056
057 /** The line number of the first character of this Token. */
058 public int beginLine;
059 /** The column number of the first character of this Token. */
060 public int beginColumn;
061 /** The line number of the last character of this Token. */
062 public int endLine;
063 /** The column number of the last character of this Token. */
064 public int endColumn;
065
066 /**
067 * The string image of the token.
068 */
069 public String image;
070
071 /**
072 * A reference to the next regular (non-special) token from the input
073 * stream. If this is the last token from the input stream, or if the
074 * token manager has not read tokens beyond this one, this field is
075 * set to null. This is true only if this token is also a regular
076 * token. Otherwise, see below for a description of the contents of
077 * this field.
078 */
079 public Token next;
080
081 /**
082 * This field is used to access special tokens that occur prior to this
083 * token, but after the immediately preceding regular (non-special) token.
084 * If there are no such special tokens, this field is set to null.
085 * When there are more than one such special token, this field refers
086 * to the last of these special tokens, which in turn refers to the next
087 * previous special token through its specialToken field, and so on
088 * until the first special token (whose specialToken field is null).
089 * The next fields of special tokens refer to other special tokens that
090 * immediately follow it (without an intervening regular token). If there
091 * is no such token, this field is null.
092 */
093 public Token specialToken;
094
095 /**
096 * An optional attribute value of the Token.
097 * Tokens which are not used as syntactic sugar will often contain
098 * meaningful values that will be used later on by the compiler or
099 * interpreter. This attribute value is often different from the image.
100 * Any subclass of Token that actually wants to return a non-null value can
101 * override this method as appropriate.
102 */
103 public Object getValue() {
104 return null;
105 }
106
107 /**
108 * No-argument constructor
109 */
110 public Token() {}
111
112 /**
113 * Constructs a new token for the specified Image.
114 */
115 public Token(int kind)
116 {
117 this(kind, null);
118 }
119
120 /**
121 * Constructs a new token for the specified Image and Kind.
122 */
123 public Token(int kind, String image)
124 {
125 this.kind = kind;
126 this.image = image;
127 }
128
129 /**
130 * Returns the image.
131 */
132 public String toString()
133 {
134 return image;
135 }
136
137 /**
138 * Returns a new Token object, by default. However, if you want, you
139 * can create and return subclass objects based on the value of ofKind.
140 * Simply add the cases to the switch for all those special cases.
141 * For example, if you have a subclass of Token called IDToken that
142 * you want to create if ofKind is ID, simply add something like :
143 *
144 * case MyParserConstants.ID : return new IDToken(ofKind, image);
145 *
146 * to the following switch statement. Then you can cast matchedToken
147 * variable to the appropriate type and use sit in your lexical actions.
148 */
149 public static Token newToken(int ofKind, String image)
150 {
151 switch(ofKind)
152 {
153 default : return new Token(ofKind, image);
154 }
155 }
156
157 public static Token newToken(int ofKind)
158 {
159 return newToken(ofKind, null);
160 }
161
162 }
163 /* JavaCC - OriginalChecksum=9aa809715876b7db9611a62322c43cb4 (do not edit this line) */