package rebelsky.compiler.lexer;

import rebelsky.compiler.misc.EndOfStream;

/**
 * A stream of tokens, typically built from a stream of characters.
 * Usually used as input for a parser.
 *
 * Note that you can determine the current position in the character
 * stream by querying that stream.
 *
 * @author Samuel A. Rebelsky
 * @version 1.0 of October 2002
 */
public interface TokenStream
{
  // +-----------+----------------------------------------------------------
  // | Observers |
  // +-----------+

  /**
   * Determine if the stream has any more tokens.
   */
  public boolean hasMore();

  /**
   * Peek at the next token.
   *
   * @exception EndOfStream
   *   If no tokens remain.
   * @exception TokenException
   *   If there are errors in tokenizing.
   * @exception Exception
   *   If I/O errors occurs.
   */
  public Token peek()
    throws EndOfStream,TokenException,Exception;

  // +-----------+----------------------------------------------------------
  // | Modifiers |
  // +-----------+

  /**
   * Get the next token, advancing the input stream to the following
   * token.
   *
   * @exception EndOfStream
   *   If no tokens remain.
   * @exception TokenException
   *   If there are errors in tokenizing.
   * @exception Exception
   *   If I/O errors occurs.
   */
  public Token next()
    throws EndOfStream,TokenException,Exception;
} // interface TokenStream

