Class Token

java.lang.Object
  extended by Token

public class Token
extends java.lang.Object

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


Field Summary
static int COLON
           
static int COMMA
           
static int DOT
           
static int EOF
           
static int ID
           
static int INTEGER
           
static int KW_CLASS
           
static int KW_ELSE
           
static int KW_IF
           
static int KW_INTEGER
           
static int KW_MOVIE
           
static int KW_PROLOG
           
static int KW_REAL
           
static int KW_SHOW
           
static int KW_STATIC
           
static int KW_VOID
           
private  java.lang.String label
           
static int LCURLY
           
static int LPAREN
           
static int OP_ADD
           
static int OP_ASSIGN
           
static int OP_DIV
           
static int OP_EQ
           
static int OP_GT
           
static int OP_LT
           
static int OP_MUL
           
static int OP_NOT
           
static int OP_SUB
           
static int RCURLY
           
static int REAL
           
static int RPAREN
           
static int SEMICOLON
           
private static java.lang.String[] tokenTypes
          The token types as Strings for use in toString.
private  int type
           
private  java.lang.Number value
           
 
Constructor Summary
Token(int t)
          Construct a new Token with no attributes except its type.
Token(int t, double v)
          Construct a new Token with an associated real value attribute.
Token(int t, int v)
          Construct a new Token with an associated integer value attribute.
Token(int t, java.lang.String s)
          Construct a new Token with an associated String attribute.
 
Method Summary
 double getDoubleValue()
          Get the numeric attribute of this token as a double value.
 int getIntValue()
          Get the numeric attribute of this token as an int value.
 java.lang.String getLabel()
          Get the String attribute of this object.
 int getType()
          Get the type of this Token.
 java.lang.String toString()
          Provide the String that describes this Token.
static java.lang.String typeLabel(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 java.lang.Number value

label

private java.lang.String label

tokenTypes

private static java.lang.String[] tokenTypes
The token types as Strings for use in toString. The index of each string must match the Token type so that it gets displayed correctly.


EOF

public static final int EOF
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

DOT

public static final int DOT
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

COLON

public static final int COLON
See Also:
Constant Field Values

ID

public static final int ID
See Also:
Constant Field Values

INTEGER

public static final int INTEGER
See Also:
Constant Field Values

REAL

public static final int REAL
See Also:
Constant Field Values

OP_ASSIGN

public static final int OP_ASSIGN
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_LT

public static final int OP_LT
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_DIV

public static final int OP_DIV
See Also:
Constant Field Values

KW_STATIC

public static final int KW_STATIC
See Also:
Constant Field Values

KW_VOID

public static final int KW_VOID
See Also:
Constant Field Values

KW_INTEGER

public static final int KW_INTEGER
See Also:
Constant Field Values

KW_REAL

public static final int KW_REAL
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_PROLOG

public static final int KW_PROLOG
See Also:
Constant Field Values

KW_MOVIE

public static final int KW_MOVIE
See Also:
Constant Field Values

KW_CLASS

public static final int KW_CLASS
See Also:
Constant Field Values

KW_SHOW

public static final int KW_SHOW
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,
             java.lang.String s)
Construct a new Token with an associated String attribute.

Parameters:
t - the token type (probably Token.ID).
s - the value of the String attribute for this token

Token

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

Parameters:
t - the token type (probably Token.INTEGER).
v - the integer value of the numeric attribute for this token

Token

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

Parameters:
t - the token type (probably Token.REAL).
v - the double value of the numeric attribute for this token
Method Detail

getType

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

Returns:
the Token type

getLabel

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

Returns:
the Token string

getIntValue

public int getIntValue()
Get the numeric attribute of this token as an int value.

Returns:
the value of the numeric attribute of this token as an int value

getDoubleValue

public double getDoubleValue()
Get the numeric attribute of this token as a double value.

Returns:
the value of the numeric attribute of this token as a double value

toString

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

Overrides:
toString in class java.lang.Object

typeLabel

public static java.lang.String typeLabel(int type)
Provide the String that describes this Token type.

Parameters:
type - the Token type to be described. Must be a valid (defined) Token type, or a runtime Exception will occur.
Returns:
the String the describes this Token type.