public class Token
extends java.lang.Object
To read in the tokens of a postscript file, without interpretation, we might do the following:
public static voidmain(String[] args)
{ int i=0;Reader
r = newReader()
;Token
t; while (r.hasNext()
) { t =r.next()
; if (t.isSymbol()
&& // only if symbol: t.getSymbol
().equals("quit")
) break; // process token System.out.println(i+": "+t); i++; } }
Modifier and Type | Field and Description |
---|---|
static int |
BooleanKind
Token is a boolean.
|
static int |
NumberKind
Token is a number.
|
static int |
ProcedureKind
Token is a procedure.
|
static int |
SymbolKind
Token is a symbol.
|
Constructor and Description |
---|
Token(boolean bool)
Construct a boolean token
|
Token(double value)
Construct a numeric token.
|
Token(structure5.List<Token> proc)
Construct a procedure.
|
Token(java.lang.String symbol)
Construct a symbol token
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object other)
Returns true if this token has the same value as the other.
|
boolean |
getBoolean()
Fetch boolean value of token, provided it's a boolean.
|
double |
getNumber()
Fetch numeric value of token, provided it's a number.
|
structure5.List<Token> |
getProcedure()
Fetch the list of tokens associated with a procedure token.
|
java.lang.String |
getSymbol()
Fetch string value of token, provided it's a symbol.
|
boolean |
isBoolean()
Returns true if and only if this token is a boolean.
|
boolean |
isNumber()
Returns true if and only if this token is a number.
|
boolean |
isProcedure()
Returns true if and only if this token is a procedure.
|
boolean |
isSymbol()
Returns true if and only if this token is a symbol.
|
int |
kind()
Return the kind of token.
|
java.lang.String |
toString()
Generates string representation of a token.
|
public static final int NumberKind
public static final int BooleanKind
public static final int SymbolKind
public static final int ProcedureKind
public Token(double value)
value
- the numeric value of the tokenpublic Token(boolean bool)
bool
- the boolean value of the tokenpublic Token(java.lang.String symbol)
symbol
- the string representing the tokenpublic Token(structure5.List<Token> proc)
proc
- the list of tokens that make up the procedure.public int kind()
public boolean isNumber()
public boolean isBoolean()
public boolean isSymbol()
public boolean isProcedure()
public double getNumber()
public boolean getBoolean()
public java.lang.String getSymbol()
public structure5.List<Token> getProcedure()
public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
other
- another tokenpublic java.lang.String toString()
toString
in class java.lang.Object