KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jbet > Token


1 /*
2  * JBET - Java Binary Enhancement Tool
3  * Copyright (c) 2003 Networks Associates Technology, Inc.
4  *
5  * This software was developed under DARPA/SPAWAR contract
6  * N66001-00-C-8602 "SPMA" as part of the
7  * DARPA OASIS research program.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  * notice, this list of conditions and the following disclaimer in the
16  * documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */

30
31 package jbet;
32
33 /**
34  * The Token class.
35  *
36  * This file contains fields that hold tokens (type, value), and code
37  * that constructs different types of tokens or converts tokens into
38  * strings.
39  *
40  * $Id: Token.java,v 1.4 2003/09/09 17:31:54 areisse Exp $
41  *
42  * @author Larry D'Anna
43  * @version
44  */

45
46 public class Token {
47
48     public int type; // The first 256 of these are reserved for opt types
49

50     // token value storage
51
public String JavaDoc text;
52     public long l;
53     public double d;
54
55     /*
56      * With the exception of DEFAULT and DONOR which are used in
57      * manipulating the Jbet.lexerVars Hashtable, all of these token
58      * types are created by Lexer.
59      */

60     public static final int EOF = 0x101;
61     public static final int TAG = 0x102;
62     public static final int NAME = 0x103;
63     public static final int END_OF_OPTS = 0x104;
64     public static final int TYPE = 0x105;
65     public static final int DEFAULT = 0x106; // set default class Jbet.setDefault
66
public static final int DONOR = 0x107; // set default donor class
67
// Jbet.setDefaultDonor
68
public static final int DESCRIPTOR = 0x108;
69     public static final int STRING = 0x109;
70     public static final int INT = 0x10A;
71     public static final int LABEL = 0x10B;
72     public static final int FLOAT = 0x10C;
73     public static final int EOL = '\n';
74
75
76     // Constructors (only called from Lexer.java)
77

78     /** Constructor.
79      * Used for EOF, END_OF_OPTS, EOL and opt token type creation.
80      */

81     public Token (int t) {
82     type = t;
83     text = null;
84     }
85
86     
87     /** Constructor.
88      * Used for TAG, NAME, STRING, DESCRIPTOR, TYPE, and LABEL token
89      * type creation.
90      */

91     public Token (int t, String JavaDoc s) {
92     type = t;
93     text = s;
94     }
95
96     /** Constructor.
97      * Used for INT token type creation.
98      */

99     public Token (int t, long s) {
100     type = t;
101     l = s;
102     }
103
104     /** Constructor.
105      * Used for FLOAT token type creation.
106      */

107     public Token (int t, double s) {
108     type = t;
109     d = s;
110     }
111
112     /** Return a string rep.
113      * @return printable string
114      */

115     public String JavaDoc toString() {
116     if (type < 256)
117         return "'" + ((char)type) + "'";
118     switch (type) {
119     case DEFAULT:
120         return "<DEFAULT>";
121     case DONOR:
122         return "<DONOR>";
123     case EOF:
124         return "EOF";
125     case END_OF_OPTS:
126         return "END_OF_OPTS";
127     case STRING:
128         return '"' + text + '"';
129     case DESCRIPTOR:
130     case TYPE:
131     case TAG:
132         return text;
133     case LABEL:
134         return text + ":";
135     case INT:
136         return "" + l;
137     }
138     return null;
139     }
140
141 }
142
143
Popular Tags