java.io
public class StreamTokenizer extends Object
Modifier and Type | Field and Description |
---|---|
double |
nval
The numeric value associated with number tokens.
|
String |
sval
The String associated with word and string tokens.
|
static int |
TT_EOF
A constant indicating that the end of the stream has been read.
|
static int |
TT_EOL
A constant indicating that the end of the line has been read.
|
static int |
TT_NUMBER
A constant indicating that a number token has been read.
|
static int |
TT_WORD
A constant indicating that a word token has been read.
|
int |
ttype
Contains the type of the token read resulting from a call to nextToken
The rules are as follows:
For a token consisting of a single ordinary character, this is the
value of that character.
|
Constructor and Description |
---|
StreamTokenizer(InputStream is)
Deprecated.
Since JDK 1.1.
|
StreamTokenizer(Reader r)
This method initializes a new
StreamTokenizer to read
characters from a Reader and parse them. |
Modifier and Type | Method and Description |
---|---|
void |
commentChar(int ch)
This method sets the comment attribute on the specified
character.
|
void |
eolIsSignificant(boolean flag)
This method sets a flag that indicates whether or not the end of line
sequence terminates and is a token.
|
int |
lineno()
This method returns the current line number.
|
void |
lowerCaseMode(boolean flag)
This method sets a flag that indicates whether or not alphabetic
tokens that are returned should be converted to lower case.
|
int |
nextToken()
This method reads the next token from the stream.
|
void |
ordinaryChar(int ch)
This method makes the specified character an ordinary character.
|
void |
ordinaryChars(int low,
int hi)
This method makes all the characters in the specified range, range
terminators included, ordinary.
|
void |
parseNumbers()
This method sets the numeric attribute on the characters '0' - '9' and
the characters '.' and '-'.
|
void |
pushBack()
Puts the current token back into the StreamTokenizer so
nextToken will return the same value on the next call. |
void |
quoteChar(int ch)
This method sets the quote attribute on the specified character.
|
void |
resetSyntax()
This method removes all attributes (whitespace, alphabetic, numeric,
quote, and comment) from all characters.
|
void |
slashSlashComments(boolean flag)
This method sets a flag that indicates whether or not "C++" language style
comments ("//" comments through EOL ) are handled by the parser.
|
void |
slashStarComments(boolean flag)
This method sets a flag that indicates whether or not "C" language style
comments (with nesting not allowed) are handled by the parser.
|
String |
toString()
This method returns the current token value as a
String in
the form "Token[x], line n", where 'n' is the current line numbers and
'x' is determined as follows. |
void |
whitespaceChars(int low,
int hi)
This method sets the whitespace attribute for all characters in the
specified range, range terminators included.
|
void |
wordChars(int low,
int hi)
This method sets the alphabetic attribute for all characters in the
specified range, range terminators included.
|
public static final int TT_EOF
public static final int TT_EOL
public static final int TT_NUMBER
public static final int TT_WORD
public int ttype
public double nval
public StreamTokenizer(InputStream is)
InputStream
and tokenizes
them. For details on how this method operates by default, see
StreamTokenizer(Reader)
.is
- The InputStream
to read frompublic StreamTokenizer(Reader r)
StreamTokenizer
to read
characters from a Reader
and parse them. The char values
have their hight bits masked so that the value is treated a character
in the range of 0x0000 to 0x00FF.
This constructor sets up the parsing table to parse the stream in the following manner:
r
- The Reader
to read chars frompublic void commentChar(int ch)
ch
- The character to set the comment attribute for, passed as an intpublic void eolIsSignificant(boolean flag)
false
flag
- true
if EOF is significant, false
otherwisepublic int lineno()
pushBack()
method is called, it has no effect on the
line number returned by this method.public void lowerCaseMode(boolean flag)
flag
- true
to convert to lower case,
false
otherwisepublic int nextToken() throws IOException
ttype
variable to the appropriate token type and
returns it. It also can set sval
or nval
as described below. The parsing strategy is as follows:
nval
is set to the value parsed.sval
. If lower case mode is set, the token
stored in sval
is converted to lower case. The end of line
sequence terminates a word only if EOL signficance has been turned on.
The start of a comment also terminates a word. Any character with a
non-alphabetic and non-numeric attribute (such as white space, a quote,
or a commet) are treated as non-alphabetic and terminate the word.String
. This String
is stored as
sval
, but is not converted to lower case, even if lower case
mode is enabled. The token type returned is the value of the quote
character encountered. Any escape sequences
(\b (backspace), \t (HTAB), \n (linefeed), \f (form feed), \r
(carriage return), \" (double quote), \' (single quote), \\
(backslash), \XXX (octal esacpe)) are converted to the appropriate
char values. Invalid esacape sequences are left in untranslated.
Unicode characters like ('\ u0000') are not recognized. IOException
- If an I/O error occurspublic void ordinaryChar(int ch)
ch
- The character to make ordinary, passed as an intpublic void ordinaryChars(int low, int hi)
low
- The low end of the range of values to set the whitespace
attribute forhi
- The high end of the range of values to set the whitespace
attribute forpublic void parseNumbers()
public void pushBack()
nextToken
will return the same value on the next call.
May cause the lineno method to return an incorrect value
if lineno is called before the next call to nextToken.public void quoteChar(int ch)
ch
- The character to set the quote attribute for, passed as an int.public void resetSyntax()
ordinaryChars(0x00, 0xFF)
.ordinaryChars(int, int)
public void slashSlashComments(boolean flag)
true
commented out sequences are skipped and
ignored by the parser. This defaults to false
.flag
- true
to recognized and handle "C++" style
comments, false
otherwisepublic void slashStarComments(boolean flag)
true
commented out sequences are skipped and
ignored by the parser. This defaults to false
.flag
- true
to recognized and handle "C" style comments,
false
otherwisepublic String toString()
String
in
the form "Token[x], line n", where 'n' is the current line numbers and
'x' is determined as follows.
ttype
is TT_EOF, then 'x' is "EOF"ttype
is TT_EOL, then 'x' is "EOL"ttype
is TT_WORD, then 'x' is sval
ttype
is TT_NUMBER, then 'x' is "n=strnval" where
'strnval' is String.valueOf(nval)
.ttype
is a quote character, then 'x' is
sval
ttype
toString
in class Object
Object.getClass()
,
Object.hashCode()
,
Class.getName()
,
Integer.toHexString(int)
public void whitespaceChars(int low, int hi)
low
- The low end of the range of values to set the whitespace
attribute forhi
- The high end of the range of values to set the whitespace
attribute forpublic void wordChars(int low, int hi)
low
- The low end of the range of values to set the alphabetic
attribute forhi
- The high end of the range of values to set the alphabetic
attribute for