Class Token

java.lang.Object
  |
  +--Token

public class Token
extends Object

Each Token object represents one token from the compiler input stream.


Field Summary
static int COMMA
           
static int EOF
           
static int ID
           
static int INT
           
static int KW_ELSE
           
static int KW_IF
           
static int KW_INT
           
static int KW_RETURN
           
static int KW_WHILE
           
private  String label
           
static int LCURLY
           
static int LPAREN
           
static int OP_ADD
           
static int OP_ASSIGN
           
static int OP_EQ
           
static int OP_GT
           
static int OP_MUL
           
static int OP_NOT
           
static int OP_SUB
           
static int RCURLY
           
static int RPAREN
           
static int SEMICOLON
           
private static String[] tokenTypes
           
private  int type
           
private  int value
           
 
Constructor Summary
Token(int t)
          Construct a new Token with no attributes except its type.
Token(int t, int v)
          Construct a new Token with an associated integer value attribute.
Token(int t, String s)
          Construct a new Token with an associated String attribute.
 
Method Summary
 String getLabel()
          Get the String attribute of this object.
 int getType()
          Get the type of this Token.
 int getValue()
          Get the integer attribute of this object.
 String toString()
          Provide the String that describes this Token.
static String toString(int type)
          Provide the String that describes this Token type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

type

private int type

value

private int value

label

private String label

tokenTypes

private static String[] tokenTypes

EOF

public static final int EOF
See Also:
Constant Field Values

ID

public static final int ID
See Also:
Constant Field Values

INT

public static final int INT
See Also:
Constant Field Values

KW_INT

public static final int KW_INT
See Also:
Constant Field Values

KW_RETURN

public static final int KW_RETURN
See Also:
Constant Field Values

KW_IF

public static final int KW_IF
See Also:
Constant Field Values

KW_ELSE

public static final int KW_ELSE
See Also:
Constant Field Values

KW_WHILE

public static final int KW_WHILE
See Also:
Constant Field Values

OP_NOT

public static final int OP_NOT
See Also:
Constant Field Values

OP_EQ

public static final int OP_EQ
See Also:
Constant Field Values

OP_GT

public static final int OP_GT
See Also:
Constant Field Values

OP_ADD

public static final int OP_ADD
See Also:
Constant Field Values

OP_SUB

public static final int OP_SUB
See Also:
Constant Field Values

OP_MUL

public static final int OP_MUL
See Also:
Constant Field Values

OP_ASSIGN

public static final int OP_ASSIGN
See Also:
Constant Field Values

LPAREN

public static final int LPAREN
See Also:
Constant Field Values

RPAREN

public static final int RPAREN
See Also:
Constant Field Values

LCURLY

public static final int LCURLY
See Also:
Constant Field Values

RCURLY

public static final int RCURLY
See Also:
Constant Field Values

COMMA

public static final int COMMA
See Also:
Constant Field Values

SEMICOLON

public static final int SEMICOLON
See Also:
Constant Field Values
Constructor Detail

Token

public Token(int t)
Construct a new Token with no attributes except its type.

Parameters:
t - the token type, one of the types defined by the Token class.

Token

public Token(int t,
             String s)
Construct a new Token with an associated String attribute.

Parameters:
t - the token type (probably Token.ID).
s - the actual String name of the id

Token

public Token(int t,
             int v)
Construct a new Token with an associated integer value attribute.

Parameters:
t - the token type (probably Token.INT).
v - the value of the integer that this token represents
Method Detail

getType

public int getType()
Get the type of this Token.

Returns:
the Token type

getLabel

public String getLabel()
Get the String attribute of this object.

Returns:
the Token string

getValue

public int getValue()
Get the integer attribute of this object.

Returns:
the Token value

toString

public String toString()
Provide the String that describes this Token.

Overrides:
toString in class Object

toString

public static String toString(int type)
Provide the String that describes this Token type.

Returns:
the String the describes this Token type.