Class Token

java.lang.Object
tech.ixor.calclox.token.Token

public class Token extends Object
One lexical unit of CalcLox source.

Tokens retain the original lexeme and one-based line number. Literal tokens also carry their decoded runtime value: a Double for numbers, a String for strings, and null for tokens without a literal value.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final String
    Exact source text occupied by this token.
    final int
    One-based source line on which the token ends.
    final Object
    Parsed literal value, or null when the token has none.
    final TokenType
    Syntactic category recognized by the scanner.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Token(TokenType type, String lexeme, Object literal, int line)
    Creates a token.
  • Method Summary

    Modifier and Type
    Method
    Description
    Formats the token as its type, lexeme, and literal value for diagnostics.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • type

      public final TokenType type
      Syntactic category recognized by the scanner.
    • lexeme

      public final String lexeme
      Exact source text occupied by this token.
    • literal

      public final Object literal
      Parsed literal value, or null when the token has none.
    • line

      public final int line
      One-based source line on which the token ends.
  • Constructor Details

    • Token

      public Token(TokenType type, String lexeme, Object literal, int line)
      Creates a token.
      Parameters:
      type - syntactic category
      lexeme - original source text
      literal - parsed literal value
      line - one-based source line
  • Method Details

    • toString

      public String toString()
      Formats the token as its type, lexeme, and literal value for diagnostics.
      Overrides:
      toString in class Object
      Returns:
      diagnostic token representation