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).
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    boolean
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a LookaheadScanner.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns true if an error has occurred, and false otherwise.
    Returns the name of the source file.
    void
    Scans to the next token in the input.
    Returns the previous token.
    void
    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.
    void
    Returns to the previously recorded position in the input stream of tokens.
    Returns the current token.

    Methods inherited from class java.lang.Object

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

    • isLookingAhead

      public boolean isLookingAhead
  • 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.