package rebelsky.compiler.lexer;

import rebelsky.compiler.misc.Symbol;

/**
 * Tokens for a generic tokenizer/lexer/whatever.
 *
 * @author Samuel A. Rebelsky
 * @version 1.1 of January 2004
 */
public class Token 
  implements Symbol
{
  // +-----------+---------------------------------------------------------
  // | Constants |
  // +-----------+

  /** 
   * The token type of identifiers (which are not necessarily equal
   * if they have the same type).
   */ 
  public static final int IDENTIFIER = 1;

  /**
   * The token type of integers.
   */
  public static final int INTEGER = 2;

  /**
   * The token type of real numbers.
   */
  public static final int REAL = 3;

  /**
   * The token type of strings.
   */
  public static final int STRING = 4;

  /**
   * The token type of characters.
   */
  public static final int CHAR = 5;

  /**
   * The starting value of user-defined token IDs
   */
  public static final int FIRSTID = 101;


  // +--------+------------------------------------------------------------
  // | Fields |
  // +--------+

  /** The type of the token. */
  int tokType;


  // +--------------+------------------------------------------------------
  // | Constructors |
  // +--------------+

  /**
   * Create a new token of a specified type.
   */
  public Token(int type) {
    this.tokType = type;
  } // Token(int)


  // +-----------+---------------------------------------------------------
  // | Observers |
  // +-----------+

  /**
   * Determine if the token is the same as another token.  Should
   * probably be overridden by subclasses.
   */
  public boolean equals(Token other) {
    return this == other;
  } // equals(Token)

  /**
   * Get the type of the token.
   */
  public int getType() {
    return this.tokType;
  } // getType(void)

  /**
   * Convert the token to a string (e.g., for printing).  Should
   * probably be overridden by subclasses.
   */
  public String toString() {
    return "Token[" + this.tokType + "]";
  } // toString(void)

} // class Token

