Package jminusminus

Class LookaheadScanner

java.lang.Object
jminusminus.LookaheadScanner

class LookaheadScanner extends Object
A lexical analyzer for j-- that interfaces with the hand-written parser (Parser). It provides a backtracking mechanism, and makes use of the underlying hand-written scanner (Scanner).
  • Constructor Details

    • LookaheadScanner

      public LookaheadScanner(String fileName) throws FileNotFoundException
      Constructs a LookaheadScanner.
      Parameters:
      fileName - the name of the file containing the source.
      Throws:
      FileNotFoundException - when the named file cannot be found.
  • Method Details

    • next

      public void next()
      Scans to the next token in the input.
    • recordPosition

      public void recordPosition()
      Records the current position in the input, so that we can start looking ahead in the input (and later return to this position) --- the current and subsequent tokens are queued until returnToPosition() is invoked.
    • returnToPosition

      public void returnToPosition()
      Returns to the previously recorded position in the input stream of tokens.
    • token

      public TokenInfo token()
      Returns the current token.
      Returns:
      the current token.
    • previousToken

      public TokenInfo previousToken()
      Returns the previous token.
      Returns:
      the previous token.
    • errorHasOccured

      public boolean errorHasOccured()
      Returns true if an error has occurred, and false otherwise.
      Returns:
      true if an error has occurred, and false otherwise.
    • fileName

      public String fileName()
      Returns the name of the source file.
      Returns:
      the name of the source file.