Class Scanner

java.lang.Object
tech.ixor.calclox.Scanner

public class Scanner extends Object
Converts CalcLox source text into the token stream consumed by Parser.

The scanner recognizes identifiers, reserved words, decimal numbers, strings, punctuation, and operators. Spaces, tabs, carriage returns, and // line comments are ignored. Line breaks are retained as token line metadata so later compilation and runtime errors can identify their source location.

A scanner instance is single-use. Call scanTokens() once for a given source.

  • Constructor Details

    • Scanner

      public Scanner(String source)
      Creates a scanner positioned at the beginning of the supplied source.
      Parameters:
      source - complete CalcLox source text
      Throws:
      NullPointerException - if source is null
  • Method Details

    • scanTokens

      public List<Token> scanTokens()
      Scans the complete source and appends a final EOF token. Number literals are represented as Double; string literal values omit their surrounding quotation marks.
      Returns:
      tokens in source order, including the terminating EOF token
      Throws:
      CalcLoxRunnerError - if the source contains an unknown character or an unterminated string