Package jminusminus
Class LookaheadScanner
java.lang.Object
jminusminus.LookaheadScanner
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
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns true if an error has occurred, and false otherwise.fileName()
Returns the name of the source file.void
next()
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.token()
Returns the current token.
-
Field Details
-
isLookingAhead
public boolean isLookingAhead
-
-
Constructor Details
-
LookaheadScanner
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
Returns the current token.- Returns:
- the current token.
-
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
Returns the name of the source file.- Returns:
- the name of the source file.
-