Class Token

java.lang.Object
  extended by Token

public class Token
extends java.lang.Object

Tokens returned by the scanner. CS536, Fall 2007.


Field Summary
 TokenCode code
          A code indicating the token class of this token.
 int column
          The column of the first character of this token.
 int line
          The line on which this token appears.
 java.lang.Object value
          The value of this token, if any.
 
Constructor Summary
Token(TokenCode code, int line, int column)
          Creates a new token with null value.
Token(TokenCode code, int line, int column, java.lang.Object value)
          Creates a new token.
 
Method Summary
 int intValue()
          Returns an integer code corresponding to this token.
 java.lang.String toString()
          Returns a printable representation of this token.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

code

public final TokenCode code
A code indicating the token class of this token.


line

public final int line
The line on which this token appears. The first line of the input file is line 1.


column

public final int column
The column of the first character of this token. The first characater of a line is column 1.


value

public final java.lang.Object value
The value of this token, if any. Otherwise, null.

Constructor Detail

Token

public Token(TokenCode code,
             int line,
             int column,
             java.lang.Object value)
Creates a new token.

Parameters:
code - the token code.
line - the line on which the token appears.
column - the column of the first character of the token.
value - the token value.

Token

public Token(TokenCode code,
             int line,
             int column)
Creates a new token with null value.

Parameters:
code - the code.
line - the line on which the token appears.
column - the column of the first character of the token.
Method Detail

toString

public java.lang.String toString()
Returns a printable representation of this token. The result has the format Token@line,column: display-string(value) or Token@line,column: display-string if value is null. The display-string is code.toString().

Overrides:
toString in class java.lang.Object
Returns:
a String representing this token.

intValue

public int intValue()
Returns an integer code corresponding to this token.

Returns:
the token code.