|
Building Parsers with Java | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--sjm.parse.tokens.Token
A token represents a logical chunk of a string. For
example, a typical tokenizer would break the string
"1.23 <= 12.3" into three tokens: the number
1.23, a less-than-or-equal symbol, and the number 12.3. A
token is a receptacle, and relies on a tokenizer to decide
precisely how to divide a string into tokens.
| Field Summary | |
static Token |
EOF
A constant indicating that there are no more tokens |
protected double |
nval
|
protected java.lang.String |
sval
|
static TokenType |
TT_EOF
A constant indicating that the end of the stream has been read. |
static TokenType |
TT_NUMBER
A constant indicating that a token is a number, like 3.14 |
static TokenType |
TT_QUOTED
A constant indicating that a token is a quoted string, like "Launch Mi". |
static TokenType |
TT_SYMBOL
A constant indicating that a token is a symbol like "<=". |
static TokenType |
TT_WORD
A constant indicating a token is a word, like "cat" |
protected TokenType |
ttype
|
| Constructor Summary | |
Token(char c)
Constructs a token from the given char. |
|
Token(double nval)
Constructs a token from the given number. |
|
Token(java.lang.String sval)
Constructs a token from the given string. |
|
Token(TokenType ttype,
java.lang.String sval,
double nval)
Constructs a token of the indicated type and associated string or numeric values. |
|
| Method Summary | |
boolean |
equals(java.lang.Object o)
Returns true if the supplied object is an equivalent token. |
boolean |
equalsIgnoreCase(java.lang.Object o)
Returns true if the supplied object is an equivalent token, given mellowness about case in strings and characters. |
boolean |
isNumber()
Returns true if this token is a number. |
boolean |
isQuotedString()
Returns true if this token is a quoted string. |
boolean |
isSymbol()
Returns true if this token is a symbol. |
boolean |
isWord()
Returns true if this token is a word. |
double |
nval()
Returns the numeric value of this token. |
java.lang.String |
sval()
Returns the string value of this token. |
java.lang.String |
toString()
Return a textual description of this object. |
TokenType |
ttype()
Returns the type of this token. |
java.lang.Object |
value()
Returns an object that represents the value of this token. |
| Methods inherited from class java.lang.Object |
clone,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
| Field Detail |
protected TokenType ttype
protected java.lang.String sval
protected double nval
public static final TokenType TT_EOF
public static final Token EOF
public static final TokenType TT_NUMBER
public static final TokenType TT_WORD
public static final TokenType TT_SYMBOL
public static final TokenType TT_QUOTED
| Constructor Detail |
public Token(char c)
char - the charpublic Token(double nval)
double - the numberpublic Token(java.lang.String sval)
String - the string
public Token(TokenType ttype,
java.lang.String sval,
double nval)
TokenType - the type of the token, typically one
of the constants this class definesstring - the string value of the token, typically
null except for WORD and QUOTED tokensdouble - the numeric value of the token, typically
0 except for NUMBER tokens| Method Detail |
public boolean equals(java.lang.Object o)
object - the object to comparepublic boolean equalsIgnoreCase(java.lang.Object o)
object - the object to comparepublic boolean isNumber()
public boolean isQuotedString()
public boolean isSymbol()
public boolean isWord()
public double nval()
public java.lang.String sval()
public java.lang.String toString()
public TokenType ttype()
public java.lang.Object value()
|
by Steve Metsker | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||