edu.cornell.cs.sam.io
Interface Tokenizer

All Known Implementing Classes:
SamTokenizer

public interface Tokenizer


Nested Class Summary
static class Tokenizer.TokenType
          Represents the type of a tokenizer token
 
Method Summary
 boolean canPushBack()
          Checks if the stream can be pushed back
 boolean check(char c)
          Removes the next token if it is an operator, and matches the character c.
 boolean check(java.lang.String s)
          Removes the next token if it is a word, and matches the string s.
 void close()
          Closes the input stream
 char getCharacter()
          Returns the next token (unless it is not a character)
 java.lang.String getComment()
          Returns the next token (unless it is not a comment)
 float getFloat()
          Returns the next token (unless it is not a float)
 int getInt()
          Returns the next token (unless it is not an integer)
 char getOp()
          Returns the next token (unless it is not an operator)
 java.lang.String getString()
          Returns the next token (unless it is not a string)
 java.lang.String getWhitespaceBeforeToken()
          Returns the whitespace in the file before the current token.
 java.lang.String getWord()
          Returns the next token (unless it is not a word)
 int lineNo()
          Returns the line number of the last token requested
 void match(char c)
          Removes the next token if it is an operator, and matches the given character.
 void match(java.lang.String s)
          Removes the next token if it is a word, and matches the given string.
 int nextLineNo()
          Returns the line number of the next token to be read
 Tokenizer.TokenType peekAtKind()
          Returns the type of the next token
 void pushBack()
          Pushes the last token requested back.
 void skipToken()
          Skips the next token
 boolean test(char c)
          Checks if the next token is an operator and matches the character c.
 boolean test(java.lang.String s)
          Checks if the next token is a word and matches the string s.
 

Method Detail

peekAtKind

Tokenizer.TokenType peekAtKind()
Returns the type of the next token

Returns:
the type of the next token

getInt

int getInt()
           throws TokenizerException
Returns the next token (unless it is not an integer)

Returns:
the integer expected
Throws:
TokenizerException - if the next token is not an integer

getFloat

float getFloat()
               throws TokenizerException
Returns the next token (unless it is not a float)

Returns:
the floating point number expected
Throws:
TokenizerException - if the next token is not a float

getWord

java.lang.String getWord()
                         throws TokenizerException
Returns the next token (unless it is not a word)

Returns:
the word expected
Throws:
TokenizerException - if the next token is not a word

getString

java.lang.String getString()
                           throws TokenizerException
Returns the next token (unless it is not a string)

Returns:
the string expected
Throws:
TokenizerException - if the next token is not a string

getCharacter

char getCharacter()
                  throws TokenizerException
Returns the next token (unless it is not a character)

Returns:
the character expected
Throws:
TokenizerException - if the next token is not a character

getOp

char getOp()
           throws TokenizerException
Returns the next token (unless it is not an operator)

Returns:
the operator expected
Throws:
TokenizerException - if the next token is not an operator

getComment

java.lang.String getComment()
                            throws TokenizerException
Returns the next token (unless it is not a comment)

Returns:
the comment expected
Throws:
TokenizerException - if the next token is not a comment

match

void match(char c)
           throws TokenizerException
Removes the next token if it is an operator, and matches the given character. Otherwise, throws TokenizerException.

Parameters:
c - the character to match
Throws:
TokenizerException - if the next token is not c, or is not an operator token.

match

void match(java.lang.String s)
           throws TokenizerException
Removes the next token if it is a word, and matches the given string. Otherwise, throws TokenizerException.

Parameters:
s - the string to match
Throws:
TokenizerException - if the next token is not s, or is not a word token

check

boolean check(char c)
Removes the next token if it is an operator, and matches the character c. Otherwise, returns false.

Parameters:
c - the character to match
Returns:
true if the next token is an operator and matches c, false otherwise

check

boolean check(java.lang.String s)
Removes the next token if it is a word, and matches the string s. Otherwise, returns false.

Parameters:
s - the string to match
Returns:
true if the next token is a word, and matches s, false otherwise

test

boolean test(char c)
Checks if the next token is an operator and matches the character c. Otherwise, returns false. The token is not removed.

Parameters:
c - the character to match
Returns:
true if the next token is an operator, and matches c, false otherwise

test

boolean test(java.lang.String s)
Checks if the next token is a word and matches the string s. The token is not removed.

Parameters:
s - the string to match
Returns:
true if the next token is a word, and matches s, false otherwise

pushBack

void pushBack()
Pushes the last token requested back. Implementations are required to be able to push back to the start of the file.


canPushBack

boolean canPushBack()
Checks if the stream can be pushed back

Returns:
true if it can be pushed back, false if at the beginning of the file

skipToken

void skipToken()
Skips the next token


getWhitespaceBeforeToken

java.lang.String getWhitespaceBeforeToken()
Returns the whitespace in the file before the current token. This may be null

Returns:
the whitespace string

lineNo

int lineNo()
Returns the line number of the last token requested

Returns:
the line number of the last token

nextLineNo

int nextLineNo()
Returns the line number of the next token to be read

Returns:
the line number of the next token

close

void close()
Closes the input stream