at.dms.compiler
Class Scanner

java.lang.Object
  |
  +--at.dms.compiler.Scanner
All Implemented Interfaces:
antlr.TokenStream
Direct Known Subclasses:
KjcScanner

public abstract class Scanner
extends java.lang.Object
implements antlr.TokenStream

This class describes the capabilities of lexers (token streams) to share a common input buffer and to handle line numbers.


Field Summary
protected  InputBuffer buffer
          The data source for this scanner.
 
Constructor Summary
protected Scanner(Compiler compiler, InputBuffer buffer)
          Constructs a new hand written scanner.
 
Method Summary
 InputBuffer getBuffer()
          Returns the input buffer.
 java.lang.String getFile()
          Returns the name of the source code file.
 JavadocComment getJavadocComment()
           
 int getLine()
          Returns the current line number in the source code.
 int getPosition()
          Returns the current position in the input stream.
 JavaStyleComment[] getStatementComment()
           
protected abstract  antlr.Token getToken()
          Returns the next token in the input.
 TokenReference getTokenReference()
          Returns the reference of the current token in the source file.
protected static boolean isJavaIdentifierStart(char c)
          Determines if the specified character is permissible as the first character in a Java identifier.
 antlr.Token nextToken()
          Identifiers/Keywords/true/false/null (start with java letter) numeric literal (start with number) character literal (start with single quote) string (start with double quote) separator (parens, braces, brackets, semicolon, comma, period) operator (equals, plus, minus, etc) whitespace comment (start with slash)
protected  boolean readJavaComment()
          Reads a Java style comment (with leading // or * or **).
protected  void reportTrouble(MessageDescription mess, java.lang.Object param1, java.lang.Object param2)
          Reports that an error has been detected in the lexical analyzer.
protected  void reportTrouble(PositionedError trouble)
          Reports that an error has been detected in the lexical analyzer.
protected  char scanEscapeSequence()
          Scans an escape sequence.
 void setLine(int line)
          Sets the current line number in the source code.
 void setPosition(int pos)
          Sets the current position in the input stream.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buffer

protected final InputBuffer buffer
The data source for this scanner.
Constructor Detail

Scanner

protected Scanner(Compiler compiler,
                  InputBuffer buffer)
Constructs a new hand written scanner.
Method Detail

getBuffer

public final InputBuffer getBuffer()
Returns the input buffer.

getFile

public final java.lang.String getFile()
Returns the name of the source code file.

getLine

public final int getLine()
Returns the current line number in the source code.

setLine

public final void setLine(int line)
Sets the current line number in the source code.

getPosition

public final int getPosition()
Returns the current position in the input stream.

setPosition

public final void setPosition(int pos)
Sets the current position in the input stream.

getTokenReference

public final TokenReference getTokenReference()
Returns the reference of the current token in the source file.

reportTrouble

protected final void reportTrouble(PositionedError trouble)
Reports that an error has been detected in the lexical analyzer. The handling is delegated to the compiler driver.
Parameters:
error - The error to report.

reportTrouble

protected final void reportTrouble(MessageDescription mess,
                                   java.lang.Object param1,
                                   java.lang.Object param2)
Reports that an error has been detected in the lexical analyzer. The handling is delegated to the compiler driver.
Parameters:
mess - the error message.
param1 - the first message parameter.
param2 - the second message parameter.

getToken

protected abstract antlr.Token getToken()
                                 throws PositionedError
Returns the next token in the input.

nextToken

public final antlr.Token nextToken()
Identifiers/Keywords/true/false/null (start with java letter) numeric literal (start with number) character literal (start with single quote) string (start with double quote) separator (parens, braces, brackets, semicolon, comma, period) operator (equals, plus, minus, etc) whitespace comment (start with slash)
Specified by:
nextToken in interface antlr.TokenStream

scanEscapeSequence

protected char scanEscapeSequence()
                           throws PositionedError
Scans an escape sequence. NOTE: scanXxx procedures do not return tokens.
Returns:
the scanned character.

isJavaIdentifierStart

protected static boolean isJavaIdentifierStart(char c)
Determines if the specified character is permissible as the first character in a Java identifier.
Returns:
true iff the character may start a Java identifier

readJavaComment

protected boolean readJavaComment()
                           throws PositionedError
Reads a Java style comment (with leading // or * or **).
Returns:
true iff a comment was read (the leading '/' is consumed)

getStatementComment

public JavaStyleComment[] getStatementComment()

getJavadocComment

public JavadocComment getJavadocComment()