public class Token extends Object
The framework class that represents a token returned by the scanner.
Copyright (c) 2009 by Ronald Mak
For instructional purposes only. No warranties.
Modifier and Type | Field and Description |
---|---|
protected int |
lineNum |
protected int |
position |
protected Source |
source |
protected String |
text |
protected TokenType |
type |
protected Object |
value |
Modifier and Type | Method and Description |
---|---|
protected char |
currentChar()
Call the source's currentChar() method.
|
protected void |
extract()
Default method to extract only one-character tokens from the source.
|
int |
getLineNumber()
Getter.
|
int |
getPosition()
Getter.
|
String |
getText()
Getter.
|
<T extends TokenType> |
getType()
Getter
|
Object |
getValue()
Getter.
|
protected char |
nextChar()
Call the source's nextChar() method.
|
protected char |
peekAhead(int pos)
Peek ahead
pos many spaces. |
protected char |
peekChar()
Call the source's peekChar() method.
|
String |
toString() |
protected TokenType type
protected String text
protected Object value
protected Source source
protected int lineNum
protected int position
public Token(Source source) throws IOException
source
- the source from where to fetch the token's characters.Exception
- if an error occurred.IOException
public <T extends TokenType> T getType()
public String getText()
public Object getValue()
public int getLineNumber()
public int getPosition()
protected void extract() throws IOException
Exception
- if an error occurred.IOException
protected char currentChar() throws IOException
Exception
- if an error occurred.IOException
protected char nextChar() throws IOException
Exception
- if an error occurred.IOException
protected char peekChar() throws IOException
Exception
- if an error occurred.IOException
protected char peekAhead(int pos) throws IOException
pos
many spaces.pos
- Exception
IOException
Copyright © 2010–2015. All rights reserved.