Name
StreamTokenizer
Synopsis
This class performs lexical
analysis of a specified input stream and breaks the input into
tokens. It can be extremely useful when writing simple parsers.
nextToken(
) returns the next token in the stream; this is either one
of the constants defined by the class (which represent end-of-file,
end-of-line, a parsed floating-point number, and a parsed word) or a
character value. pushBack( ) pushes the token back
onto the stream, so that it is returned by the next call to
nextToken( ). The public variables
sval and nval contain the
string and numeric values (if applicable) of the most recently read
token. They are applicable when the returned token is
TT_WORD or TT_NUMBER.
lineno( ) returns the current line number.
The remaining methods allow you to specify how tokens are recognized.
wordChars(
) specifies a range of
characters that should be
treated as parts of words.
whitespaceChars(
) specifies a range of characters that serve to delimit
tokens. ordinaryChars(
)
and ordinaryChar(
) specify characters that are never part of tokens and
should be returned as-is. resetSyntax(
)
makes all characters
ordinary. eolIsSignificant(
)
specifies whether end-of-line is significant.
If so, the TT_EOL constant is returned for
end-of-lines; otherwise, they are treated as whitespace.
commentChar( )
specifies a character that begins a
comment that lasts until the end of the
line. No characters in the comment are returned.
slashStarComments(
)
and
slashSlashComments( ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access