Class Token

java.lang.Object
  extended by Token

public class Token
extends Object

A class that implements Tokens that might be read from a stream of postscript commands. There are, basically, four types of tokens:

Example usage:

To read in the tokens of a postscript file, without interpretation, we might do the following:

  public static void main(String[] args)
  {
      int i=0;
      Reader r = new Reader();
      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++;
      }
  }


Field Summary
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 Summary
Token(boolean bool)
          Construct a boolean token
Token(double value)
          Construct a numeric token.
Token(List<Token> proc)
          Construct a procedure.
Token(String symbol)
          Construct a symbol token
 
Method Summary
 boolean equals(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.
 List<Token> getProcedure()
          Fetch the list of tokens associated with a procedure token.
 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.
 String toString()
          Generates string representation of a token.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NumberKind

public static final int NumberKind
Token is a number.

See Also:
Constant Field Values

BooleanKind

public static final int BooleanKind
Token is a boolean.

See Also:
Constant Field Values

SymbolKind

public static final int SymbolKind
Token is a symbol.

See Also:
Constant Field Values

ProcedureKind

public static final int ProcedureKind
Token is a procedure.

See Also:
Constant Field Values
Constructor Detail

Token

public Token(double value)
Construct a numeric token.

Parameters:
value - the numeric value of the token

Token

public Token(boolean bool)
Construct a boolean token

Parameters:
bool - the boolean value of the token

Token

public Token(String symbol)
Construct a symbol token

Parameters:
symbol - the string representing the token

Token

public Token(List<Token> proc)
Construct a procedure.

Parameters:
proc - the list of tokens that make up the procedure.
Method Detail

kind

public int kind()
Return the kind of token. Great for use in switch statements.

Returns:
integer representing the kind of the token, usually Token.number, Token.symbol, etc.

isNumber

public boolean isNumber()
Returns true if and only if this token is a number.

Returns:
true iff token is a number.

isBoolean

public boolean isBoolean()
Returns true if and only if this token is a boolean.

Returns:
true iff token is a boolean.

isSymbol

public boolean isSymbol()
Returns true if and only if this token is a symbol.

Returns:
true iff token is a symbol.

isProcedure

public boolean isProcedure()
Returns true if and only if this token is a procedure.

Returns:
true iff token is a procedure.

getNumber

public double getNumber()
Fetch numeric value of token, provided it's a number.

Returns:
token's numeric value.

getBoolean

public boolean getBoolean()
Fetch boolean value of token, provided it's a boolean.

Returns:
token's boolean value.

getSymbol

public String getSymbol()
Fetch string value of token, provided it's a symbol.

Returns:
token's string value.

getProcedure

public List<Token> getProcedure()
Fetch the list of tokens associated with a procedure token.

Returns:
a List of associated token values.

equals

public boolean equals(Object other)
Returns true if this token has the same value as the other. (Does not work correctly for procedures, but sufficient.)

Overrides:
equals in class Object
Parameters:
other - another token
Returns:
true if and only if this token is equivalent to other

toString

public String toString()
Generates string representation of a token.

Overrides:
toString in class Object
Returns:
a string representation of the token.